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

Function skip_struct

cpp/fory/serialization/skip.cc:373–463  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

371}
372
373void skip_struct(ReadContext &ctx, const FieldType &) {
374 // Struct fields in compatible mode are serialized with type_id and
375 // optionally meta_index, followed by field values. We use the loaded
376 // TypeMeta to skip all fields for the remote struct.
377 //
378 // Type categories:
379 // - COMPATIBLE_STRUCT/NAMED_COMPATIBLE_STRUCT: type_id + meta_index + fields
380 // - NAMED_STRUCT in compatible mode: type_id + meta_index + fields
381 // - STRUCT: type_id + struct_version + fields (no meta_index)
382
383 if (!ctx.is_compatible()) {
384 ctx.set_error(Error::unsupported(
385 "Struct skipping is only supported in compatible mode"));
386 return;
387 }
388
389 // Read remote type_id
390 uint32_t remote_type_id = ctx.read_uint8(ctx.error());
391 if (FORY_PREDICT_FALSE(ctx.has_error())) {
392 return;
393 }
394
395 uint32_t user_type_id = 0;
396 switch (static_cast<TypeId>(remote_type_id)) {
397 case TypeId::ENUM:
398 case TypeId::STRUCT:
399 case TypeId::EXT:
400 case TypeId::TYPED_UNION:
401 user_type_id = ctx.read_var_uint32(ctx.error());
402 if (FORY_PREDICT_FALSE(ctx.has_error())) {
403 return;
404 }
405 break;
406 default:
407 break;
408 }
409 TypeId remote_tid = static_cast<TypeId>(remote_type_id);
410 bool has_user_type_id =
411 remote_tid == TypeId::ENUM || remote_tid == TypeId::STRUCT ||
412 remote_tid == TypeId::EXT || remote_tid == TypeId::TYPED_UNION;
413
414 const TypeInfo *type_info = nullptr;
415
416 if (remote_tid == TypeId::COMPATIBLE_STRUCT ||
417 remote_tid == TypeId::NAMED_COMPATIBLE_STRUCT ||
418 remote_tid == TypeId::NAMED_STRUCT) {
419 // These types write TypeMeta inline using streaming protocol
420 auto type_info_res = ctx.read_type_meta();
421 if (FORY_PREDICT_FALSE(!type_info_res.ok())) {
422 ctx.set_error(std::move(type_info_res).error());
423 return;
424 }
425 type_info = type_info_res.value();
426 } else {
427 // Plain STRUCT: look up by type_id, read struct_version if enabled
428 auto type_info_res =
429 has_user_type_id
430 ? ctx.type_resolver().get_user_type_info_by_id(remote_type_id,

Callers 1

skip_field_valueFunction · 0.70

Calls 14

get_field_infosMethod · 0.80
skip_field_valueFunction · 0.70
errorMethod · 0.65
valueMethod · 0.65
is_compatibleMethod · 0.45
set_errorMethod · 0.45
read_uint8Method · 0.45
has_errorMethod · 0.45
read_var_uint32Method · 0.45
read_type_metaMethod · 0.45
okMethod · 0.45

Tested by

no test coverage detected