@@ -445,12 +445,85 @@ struct TypeIdResolver {
445
445
}
446
446
};
447
447
448
+ std::vector<SerializableFieldDefinition> toSerializableField (
449
+ folly::span<const FieldDefinition> fields) {
450
+ std::vector<SerializableFieldDefinition> result;
451
+ result.reserve (fields.size ());
452
+ for (const auto & field : fields) {
453
+ auto & fieldDef = result.emplace_back ();
454
+ fieldDef.identity () = field.identity ();
455
+ fieldDef.presence () = field.presence ();
456
+ fieldDef.type () = field.type ().id ();
457
+ if (const auto * customDefault = field.customDefault ()) {
458
+ fieldDef.customDefaultValue () =
459
+ SerializableRecord::toThrift (*customDefault);
460
+ }
461
+ fieldDef.annotations () = detail::toRawAnnotations (field.annotations ());
462
+ }
463
+ return result;
464
+ }
465
+
466
+ SerializableTypeDefinition toSerializableDefinition (DefinitionRef ref) {
467
+ return ref.visit (
468
+ [&](const StructNode& node) {
469
+ SerializableTypeDefinition result;
470
+ auto & structDef = result.structDef ().ensure ();
471
+ structDef.fields () = toSerializableField (node.fields ());
472
+ structDef.isSealed () = node.isSealed ();
473
+ structDef.annotations () = detail::toRawAnnotations (node.annotations ());
474
+ return result;
475
+ },
476
+ [&](const UnionNode& node) {
477
+ SerializableTypeDefinition result;
478
+ auto & unionDef = result.unionDef ().ensure ();
479
+ unionDef.fields () = toSerializableField (node.fields ());
480
+ unionDef.isSealed () = node.isSealed ();
481
+ unionDef.annotations () = detail::toRawAnnotations (node.annotations ());
482
+ return result;
483
+ },
484
+ [&](const EnumNode& node) {
485
+ SerializableTypeDefinition result;
486
+ auto & enumDef = result.enumDef ().ensure ();
487
+ enumDef.values ()->reserve (node.values ().size ());
488
+ for (const auto & v : node.values ()) {
489
+ auto & enumValue = enumDef.values ()->emplace_back ();
490
+ enumValue.name () = v.name ;
491
+ enumValue.datum () = v.i32 ;
492
+ enumValue.annotations () = detail::toRawAnnotations (v.annotations ());
493
+ }
494
+ enumDef.annotations () = detail::toRawAnnotations (node.annotations ());
495
+ return result;
496
+ },
497
+ [&](const OpaqueAliasNode& node) {
498
+ SerializableTypeDefinition result;
499
+ auto & opaqueAliasDef = result.opaqueAliasDef ().ensure ();
500
+ opaqueAliasDef.targetType () = node.targetType ().id ();
501
+ opaqueAliasDef.annotations () =
502
+ detail::toRawAnnotations (node.annotations ());
503
+ return result;
504
+ });
505
+ }
506
+
448
507
} // namespace
449
508
450
509
TypeRef TypeSystem::resolveTypeId (const TypeId& typeId) const {
451
510
return TypeIdResolver{*this }(typeId);
452
511
}
453
512
513
+ SerializableTypeSystem TypeSystem::toSerializableTypeSystem (
514
+ const folly::F14FastSet<Uri>& uris) const {
515
+ SerializableTypeSystem result;
516
+ for (const auto & uri : uris) {
517
+ auto def = getUserDefinedTypeOrThrow (uri);
518
+
519
+ SerializableTypeDefinitionEntry entry;
520
+ entry.definition () = toSerializableDefinition (def);
521
+
522
+ result.types ()->emplace (uri, std::move (entry));
523
+ }
524
+ return result;
525
+ }
526
+
454
527
} // namespace apache::thrift::type_system
455
528
456
529
std::size_t std::hash<apache::thrift::type_system::DefinitionRef>::operator ()(
0 commit comments