MCPcopy Create free account
hub / github.com/apache/fory / read_primitive_field_direct

Function read_primitive_field_direct

cpp/fory/serialization/struct_serializer.h:2919–2964  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

2917/// NOTE: Only use for raw primitive types, not wrappers!
2918template <typename FieldType>
2919FORY_ALWAYS_INLINE FieldType read_primitive_field_direct(ReadContext &ctx,
2920 Error &error) {
2921 static_assert(is_raw_primitive_v<FieldType>,
2922 "read_primitive_field_direct only supports raw primitives");
2923
2924 // Use the actual C++ type, not TypeId. Fixed unsigned fields use the
2925 // explicit fixed read helpers; this path follows serializer defaults.
2926 if constexpr (std::is_same_v<FieldType, bool>) {
2927 uint8_t v = ctx.read_uint8(error);
2928 return v != 0;
2929 } else if constexpr (std::is_same_v<FieldType, int8_t>) {
2930 return ctx.read_int8(error);
2931 } else if constexpr (std::is_same_v<FieldType, uint8_t>) {
2932 return ctx.read_uint8(error);
2933 } else if constexpr (std::is_same_v<FieldType, int16_t>) {
2934 // int16_t uses fixed 2-byte encoding
2935 return ctx.read_int16(error);
2936 } else if constexpr (std::is_same_v<FieldType, uint16_t>) {
2937 // uint16_t uses fixed 2-byte encoding
2938 int16_t v = ctx.read_int16(error);
2939 return static_cast<uint16_t>(v);
2940 } else if constexpr (std::is_same_v<FieldType, int32_t>) {
2941 // int32_t uses varint encoding
2942 return ctx.read_var_int32(error);
2943 } else if constexpr (std::is_same_v<FieldType, uint32_t>) {
2944 return ctx.read_var_uint32(error);
2945 } else if constexpr (std::is_same_v<FieldType, int64_t>) {
2946 // int64_t uses varint encoding
2947 return ctx.read_var_int64(error);
2948 } else if constexpr (std::is_same_v<FieldType, uint64_t>) {
2949 return ctx.read_var_uint64(error);
2950 } else if constexpr (std::is_same_v<FieldType, float16_t>) {
2951 return ctx.read_f16(error);
2952 } else if constexpr (std::is_same_v<FieldType, bfloat16_t>) {
2953 return ctx.read_bf16(error);
2954 } else if constexpr (std::is_same_v<FieldType, float>) {
2955 return ctx.read_float(error);
2956 } else if constexpr (std::is_same_v<FieldType, double>) {
2957 return ctx.read_double(error);
2958 } else {
2959 // Fallback for other types - should not be reached for primitives
2960 static_assert(sizeof(FieldType) == 0,
2961 "Unexpected type in read_primitive_field_direct");
2962 return FieldType{};
2963 }
2964}
2965
2966/// Helper to read a single field by index
2967template <size_t Index, typename T>

Callers

nothing calls this directly

Calls 11

read_uint8Method · 0.45
read_int8Method · 0.45
read_int16Method · 0.45
read_var_int32Method · 0.45
read_var_uint32Method · 0.45
read_var_int64Method · 0.45
read_var_uint64Method · 0.45
read_f16Method · 0.45
read_bf16Method · 0.45
read_floatMethod · 0.45
read_doubleMethod · 0.45

Tested by

no test coverage detected