| 371 | } |
| 372 | |
| 373 | void 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, |
no test coverage detected