protobuf_format.h 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. #pragma once
  2. #include "common.h"
  3. #include <yt/yt_proto/yt/formats/extension.pb.h>
  4. #include <util/generic/maybe.h>
  5. #include <google/protobuf/message.h>
  6. /// @cond Doxygen_Suppress
  7. namespace NYT::NDetail {
  8. ////////////////////////////////////////////////////////////////////////////////
  9. enum class EProtobufType
  10. {
  11. EnumInt /* "enum_int" */,
  12. EnumString /* "enum_string" */,
  13. Any /* "any" */,
  14. OtherColumns /* "other_columns" */,
  15. };
  16. enum class EProtobufSerializationMode
  17. {
  18. Protobuf,
  19. Yt,
  20. Embedded,
  21. };
  22. enum class EProtobufListMode
  23. {
  24. Optional,
  25. Required,
  26. };
  27. enum class EProtobufMapMode
  28. {
  29. ListOfStructsLegacy,
  30. ListOfStructs,
  31. Dict,
  32. OptionalDict,
  33. };
  34. enum class EProtobufFieldSortOrder
  35. {
  36. AsInProtoFile,
  37. ByFieldNumber,
  38. };
  39. enum class EProtobufOneofMode
  40. {
  41. SeparateFields,
  42. Variant,
  43. };
  44. enum class EProtobufEnumWritingMode
  45. {
  46. SkipUnknownValues,
  47. CheckValues,
  48. };
  49. struct TProtobufOneofOptions
  50. {
  51. EProtobufOneofMode Mode = EProtobufOneofMode::Variant;
  52. TString VariantFieldName;
  53. };
  54. struct TProtobufFieldOptions
  55. {
  56. TMaybe<EProtobufType> Type;
  57. EProtobufSerializationMode SerializationMode = EProtobufSerializationMode::Protobuf;
  58. EProtobufListMode ListMode = EProtobufListMode::Required;
  59. EProtobufMapMode MapMode = EProtobufMapMode::ListOfStructsLegacy;
  60. };
  61. struct TProtobufMessageOptions
  62. {
  63. EProtobufFieldSortOrder FieldSortOrder = EProtobufFieldSortOrder::ByFieldNumber;
  64. };
  65. TString GetColumnName(const ::google::protobuf::FieldDescriptor& field);
  66. TProtobufFieldOptions GetFieldOptions(
  67. const ::google::protobuf::FieldDescriptor* fieldDescriptor,
  68. const TMaybe<TProtobufFieldOptions>& defaultFieldOptions = {});
  69. TProtobufOneofOptions GetOneofOptions(
  70. const ::google::protobuf::OneofDescriptor* oneofDescriptor,
  71. const TMaybe<TProtobufOneofOptions>& defaultOneofOptions = {});
  72. TProtobufMessageOptions GetMessageOptions(const ::google::protobuf::Descriptor* descriptor);
  73. TMaybe<TVector<TString>> InferColumnFilter(const ::google::protobuf::Descriptor& descriptor);
  74. TNode MakeProtoFormatConfigWithTables(const TVector<const ::google::protobuf::Descriptor*>& descriptors);
  75. TNode MakeProtoFormatConfigWithDescriptors(const TVector<const ::google::protobuf::Descriptor*>& descriptors);
  76. TTableSchema CreateTableSchemaImpl(
  77. const ::google::protobuf::Descriptor& messageDescriptor,
  78. bool keepFieldsWithoutExtension);
  79. ////////////////////////////////////////////////////////////////////////////////
  80. } // namespace NYT::NDetail
  81. /// @endcond