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

Function read_struct_fields_compatible

cpp/fory/serialization/struct_serializer.h:4283–4407  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

4281/// Reads fields in remote schema order, dispatching by field_id to local fields
4282template <typename T, size_t... Indices>
4283FORY_NOINLINE void
4284read_struct_fields_compatible(T &obj, ReadContext &ctx,
4285 const TypeMeta *remote_type_meta,
4286 std::index_sequence<Indices...>) {
4287 const auto &remote_fields = remote_type_meta->get_field_infos();
4288 Buffer &buffer = ctx.buffer();
4289 const bool use_exact_offset_reads = !buffer.has_input_stream();
4290 uint32_t offset = buffer.reader_index();
4291 constexpr size_t total_cases =
4292 CompileTimeFieldHelpers<T>::FieldCount * static_cast<size_t>(2);
4293#define FORY_COMPAT_LOOP_SWITCH_CASE(N) \
4294 case (N): { \
4295 constexpr size_t matched_case = static_cast<size_t>(N); \
4296 if constexpr (matched_case < total_cases) { \
4297 if constexpr ((matched_case & 1U) == 0) { \
4298 if (use_exact_offset_reads) { \
4299 constexpr size_t local_sorted_id = matched_case / 2; \
4300 if constexpr (can_read_exact_primitive_with_offset< \
4301 T, local_sorted_id>()) { \
4302 read_exact_primitive_run<T, local_sorted_id>( \
4303 obj, ctx, remote_fields, remote_idx, offset); \
4304 } else { \
4305 read_compatible_exact_case_at<T, matched_case>(obj, ctx, offset); \
4306 } \
4307 } else { \
4308 read_compatible_exact_case<T, matched_case>(obj, ctx); \
4309 } \
4310 } else { \
4311 if (use_exact_offset_reads) { \
4312 buffer.reader_index(offset); \
4313 } \
4314 read_compatible_conversion_case<T, matched_case>( \
4315 obj, ctx, remote_field.field_type); \
4316 if (use_exact_offset_reads) { \
4317 offset = buffer.reader_index(); \
4318 } \
4319 } \
4320 } else { \
4321 ctx.set_error(Error::type_error("Invalid compatible matched id")); \
4322 } \
4323 break; \
4324 }
4325#define FORY_COMPAT_LOOP_SWITCH_CASES_16(O) \
4326 FORY_COMPAT_LOOP_SWITCH_CASE((O) + 0) \
4327 FORY_COMPAT_LOOP_SWITCH_CASE((O) + 1) \
4328 FORY_COMPAT_LOOP_SWITCH_CASE((O) + 2) \
4329 FORY_COMPAT_LOOP_SWITCH_CASE((O) + 3) \
4330 FORY_COMPAT_LOOP_SWITCH_CASE((O) + 4) \
4331 FORY_COMPAT_LOOP_SWITCH_CASE((O) + 5) \
4332 FORY_COMPAT_LOOP_SWITCH_CASE((O) + 6) \
4333 FORY_COMPAT_LOOP_SWITCH_CASE((O) + 7) \
4334 FORY_COMPAT_LOOP_SWITCH_CASE((O) + 8) \
4335 FORY_COMPAT_LOOP_SWITCH_CASE((O) + 9) \
4336 FORY_COMPAT_LOOP_SWITCH_CASE((O) + 10) \
4337 FORY_COMPAT_LOOP_SWITCH_CASE((O) + 11) \
4338 FORY_COMPAT_LOOP_SWITCH_CASE((O) + 12) \
4339 FORY_COMPAT_LOOP_SWITCH_CASE((O) + 13) \
4340 FORY_COMPAT_LOOP_SWITCH_CASE((O) + 14) \

Callers 1

read_compatibleMethod · 0.85

Calls 8

get_field_infosMethod · 0.80
has_input_streamMethod · 0.80
reader_indexMethod · 0.80
skip_field_valueFunction · 0.70
bufferMethod · 0.45
sizeMethod · 0.45
has_errorMethod · 0.45
set_errorMethod · 0.45

Tested by

no test coverage detected