schema_from_proto.h 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. #pragma once
  2. #include <library/cpp/yson/node/node.h>
  3. #include <util/generic/hash.h>
  4. #include <util/generic/string.h>
  5. #include <google/protobuf/descriptor.h>
  6. namespace NYql {
  7. namespace NPureCalc {
  8. enum class EEnumPolicy {
  9. Int32,
  10. String,
  11. YTFlagDefaultInt32,
  12. YTFlagDefaultString
  13. };
  14. enum class EEnumFormatType {
  15. Int32,
  16. String
  17. };
  18. /**
  19. * Options that customize building of struct type from protobuf descriptor.
  20. */
  21. struct TProtoSchemaOptions {
  22. public:
  23. EEnumPolicy EnumPolicy;
  24. bool ListIsOptional;
  25. THashMap<TString, TString> FieldRenames;
  26. public:
  27. TProtoSchemaOptions();
  28. public:
  29. TProtoSchemaOptions& SetEnumPolicy(EEnumPolicy);
  30. TProtoSchemaOptions& SetListIsOptional(bool);
  31. TProtoSchemaOptions& SetFieldRenames(
  32. THashMap<TString, TString> fieldRenames
  33. );
  34. };
  35. EEnumFormatType EnumFormatType(const google::protobuf::FieldDescriptor& enumField, EEnumPolicy enumPolicy);
  36. /**
  37. * Build struct type from a protobuf descriptor. The returned yson can be loaded into a struct annotation node
  38. * using the ParseTypeFromYson function.
  39. */
  40. NYT::TNode MakeSchemaFromProto(const google::protobuf::Descriptor&, const TProtoSchemaOptions& = {});
  41. /**
  42. * Build variant over tuple type from protobuf descriptors.
  43. */
  44. NYT::TNode MakeVariantSchemaFromProtos(const TVector<const google::protobuf::Descriptor*>&, const TProtoSchemaOptions& = {});
  45. }
  46. }