File indexing completed on 2025-01-31 10:12:07
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022
0023
0024
0025
0026
0027
0028
0029
0030
0031 #ifndef GOOGLE_PROTOBUF_DESCRIPTOR_H__
0032 #define GOOGLE_PROTOBUF_DESCRIPTOR_H__
0033
0034 #include <atomic>
0035 #include <cstdint>
0036 #include <iterator>
0037 #include <memory>
0038 #include <string>
0039 #include <utility>
0040 #include <vector>
0041
0042 #include "google/protobuf/stubs/common.h"
0043 #include "absl/base/attributes.h"
0044 #include "absl/base/call_once.h"
0045 #include "absl/container/btree_map.h"
0046 #include "absl/container/flat_hash_map.h"
0047 #include "absl/functional/any_invocable.h"
0048 #include "absl/functional/function_ref.h"
0049 #include "absl/log/absl_check.h"
0050 #include "absl/log/absl_log.h"
0051 #include "absl/strings/str_format.h"
0052 #include "absl/strings/string_view.h"
0053 #include "absl/synchronization/mutex.h"
0054 #include "absl/types/optional.h"
0055 #include "google/protobuf/descriptor_lite.h"
0056 #include "google/protobuf/extension_set.h"
0057 #include "google/protobuf/port.h"
0058
0059
0060 #include "google/protobuf/port_def.inc"
0061
0062 #ifdef SWIG
0063 #define PROTOBUF_EXPORT
0064 #define PROTOBUF_IGNORE_DEPRECATION_START
0065 #define PROTOBUF_IGNORE_DEPRECATION_STOP
0066 #endif
0067
0068
0069 namespace google {
0070 namespace protobuf {
0071
0072 class Descriptor;
0073 class FieldDescriptor;
0074 class OneofDescriptor;
0075 class EnumDescriptor;
0076 class EnumValueDescriptor;
0077 class ServiceDescriptor;
0078 class MethodDescriptor;
0079 class FileDescriptor;
0080 class DescriptorDatabase;
0081 class DescriptorPool;
0082
0083
0084 #ifndef SWIG
0085 enum Edition : int;
0086 #else
0087 typedef int Edition;
0088 #endif
0089 class DescriptorProto;
0090 class DescriptorProto_ExtensionRange;
0091 class FieldDescriptorProto;
0092 class OneofDescriptorProto;
0093 class EnumDescriptorProto;
0094 class EnumValueDescriptorProto;
0095 class ServiceDescriptorProto;
0096 class MethodDescriptorProto;
0097 class FileDescriptorProto;
0098 class MessageOptions;
0099 class FieldOptions;
0100 class OneofOptions;
0101 class EnumOptions;
0102 class EnumValueOptions;
0103 class ExtensionRangeOptions;
0104 class ServiceOptions;
0105 class MethodOptions;
0106 class FileOptions;
0107 class UninterpretedOption;
0108 class FeatureSet;
0109 class FeatureSetDefaults;
0110 class SourceCodeInfo;
0111
0112
0113 class MessageLite;
0114
0115
0116 class Message;
0117 class Reflection;
0118
0119
0120 class DescriptorBuilder;
0121 class FileDescriptorTables;
0122 class Symbol;
0123
0124
0125 class UnknownField;
0126
0127
0128 namespace compiler {
0129 class CodeGenerator;
0130 class CommandLineInterface;
0131 namespace cpp {
0132
0133 class Formatter;
0134 }
0135 }
0136
0137 namespace descriptor_unittest {
0138 class DescriptorTest;
0139 class ValidationErrorTest;
0140 }
0141
0142
0143 namespace io {
0144 class Printer;
0145 }
0146
0147
0148 struct SourceLocation {
0149 int start_line;
0150 int end_line;
0151 int start_column;
0152 int end_column;
0153
0154
0155
0156 std::string leading_comments;
0157 std::string trailing_comments;
0158 std::vector<std::string> leading_detached_comments;
0159 };
0160
0161
0162
0163 struct DebugStringOptions {
0164
0165
0166
0167
0168 bool include_comments;
0169
0170 bool elide_group_body;
0171 bool elide_oneof_body;
0172
0173 DebugStringOptions()
0174 : include_comments(false),
0175 elide_group_body(false),
0176 elide_oneof_body(false) {
0177 }
0178 };
0179
0180
0181
0182
0183
0184 namespace internal {
0185
0186
0187
0188
0189
0190
0191
0192
0193 #if !defined(PROTOBUF_INTERNAL_CHECK_CLASS_SIZE)
0194 #define PROTOBUF_INTERNAL_CHECK_CLASS_SIZE(t, expected)
0195 #endif
0196
0197 class FlatAllocator;
0198
0199 class PROTOBUF_EXPORT LazyDescriptor {
0200 public:
0201
0202
0203 void Init() {
0204 descriptor_ = nullptr;
0205 once_ = nullptr;
0206 }
0207
0208
0209
0210
0211
0212 void Set(const Descriptor* descriptor);
0213
0214
0215
0216
0217
0218
0219 void SetLazy(absl::string_view name, const FileDescriptor* file);
0220
0221
0222
0223
0224 inline const Descriptor* Get(const ServiceDescriptor* service) {
0225 Once(service);
0226 return descriptor_;
0227 }
0228
0229 private:
0230 void Once(const ServiceDescriptor* service);
0231
0232 const Descriptor* descriptor_;
0233
0234 absl::once_flag* once_;
0235 };
0236
0237 class PROTOBUF_EXPORT SymbolBase {
0238 private:
0239 friend class google::protobuf::Symbol;
0240 uint8_t symbol_type_;
0241 };
0242
0243
0244
0245
0246
0247 template <int N>
0248 class PROTOBUF_EXPORT SymbolBaseN : public SymbolBase {};
0249
0250
0251
0252
0253
0254 class PROTOBUF_EXPORT InternalFeatureHelper {
0255 public:
0256 template <typename DescriptorT>
0257 static const FeatureSet& GetFeatures(const DescriptorT& desc) {
0258 return desc.features();
0259 }
0260
0261 private:
0262 friend class ::google::protobuf::compiler::CodeGenerator;
0263 friend class ::google::protobuf::compiler::CommandLineInterface;
0264
0265
0266
0267
0268
0269
0270 template <typename DescriptorT, typename TypeTraitsT, uint8_t field_type,
0271 bool is_packed>
0272 static typename TypeTraitsT::ConstType GetUnresolvedFeatures(
0273 const DescriptorT& descriptor,
0274 const google::protobuf::internal::ExtensionIdentifier<
0275 FeatureSet, TypeTraitsT, field_type, is_packed>& extension) {
0276 return descriptor.proto_features_->GetExtension(extension);
0277 }
0278
0279
0280
0281
0282 static Edition GetEdition(const FileDescriptor& desc);
0283 };
0284
0285 PROTOBUF_EXPORT absl::string_view ShortEditionName(Edition edition);
0286
0287 bool IsEnumFullySequential(const EnumDescriptor* enum_desc);
0288
0289 }
0290
0291
0292 template <typename Sink>
0293 void AbslStringify(Sink& sink, Edition edition) {
0294 absl::Format(&sink, "%v", internal::ShortEditionName(edition));
0295 }
0296
0297
0298
0299
0300
0301
0302 class PROTOBUF_EXPORT Descriptor : private internal::SymbolBase {
0303 public:
0304 typedef DescriptorProto Proto;
0305 #ifndef SWIG
0306 Descriptor(const Descriptor&) = delete;
0307 Descriptor& operator=(const Descriptor&) = delete;
0308 #endif
0309
0310
0311 const std::string& name() const;
0312
0313
0314
0315
0316
0317
0318 const std::string& full_name() const;
0319
0320
0321
0322 int index() const;
0323
0324
0325 const FileDescriptor* file() const;
0326
0327
0328
0329 const Descriptor* containing_type() const;
0330
0331
0332
0333
0334
0335 const MessageOptions& options() const;
0336
0337
0338
0339
0340 void CopyTo(DescriptorProto* proto) const;
0341
0342
0343
0344
0345
0346 void CopyHeadingTo(DescriptorProto* proto) const;
0347
0348
0349
0350 std::string DebugString() const;
0351
0352
0353
0354 std::string DebugStringWithOptions(const DebugStringOptions& options) const;
0355
0356
0357 template <typename Sink>
0358 friend void AbslStringify(Sink& sink, const Descriptor& d) {
0359 absl::Format(&sink, "%s", d.DebugString());
0360 }
0361
0362
0363
0364
0365 bool is_placeholder() const;
0366
0367 enum WellKnownType {
0368 WELLKNOWNTYPE_UNSPECIFIED,
0369
0370
0371 WELLKNOWNTYPE_DOUBLEVALUE,
0372 WELLKNOWNTYPE_FLOATVALUE,
0373 WELLKNOWNTYPE_INT64VALUE,
0374 WELLKNOWNTYPE_UINT64VALUE,
0375 WELLKNOWNTYPE_INT32VALUE,
0376 WELLKNOWNTYPE_UINT32VALUE,
0377 WELLKNOWNTYPE_STRINGVALUE,
0378 WELLKNOWNTYPE_BYTESVALUE,
0379 WELLKNOWNTYPE_BOOLVALUE,
0380
0381
0382 WELLKNOWNTYPE_ANY,
0383 WELLKNOWNTYPE_FIELDMASK,
0384 WELLKNOWNTYPE_DURATION,
0385 WELLKNOWNTYPE_TIMESTAMP,
0386 WELLKNOWNTYPE_VALUE,
0387 WELLKNOWNTYPE_LISTVALUE,
0388 WELLKNOWNTYPE_STRUCT,
0389
0390
0391
0392 __WELLKNOWNTYPE__DO_NOT_USE__ADD_DEFAULT_INSTEAD__,
0393 };
0394
0395 WellKnownType well_known_type() const;
0396
0397
0398
0399
0400 int field_count() const;
0401
0402
0403 const FieldDescriptor* field(int index) const;
0404
0405
0406
0407 const FieldDescriptor* FindFieldByNumber(int number) const;
0408
0409 const FieldDescriptor* FindFieldByName(absl::string_view name) const;
0410
0411
0412
0413
0414 const FieldDescriptor* FindFieldByLowercaseName(
0415 absl::string_view lowercase_name) const;
0416
0417
0418
0419
0420
0421 const FieldDescriptor* FindFieldByCamelcaseName(
0422 absl::string_view camelcase_name) const;
0423
0424
0425 int oneof_decl_count() const;
0426
0427
0428
0429 int real_oneof_decl_count() const;
0430
0431
0432 const OneofDescriptor* oneof_decl(int index) const;
0433
0434
0435
0436 const OneofDescriptor* real_oneof_decl(int index) const;
0437
0438
0439 const OneofDescriptor* FindOneofByName(absl::string_view name) const;
0440
0441
0442
0443
0444 int nested_type_count() const;
0445
0446
0447 const Descriptor* nested_type(int index) const;
0448
0449
0450
0451 const Descriptor* FindNestedTypeByName(absl::string_view name) const;
0452
0453
0454
0455
0456 int enum_type_count() const;
0457
0458
0459 const EnumDescriptor* enum_type(int index) const;
0460
0461
0462
0463 const EnumDescriptor* FindEnumTypeByName(absl::string_view name) const;
0464
0465
0466
0467 const EnumValueDescriptor* FindEnumValueByName(absl::string_view name) const;
0468
0469
0470
0471
0472
0473 class PROTOBUF_EXPORT ExtensionRange {
0474 public:
0475 typedef DescriptorProto_ExtensionRange Proto;
0476
0477 typedef ExtensionRangeOptions OptionsType;
0478
0479
0480 void CopyTo(DescriptorProto_ExtensionRange* proto) const;
0481
0482
0483 int start_number() const { return start_; }
0484
0485
0486 int end_number() const { return end_; }
0487
0488
0489
0490 int index() const;
0491
0492
0493 const ExtensionRangeOptions& options() const { return *options_; }
0494
0495
0496 const std::string& name() const { return containing_type_->name(); }
0497
0498
0499 const std::string& full_name() const {
0500 return containing_type_->full_name();
0501 }
0502
0503
0504
0505 const FileDescriptor* file() const { return containing_type_->file(); }
0506
0507
0508
0509 const Descriptor* containing_type() const { return containing_type_; }
0510
0511 private:
0512 int start_;
0513 int end_;
0514 const ExtensionRangeOptions* options_;
0515
0516 private:
0517 const Descriptor* containing_type_;
0518 const FeatureSet* proto_features_;
0519 const FeatureSet* merged_features_;
0520
0521
0522
0523
0524
0525 const FeatureSet& features() const { return *merged_features_; }
0526 friend class internal::InternalFeatureHelper;
0527
0528
0529
0530 void GetLocationPath(std::vector<int>* output) const;
0531
0532 friend class Descriptor;
0533 friend class DescriptorPool;
0534 friend class DescriptorBuilder;
0535 };
0536
0537
0538 int extension_range_count() const;
0539
0540
0541
0542 const ExtensionRange* extension_range(int index) const;
0543
0544
0545 bool IsExtensionNumber(int number) const;
0546
0547
0548 const ExtensionRange* FindExtensionRangeContainingNumber(int number) const;
0549
0550
0551
0552
0553
0554
0555
0556
0557
0558
0559
0560
0561
0562
0563
0564
0565
0566
0567
0568
0569
0570
0571
0572
0573
0574 int extension_count() const;
0575
0576
0577 const FieldDescriptor* extension(int index) const;
0578
0579
0580
0581 const FieldDescriptor* FindExtensionByName(absl::string_view name) const;
0582
0583
0584
0585 const FieldDescriptor* FindExtensionByLowercaseName(
0586 absl::string_view name) const;
0587
0588
0589
0590 const FieldDescriptor* FindExtensionByCamelcaseName(
0591 absl::string_view name) const;
0592
0593
0594
0595
0596 struct ReservedRange {
0597 int start;
0598 int end;
0599 };
0600
0601
0602 int reserved_range_count() const;
0603
0604
0605
0606 const ReservedRange* reserved_range(int index) const;
0607
0608
0609 bool IsReservedNumber(int number) const;
0610
0611
0612 const ReservedRange* FindReservedRangeContainingNumber(int number) const;
0613
0614
0615 int reserved_name_count() const;
0616
0617
0618 const std::string& reserved_name(int index) const;
0619
0620
0621 bool IsReservedName(absl::string_view name) const;
0622
0623
0624
0625
0626
0627
0628 bool GetSourceLocation(SourceLocation* out_location) const;
0629
0630
0631
0632
0633
0634 const FieldDescriptor* map_key() const;
0635
0636
0637
0638 const FieldDescriptor* map_value() const;
0639
0640 private:
0641 friend class Symbol;
0642 typedef MessageOptions OptionsType;
0643
0644
0645 friend class descriptor_unittest::DescriptorTest;
0646
0647
0648 friend class io::Printer;
0649 friend class compiler::cpp::Formatter;
0650
0651
0652
0653
0654
0655 const FeatureSet& features() const { return *merged_features_; }
0656 friend class internal::InternalFeatureHelper;
0657
0658
0659 void CopyJsonNameTo(DescriptorProto* proto) const;
0660
0661
0662
0663
0664
0665 void DebugString(int depth, std::string* contents,
0666 const DebugStringOptions& options,
0667 bool include_opening_clause) const;
0668
0669
0670
0671 void GetLocationPath(std::vector<int>* output) const;
0672
0673
0674 bool is_placeholder_ : 1;
0675
0676 bool is_unqualified_placeholder_ : 1;
0677
0678 uint8_t well_known_type_ : 5;
0679
0680
0681
0682
0683
0684
0685
0686
0687 uint16_t sequential_field_limit_;
0688
0689 int field_count_;
0690
0691
0692 const std::string* all_names_;
0693 const FileDescriptor* file_;
0694 const Descriptor* containing_type_;
0695 const MessageOptions* options_;
0696 const FeatureSet* proto_features_;
0697 const FeatureSet* merged_features_;
0698
0699
0700 FieldDescriptor* fields_;
0701 OneofDescriptor* oneof_decls_;
0702 Descriptor* nested_types_;
0703 EnumDescriptor* enum_types_;
0704 ExtensionRange* extension_ranges_;
0705 FieldDescriptor* extensions_;
0706 ReservedRange* reserved_ranges_;
0707 const std::string** reserved_names_;
0708
0709 int oneof_decl_count_;
0710 int real_oneof_decl_count_;
0711 int nested_type_count_;
0712 int enum_type_count_;
0713 int extension_range_count_;
0714 int extension_count_;
0715 int reserved_range_count_;
0716 int reserved_name_count_;
0717
0718
0719
0720
0721
0722
0723 Descriptor();
0724 friend class DescriptorBuilder;
0725 friend class DescriptorPool;
0726 friend class EnumDescriptor;
0727 friend class FieldDescriptor;
0728 friend class FileDescriptorTables;
0729 friend class OneofDescriptor;
0730 friend class MethodDescriptor;
0731 friend class FileDescriptor;
0732 };
0733
0734 PROTOBUF_INTERNAL_CHECK_CLASS_SIZE(Descriptor, 152);
0735
0736
0737
0738
0739
0740
0741
0742
0743
0744
0745
0746 class PROTOBUF_EXPORT FieldDescriptor : private internal::SymbolBase,
0747 public internal::FieldDescriptorLite {
0748 public:
0749 typedef FieldDescriptorProto Proto;
0750
0751 #ifndef SWIG
0752 FieldDescriptor(const FieldDescriptor&) = delete;
0753 FieldDescriptor& operator=(const FieldDescriptor&) = delete;
0754 #endif
0755
0756
0757
0758
0759
0760
0761
0762
0763
0764
0765
0766
0767
0768
0769
0770
0771
0772
0773
0774
0775
0776
0777
0778
0779
0780
0781
0782
0783
0784
0785
0786
0787
0788
0789
0790
0791
0792
0793
0794
0795
0796
0797
0798
0799
0800
0801
0802
0803
0804
0805
0806
0807
0808
0809
0810
0811
0812
0813
0814
0815
0816
0817
0818
0819
0820
0821 static const int kMaxNumber = (1 << 29) - 1;
0822
0823
0824
0825 static const int kFirstReservedNumber = 19000;
0826
0827
0828 static const int kLastReservedNumber = 19999;
0829
0830 const std::string& name() const;
0831 const std::string& full_name() const;
0832 const std::string& json_name() const;
0833 const FileDescriptor* file() const;
0834 bool is_extension() const;
0835 int number() const;
0836
0837
0838
0839
0840
0841
0842
0843 const std::string& lowercase_name() const;
0844
0845
0846
0847
0848
0849
0850
0851
0852
0853
0854 const std::string& camelcase_name() const;
0855
0856 Type type() const;
0857 const char* type_name() const;
0858 CppType cpp_type() const;
0859 const char* cpp_type_name() const;
0860 Label label() const;
0861
0862 #ifndef SWIG
0863 CppStringType cpp_string_type() const;
0864 #endif
0865
0866 bool is_required() const;
0867 bool is_optional() const;
0868 bool is_repeated() const;
0869 bool is_packable() const;
0870
0871 bool is_map() const;
0872
0873
0874
0875
0876
0877 bool is_packed() const;
0878
0879
0880
0881
0882
0883
0884
0885
0886 bool has_presence() const;
0887
0888
0889
0890 bool requires_utf8_validation() const;
0891
0892
0893
0894
0895
0896
0897
0898
0899
0900
0901
0902
0903
0904
0905
0906
0907
0908
0909 bool legacy_enum_field_treated_as_closed() const;
0910
0911
0912
0913 int index() const;
0914
0915
0916 bool has_default_value() const;
0917
0918
0919
0920 bool has_json_name() const;
0921
0922
0923
0924 int32_t default_value_int32_t() const;
0925 int32_t default_value_int32() const { return default_value_int32_t(); }
0926
0927
0928 int64_t default_value_int64_t() const;
0929 int64_t default_value_int64() const { return default_value_int64_t(); }
0930
0931
0932 uint32_t default_value_uint32_t() const;
0933 uint32_t default_value_uint32() const { return default_value_uint32_t(); }
0934
0935
0936 uint64_t default_value_uint64_t() const;
0937 uint64_t default_value_uint64() const { return default_value_uint64_t(); }
0938
0939
0940 float default_value_float() const;
0941
0942
0943 double default_value_double() const;
0944
0945
0946 bool default_value_bool() const;
0947
0948
0949
0950
0951 const EnumValueDescriptor* default_value_enum() const;
0952
0953
0954 const std::string& default_value_string() const;
0955
0956
0957
0958 const Descriptor* containing_type() const;
0959
0960
0961
0962 const OneofDescriptor* containing_oneof() const;
0963
0964
0965
0966 const OneofDescriptor* real_containing_oneof() const;
0967
0968
0969 int index_in_oneof() const;
0970
0971
0972
0973
0974
0975
0976 const Descriptor* extension_scope() const;
0977
0978
0979
0980 const Descriptor* message_type() const;
0981
0982
0983 const EnumDescriptor* enum_type() const;
0984
0985
0986
0987
0988
0989
0990 const FieldOptions& options() const;
0991
0992
0993 void CopyTo(FieldDescriptorProto* proto) const;
0994
0995
0996 std::string DebugString() const;
0997
0998
0999 std::string DebugStringWithOptions(const DebugStringOptions& options) const;
1000
1001
1002 template <typename Sink>
1003 friend void AbslStringify(Sink& sink, const FieldDescriptor& d) {
1004 absl::Format(&sink, "%s", d.DebugString());
1005 }
1006
1007
1008 static CppType TypeToCppType(Type type);
1009
1010
1011 static const char* TypeName(Type type);
1012
1013
1014 static const char* CppTypeName(CppType cpp_type);
1015
1016
1017 static inline bool IsTypePackable(Type field_type);
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032 const std::string& PrintableNameForExtension() const;
1033
1034
1035
1036
1037
1038
1039 bool GetSourceLocation(SourceLocation* out_location) const;
1040
1041 private:
1042 friend class Symbol;
1043 typedef FieldOptions OptionsType;
1044
1045
1046 friend class io::Printer;
1047 friend class compiler::cpp::Formatter;
1048 friend class Reflection;
1049 friend class FieldDescriptorLegacy;
1050
1051
1052
1053 bool has_optional_keyword() const;
1054
1055
1056
1057
1058
1059 const FeatureSet& features() const { return *merged_features_; }
1060 friend class internal::InternalFeatureHelper;
1061
1062
1063 void CopyJsonNameTo(FieldDescriptorProto* proto) const;
1064
1065
1066 void DebugString(int depth, std::string* contents,
1067 const DebugStringOptions& options) const;
1068
1069
1070
1071
1072 std::string DefaultValueAsString(bool quote_string_type) const;
1073
1074
1075 std::string FieldTypeNameDebugString() const;
1076
1077
1078
1079 void GetLocationPath(std::vector<int>* output) const;
1080
1081
1082 bool is_map_message_type() const;
1083
1084 bool has_default_value_ : 1;
1085 bool proto3_optional_ : 1;
1086
1087
1088 bool has_json_name_ : 1;
1089 bool is_extension_ : 1;
1090 bool is_oneof_ : 1;
1091 bool is_repeated_ : 1;
1092
1093
1094 uint8_t label_ : 2;
1095
1096
1097 uint8_t type_;
1098
1099
1100
1101
1102
1103
1104
1105
1106 uint8_t lowercase_name_index_ : 2;
1107 uint8_t camelcase_name_index_ : 2;
1108 uint8_t json_name_index_ : 3;
1109
1110
1111
1112 bool in_real_oneof_ : 1;
1113
1114
1115
1116 int number_;
1117 const std::string* all_names_;
1118 const FileDescriptor* file_;
1119
1120
1121
1122 absl::once_flag* type_once_;
1123 static void TypeOnceInit(const FieldDescriptor* to_init);
1124 void InternalTypeOnceInit() const;
1125 const Descriptor* containing_type_;
1126 union {
1127 const OneofDescriptor* containing_oneof;
1128 const Descriptor* extension_scope;
1129 } scope_;
1130 union {
1131 mutable const Descriptor* message_type;
1132 mutable const EnumDescriptor* enum_type;
1133 } type_descriptor_;
1134 const FieldOptions* options_;
1135 const FeatureSet* proto_features_;
1136 const FeatureSet* merged_features_;
1137
1138
1139
1140
1141 union {
1142 int32_t default_value_int32_t_;
1143 int64_t default_value_int64_t_;
1144 uint32_t default_value_uint32_t_;
1145 uint64_t default_value_uint64_t_;
1146 float default_value_float_;
1147 double default_value_double_;
1148 bool default_value_bool_;
1149
1150 mutable const EnumValueDescriptor* default_value_enum_;
1151 const std::string* default_value_string_;
1152 mutable std::atomic<const Message*> default_generated_instance_;
1153 };
1154
1155 static const CppType kTypeToCppTypeMap[MAX_TYPE + 1];
1156
1157 static const char* const kTypeToName[MAX_TYPE + 1];
1158
1159 static const char* const kCppTypeToName[MAX_CPPTYPE + 1];
1160
1161 static const char* const kLabelToName[MAX_LABEL + 1];
1162
1163
1164 FieldDescriptor();
1165 friend class DescriptorBuilder;
1166 friend class FileDescriptor;
1167 friend class Descriptor;
1168 friend class OneofDescriptor;
1169 };
1170
1171 PROTOBUF_INTERNAL_CHECK_CLASS_SIZE(FieldDescriptor, 88);
1172
1173
1174 class PROTOBUF_EXPORT OneofDescriptor : private internal::SymbolBase {
1175 public:
1176 typedef OneofDescriptorProto Proto;
1177
1178 #ifndef SWIG
1179 OneofDescriptor(const OneofDescriptor&) = delete;
1180 OneofDescriptor& operator=(const OneofDescriptor&) = delete;
1181 #endif
1182
1183 const std::string& name() const;
1184 const std::string& full_name() const;
1185
1186
1187 int index() const;
1188
1189
1190 const FileDescriptor* file() const;
1191
1192 const Descriptor* containing_type() const;
1193
1194
1195 int field_count() const;
1196
1197
1198 const FieldDescriptor* field(int index) const;
1199
1200 const OneofOptions& options() const;
1201
1202
1203 void CopyTo(OneofDescriptorProto* proto) const;
1204
1205
1206 std::string DebugString() const;
1207
1208
1209 std::string DebugStringWithOptions(const DebugStringOptions& options) const;
1210
1211
1212 template <typename Sink>
1213 friend void AbslStringify(Sink& sink, const OneofDescriptor& d) {
1214 absl::Format(&sink, "%s", d.DebugString());
1215 }
1216
1217
1218
1219
1220
1221
1222 bool GetSourceLocation(SourceLocation* out_location) const;
1223
1224 private:
1225 friend class Symbol;
1226 typedef OneofOptions OptionsType;
1227
1228
1229 friend class io::Printer;
1230 friend class compiler::cpp::Formatter;
1231 friend class OneofDescriptorLegacy;
1232
1233
1234
1235 bool is_synthetic() const;
1236
1237
1238
1239
1240
1241 const FeatureSet& features() const { return *merged_features_; }
1242 friend class internal::InternalFeatureHelper;
1243
1244
1245 void DebugString(int depth, std::string* contents,
1246 const DebugStringOptions& options) const;
1247
1248
1249
1250 void GetLocationPath(std::vector<int>* output) const;
1251
1252 int field_count_;
1253
1254
1255 const std::string* all_names_;
1256 const Descriptor* containing_type_;
1257 const OneofOptions* options_;
1258 const FeatureSet* proto_features_;
1259 const FeatureSet* merged_features_;
1260 const FieldDescriptor* fields_;
1261
1262
1263
1264
1265
1266
1267 OneofDescriptor();
1268 friend class DescriptorBuilder;
1269 friend class Descriptor;
1270 friend class FieldDescriptor;
1271 friend class Reflection;
1272 };
1273
1274 PROTOBUF_INTERNAL_CHECK_CLASS_SIZE(OneofDescriptor, 56);
1275
1276
1277
1278
1279 class PROTOBUF_EXPORT EnumDescriptor : private internal::SymbolBase {
1280 public:
1281 typedef EnumDescriptorProto Proto;
1282
1283 #ifndef SWIG
1284 EnumDescriptor(const EnumDescriptor&) = delete;
1285 EnumDescriptor& operator=(const EnumDescriptor&) = delete;
1286 #endif
1287
1288
1289 const std::string& name() const;
1290
1291
1292 const std::string& full_name() const;
1293
1294
1295 int index() const;
1296
1297
1298 const FileDescriptor* file() const;
1299
1300
1301
1302 int value_count() const;
1303
1304
1305 const EnumValueDescriptor* value(int index) const;
1306
1307
1308 const EnumValueDescriptor* FindValueByName(absl::string_view name) const;
1309
1310
1311 const EnumValueDescriptor* FindValueByNumber(int number) const;
1312
1313
1314
1315 const Descriptor* containing_type() const;
1316
1317
1318
1319
1320
1321 const EnumOptions& options() const;
1322
1323
1324 void CopyTo(EnumDescriptorProto* proto) const;
1325
1326
1327 std::string DebugString() const;
1328
1329
1330 std::string DebugStringWithOptions(const DebugStringOptions& options) const;
1331
1332
1333 template <typename Sink>
1334 friend void AbslStringify(Sink& sink, const EnumDescriptor& d) {
1335 absl::Format(&sink, "%s", d.DebugString());
1336 }
1337
1338
1339
1340
1341 bool is_placeholder() const;
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360 bool is_closed() const;
1361
1362
1363
1364
1365 struct ReservedRange {
1366 int start;
1367 int end;
1368 };
1369
1370
1371 int reserved_range_count() const;
1372
1373
1374
1375 const EnumDescriptor::ReservedRange* reserved_range(int index) const;
1376
1377
1378 bool IsReservedNumber(int number) const;
1379
1380
1381 const EnumDescriptor::ReservedRange* FindReservedRangeContainingNumber(
1382 int number) const;
1383
1384
1385 int reserved_name_count() const;
1386
1387
1388 const std::string& reserved_name(int index) const;
1389
1390
1391 bool IsReservedName(absl::string_view name) const;
1392
1393
1394
1395
1396
1397
1398 bool GetSourceLocation(SourceLocation* out_location) const;
1399
1400 private:
1401 friend class Symbol;
1402 friend bool internal::IsEnumFullySequential(const EnumDescriptor* enum_desc);
1403 typedef EnumOptions OptionsType;
1404
1405
1406 friend class io::Printer;
1407 friend class compiler::cpp::Formatter;
1408
1409
1410 friend class descriptor_unittest::DescriptorTest;
1411
1412
1413
1414
1415
1416 const FeatureSet& features() const { return *merged_features_; }
1417 friend class internal::InternalFeatureHelper;
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427 const EnumValueDescriptor* FindValueByNumberCreatingIfUnknown(
1428 int number) const;
1429
1430
1431 void DebugString(int depth, std::string* contents,
1432 const DebugStringOptions& options) const;
1433
1434
1435
1436 void GetLocationPath(std::vector<int>* output) const;
1437
1438
1439 bool is_placeholder_ : 1;
1440
1441 bool is_unqualified_placeholder_ : 1;
1442
1443
1444
1445
1446
1447
1448
1449
1450 int16_t sequential_value_limit_;
1451
1452 int value_count_;
1453
1454
1455 const std::string* all_names_;
1456 const FileDescriptor* file_;
1457 const Descriptor* containing_type_;
1458 const EnumOptions* options_;
1459 const FeatureSet* proto_features_;
1460 const FeatureSet* merged_features_;
1461 EnumValueDescriptor* values_;
1462
1463 int reserved_range_count_;
1464 int reserved_name_count_;
1465 EnumDescriptor::ReservedRange* reserved_ranges_;
1466 const std::string** reserved_names_;
1467
1468
1469
1470
1471
1472
1473 EnumDescriptor();
1474 friend class DescriptorBuilder;
1475 friend class Descriptor;
1476 friend class FieldDescriptor;
1477 friend class FileDescriptorTables;
1478 friend class EnumValueDescriptor;
1479 friend class FileDescriptor;
1480 friend class DescriptorPool;
1481 friend class Reflection;
1482 };
1483
1484 PROTOBUF_INTERNAL_CHECK_CLASS_SIZE(EnumDescriptor, 88);
1485
1486
1487
1488
1489
1490
1491 class PROTOBUF_EXPORT EnumValueDescriptor : private internal::SymbolBaseN<0>,
1492 private internal::SymbolBaseN<1> {
1493 public:
1494 typedef EnumValueDescriptorProto Proto;
1495
1496 #ifndef SWIG
1497 EnumValueDescriptor(const EnumValueDescriptor&) = delete;
1498 EnumValueDescriptor& operator=(const EnumValueDescriptor&) = delete;
1499 #endif
1500
1501 const std::string& name() const;
1502 int index() const;
1503 int number() const;
1504
1505
1506
1507
1508
1509
1510 const std::string& full_name() const;
1511
1512
1513 const FileDescriptor* file() const;
1514
1515 const EnumDescriptor* type() const;
1516
1517
1518
1519
1520
1521 const EnumValueOptions& options() const;
1522
1523
1524 void CopyTo(EnumValueDescriptorProto* proto) const;
1525
1526
1527 std::string DebugString() const;
1528
1529
1530 std::string DebugStringWithOptions(const DebugStringOptions& options) const;
1531
1532
1533 template <typename Sink>
1534 friend void AbslStringify(Sink& sink, const EnumValueDescriptor& d) {
1535 absl::Format(&sink, "%s", d.DebugString());
1536 }
1537
1538
1539
1540
1541
1542
1543 bool GetSourceLocation(SourceLocation* out_location) const;
1544
1545 private:
1546 friend class Symbol;
1547 typedef EnumValueOptions OptionsType;
1548
1549
1550 friend class io::Printer;
1551 friend class compiler::cpp::Formatter;
1552
1553
1554
1555
1556
1557 const FeatureSet& features() const { return *merged_features_; }
1558 friend class internal::InternalFeatureHelper;
1559
1560
1561 void DebugString(int depth, std::string* contents,
1562 const DebugStringOptions& options) const;
1563
1564
1565
1566 void GetLocationPath(std::vector<int>* output) const;
1567
1568 int number_;
1569
1570 const std::string* all_names_;
1571 const EnumDescriptor* type_;
1572 const EnumValueOptions* options_;
1573 const FeatureSet* proto_features_;
1574 const FeatureSet* merged_features_;
1575
1576
1577
1578
1579
1580 EnumValueDescriptor();
1581 friend class DescriptorBuilder;
1582 friend class EnumDescriptor;
1583 friend class DescriptorPool;
1584 friend class FileDescriptorTables;
1585 friend class Reflection;
1586 };
1587
1588 PROTOBUF_INTERNAL_CHECK_CLASS_SIZE(EnumValueDescriptor, 48);
1589
1590
1591
1592 class PROTOBUF_EXPORT ServiceDescriptor : private internal::SymbolBase {
1593 public:
1594 typedef ServiceDescriptorProto Proto;
1595
1596 #ifndef SWIG
1597 ServiceDescriptor(const ServiceDescriptor&) = delete;
1598 ServiceDescriptor& operator=(const ServiceDescriptor&) = delete;
1599 #endif
1600
1601
1602 const std::string& name() const;
1603
1604 const std::string& full_name() const;
1605
1606 int index() const;
1607
1608
1609 const FileDescriptor* file() const;
1610
1611
1612
1613
1614
1615 const ServiceOptions& options() const;
1616
1617
1618 int method_count() const;
1619
1620
1621 const MethodDescriptor* method(int index) const;
1622
1623
1624 const MethodDescriptor* FindMethodByName(absl::string_view name) const;
1625
1626
1627 void CopyTo(ServiceDescriptorProto* proto) const;
1628
1629
1630 std::string DebugString() const;
1631
1632
1633 std::string DebugStringWithOptions(const DebugStringOptions& options) const;
1634
1635
1636 template <typename Sink>
1637 friend void AbslStringify(Sink& sink, const ServiceDescriptor& d) {
1638 absl::Format(&sink, "%s", d.DebugString());
1639 }
1640
1641
1642
1643
1644
1645
1646 bool GetSourceLocation(SourceLocation* out_location) const;
1647
1648 private:
1649 friend class Symbol;
1650 typedef ServiceOptions OptionsType;
1651
1652
1653 friend class io::Printer;
1654 friend class compiler::cpp::Formatter;
1655
1656
1657
1658
1659
1660 const FeatureSet& features() const { return *merged_features_; }
1661 friend class internal::InternalFeatureHelper;
1662
1663
1664 void DebugString(std::string* contents,
1665 const DebugStringOptions& options) const;
1666
1667
1668
1669 void GetLocationPath(std::vector<int>* output) const;
1670
1671
1672 const std::string* all_names_;
1673 const FileDescriptor* file_;
1674 const ServiceOptions* options_;
1675 const FeatureSet* proto_features_;
1676 const FeatureSet* merged_features_;
1677 MethodDescriptor* methods_;
1678 int method_count_;
1679
1680
1681
1682
1683
1684 ServiceDescriptor();
1685 friend class DescriptorBuilder;
1686 friend class FileDescriptor;
1687 friend class MethodDescriptor;
1688 };
1689
1690 PROTOBUF_INTERNAL_CHECK_CLASS_SIZE(ServiceDescriptor, 64);
1691
1692
1693
1694
1695
1696 class PROTOBUF_EXPORT MethodDescriptor : private internal::SymbolBase {
1697 public:
1698 typedef MethodDescriptorProto Proto;
1699
1700 #ifndef SWIG
1701 MethodDescriptor(const MethodDescriptor&) = delete;
1702 MethodDescriptor& operator=(const MethodDescriptor&) = delete;
1703 #endif
1704
1705
1706 const std::string& name() const;
1707
1708 const std::string& full_name() const;
1709
1710 int index() const;
1711
1712
1713 const FileDescriptor* file() const;
1714
1715 const ServiceDescriptor* service() const;
1716
1717
1718 const Descriptor* input_type() const;
1719
1720 const Descriptor* output_type() const;
1721
1722
1723 bool client_streaming() const;
1724
1725 bool server_streaming() const;
1726
1727
1728
1729
1730
1731 const MethodOptions& options() const;
1732
1733
1734 void CopyTo(MethodDescriptorProto* proto) const;
1735
1736
1737 std::string DebugString() const;
1738
1739
1740 std::string DebugStringWithOptions(const DebugStringOptions& options) const;
1741
1742
1743 template <typename Sink>
1744 friend void AbslStringify(Sink& sink, const MethodDescriptor& d) {
1745 absl::Format(&sink, "%s", d.DebugString());
1746 }
1747
1748
1749
1750
1751
1752
1753 bool GetSourceLocation(SourceLocation* out_location) const;
1754
1755 private:
1756 friend class Symbol;
1757 typedef MethodOptions OptionsType;
1758
1759
1760 friend class io::Printer;
1761 friend class compiler::cpp::Formatter;
1762
1763
1764
1765
1766
1767 const FeatureSet& features() const { return *merged_features_; }
1768 friend class internal::InternalFeatureHelper;
1769
1770
1771 void DebugString(int depth, std::string* contents,
1772 const DebugStringOptions& options) const;
1773
1774
1775
1776 void GetLocationPath(std::vector<int>* output) const;
1777
1778 bool client_streaming_;
1779 bool server_streaming_;
1780
1781 const std::string* all_names_;
1782 const ServiceDescriptor* service_;
1783 mutable internal::LazyDescriptor input_type_;
1784 mutable internal::LazyDescriptor output_type_;
1785 const MethodOptions* options_;
1786 const FeatureSet* proto_features_;
1787 const FeatureSet* merged_features_;
1788
1789
1790
1791
1792
1793 MethodDescriptor();
1794 friend class DescriptorBuilder;
1795 friend class ServiceDescriptor;
1796 };
1797
1798 PROTOBUF_INTERNAL_CHECK_CLASS_SIZE(MethodDescriptor, 80);
1799
1800
1801
1802
1803 class PROTOBUF_EXPORT FileDescriptor : private internal::SymbolBase {
1804 public:
1805 typedef FileDescriptorProto Proto;
1806
1807 #ifndef SWIG
1808 FileDescriptor(const FileDescriptor&) = delete;
1809 FileDescriptor& operator=(const FileDescriptor&) = delete;
1810 #endif
1811
1812
1813
1814 const std::string& name() const;
1815
1816
1817 const std::string& package() const;
1818
1819
1820
1821 const DescriptorPool* pool() const;
1822
1823
1824 int dependency_count() const;
1825
1826
1827 const FileDescriptor* dependency(int index) const;
1828
1829
1830
1831 int public_dependency_count() const;
1832
1833
1834
1835 const FileDescriptor* public_dependency(int index) const;
1836
1837
1838
1839 int weak_dependency_count() const;
1840
1841
1842
1843 const FileDescriptor* weak_dependency(int index) const;
1844
1845
1846
1847 int message_type_count() const;
1848
1849
1850 const Descriptor* message_type(int index) const;
1851
1852
1853
1854 int enum_type_count() const;
1855
1856
1857 const EnumDescriptor* enum_type(int index) const;
1858
1859
1860 int service_count() const;
1861
1862
1863 const ServiceDescriptor* service(int index) const;
1864
1865
1866
1867 int extension_count() const;
1868
1869
1870 const FieldDescriptor* extension(int index) const;
1871
1872
1873
1874
1875
1876 const FileOptions& options() const;
1877
1878
1879
1880 const Descriptor* FindMessageTypeByName(absl::string_view name) const;
1881
1882 const EnumDescriptor* FindEnumTypeByName(absl::string_view name) const;
1883
1884
1885 const EnumValueDescriptor* FindEnumValueByName(absl::string_view name) const;
1886
1887 const ServiceDescriptor* FindServiceByName(absl::string_view name) const;
1888
1889
1890 const FieldDescriptor* FindExtensionByName(absl::string_view name) const;
1891
1892
1893 const FieldDescriptor* FindExtensionByLowercaseName(
1894 absl::string_view name) const;
1895
1896
1897 const FieldDescriptor* FindExtensionByCamelcaseName(
1898 absl::string_view name) const;
1899
1900
1901
1902
1903
1904 void CopyTo(FileDescriptorProto* proto) const;
1905
1906
1907 void CopySourceCodeInfoTo(FileDescriptorProto* proto) const;
1908
1909
1910 void CopyJsonNameTo(FileDescriptorProto* proto) const;
1911
1912
1913 void CopyHeadingTo(FileDescriptorProto* proto) const;
1914
1915
1916 std::string DebugString() const;
1917
1918
1919 std::string DebugStringWithOptions(const DebugStringOptions& options) const;
1920
1921
1922 template <typename Sink>
1923 friend void AbslStringify(Sink& sink, const FileDescriptor& d) {
1924 absl::Format(&sink, "%s", d.DebugString());
1925 }
1926
1927
1928
1929
1930 bool is_placeholder() const;
1931
1932
1933
1934 bool GetSourceLocation(SourceLocation* out_location) const;
1935
1936
1937
1938
1939
1940
1941 bool GetSourceLocation(const std::vector<int>& path,
1942 SourceLocation* out_location) const;
1943
1944 private:
1945 friend class Symbol;
1946 friend class FileDescriptorLegacy;
1947 typedef FileOptions OptionsType;
1948
1949 bool is_placeholder_;
1950
1951
1952
1953 bool finished_building_;
1954
1955 int extension_count_;
1956
1957 const std::string* name_;
1958 const std::string* package_;
1959 const DescriptorPool* pool_;
1960 Edition edition_;
1961
1962
1963
1964 Edition edition() const;
1965
1966
1967
1968
1969
1970 const FeatureSet& features() const { return *merged_features_; }
1971 friend class internal::InternalFeatureHelper;
1972
1973
1974
1975
1976 absl::once_flag* dependencies_once_;
1977 static void DependenciesOnceInit(const FileDescriptor* to_init);
1978 void InternalDependenciesOnceInit() const;
1979
1980
1981 int dependency_count_;
1982 int public_dependency_count_;
1983 int weak_dependency_count_;
1984 int message_type_count_;
1985 int enum_type_count_;
1986 int service_count_;
1987
1988 mutable const FileDescriptor** dependencies_;
1989 int* public_dependencies_;
1990 int* weak_dependencies_;
1991 Descriptor* message_types_;
1992 EnumDescriptor* enum_types_;
1993 ServiceDescriptor* services_;
1994 FieldDescriptor* extensions_;
1995 const FileOptions* options_;
1996 const FeatureSet* proto_features_;
1997 const FeatureSet* merged_features_;
1998
1999 const FileDescriptorTables* tables_;
2000 const SourceCodeInfo* source_code_info_;
2001
2002
2003
2004
2005
2006 FileDescriptor();
2007 friend class DescriptorBuilder;
2008 friend class DescriptorPool;
2009 friend class Descriptor;
2010 friend class FieldDescriptor;
2011 friend class internal::LazyDescriptor;
2012 friend class OneofDescriptor;
2013 friend class EnumDescriptor;
2014 friend class EnumValueDescriptor;
2015 friend class MethodDescriptor;
2016 friend class ServiceDescriptor;
2017 };
2018
2019 PROTOBUF_INTERNAL_CHECK_CLASS_SIZE(FileDescriptor, 168);
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047 class PROTOBUF_EXPORT DescriptorPool {
2048 public:
2049
2050 DescriptorPool();
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075 class ErrorCollector;
2076 explicit DescriptorPool(DescriptorDatabase* fallback_database,
2077 ErrorCollector* error_collector = nullptr);
2078
2079 #ifndef SWIG
2080 DescriptorPool(const DescriptorPool&) = delete;
2081 DescriptorPool& operator=(const DescriptorPool&) = delete;
2082 #endif
2083 ~DescriptorPool();
2084
2085
2086
2087
2088 static const DescriptorPool* generated_pool();
2089
2090
2091
2092
2093 const FileDescriptor* FindFileByName(absl::string_view name) const;
2094
2095
2096
2097
2098
2099 const FileDescriptor* FindFileContainingSymbol(
2100 absl::string_view symbol_name) const;
2101
2102
2103
2104
2105
2106
2107 const Descriptor* FindMessageTypeByName(absl::string_view name) const;
2108 const FieldDescriptor* FindFieldByName(absl::string_view name) const;
2109 const FieldDescriptor* FindExtensionByName(absl::string_view name) const;
2110 const OneofDescriptor* FindOneofByName(absl::string_view name) const;
2111 const EnumDescriptor* FindEnumTypeByName(absl::string_view name) const;
2112 const EnumValueDescriptor* FindEnumValueByName(absl::string_view name) const;
2113 const ServiceDescriptor* FindServiceByName(absl::string_view name) const;
2114 const MethodDescriptor* FindMethodByName(absl::string_view name) const;
2115
2116
2117
2118 const FieldDescriptor* FindExtensionByNumber(const Descriptor* extendee,
2119 int number) const;
2120
2121
2122
2123
2124
2125
2126 const FieldDescriptor* FindExtensionByPrintableName(
2127 const Descriptor* extendee, absl::string_view printable_name) const;
2128
2129
2130
2131
2132
2133
2134 void FindAllExtensions(const Descriptor* extendee,
2135 std::vector<const FieldDescriptor*>* out) const;
2136
2137
2138
2139
2140
2141
2142 class PROTOBUF_EXPORT ErrorCollector {
2143 public:
2144 inline ErrorCollector() {}
2145 #ifndef SWIG
2146 ErrorCollector(const ErrorCollector&) = delete;
2147 ErrorCollector& operator=(const ErrorCollector&) = delete;
2148 #endif
2149 virtual ~ErrorCollector();
2150
2151
2152
2153
2154 enum ErrorLocation {
2155 NAME,
2156 NUMBER,
2157 TYPE,
2158 EXTENDEE,
2159 DEFAULT_VALUE,
2160 INPUT_TYPE,
2161 OUTPUT_TYPE,
2162 OPTION_NAME,
2163 OPTION_VALUE,
2164 IMPORT,
2165 EDITIONS,
2166 OTHER
2167 };
2168 static absl::string_view ErrorLocationName(ErrorLocation location);
2169
2170
2171
2172
2173
2174
2175
2176
2177
2178 virtual void RecordError(absl::string_view filename,
2179 absl::string_view element_name,
2180 const Message* descriptor, ErrorLocation location,
2181 absl::string_view message)
2182 = 0;
2183
2184
2185
2186
2187
2188
2189
2190
2191
2192 virtual void RecordWarning(absl::string_view filename,
2193 absl::string_view element_name,
2194 const Message* descriptor,
2195 ErrorLocation location,
2196 absl::string_view message) {
2197 }
2198
2199 };
2200
2201
2202
2203
2204
2205
2206 const FileDescriptor* BuildFile(const FileDescriptorProto& proto);
2207
2208
2209 const FileDescriptor* BuildFileCollectingErrors(
2210 const FileDescriptorProto& proto, ErrorCollector* error_collector);
2211
2212
2213
2214
2215
2216
2217
2218
2219
2220
2221
2222
2223
2224
2225
2226
2227 void AllowUnknownDependencies() { allow_unknown_ = true; }
2228
2229
2230
2231
2232
2233 void EnforceWeakDependencies(bool enforce) { enforce_weak_ = enforce; }
2234
2235
2236
2237
2238
2239
2240 absl::Status SetFeatureSetDefaults(FeatureSetDefaults spec);
2241
2242
2243
2244
2245
2246 void EnforceExtensionDeclarations(bool enforce) {
2247 enforce_extension_declarations_ = enforce;
2248 }
2249
2250 #ifndef SWIG
2251
2252
2253
2254
2255 void SetRecursiveBuildDispatcher(
2256 absl::AnyInvocable<void(absl::FunctionRef<void()>) const> dispatcher) {
2257 if (dispatcher != nullptr) {
2258 dispatcher_ = std::make_unique<
2259 absl::AnyInvocable<void(absl::FunctionRef<void()>) const>>(
2260 std::move(dispatcher));
2261 } else {
2262 dispatcher_.reset(nullptr);
2263 }
2264 }
2265 #endif
2266
2267
2268
2269
2270
2271
2272
2273
2274
2275
2276
2277
2278
2279
2280
2281
2282
2283
2284
2285
2286
2287
2288
2289
2290
2291
2292 explicit DescriptorPool(const DescriptorPool* underlay);
2293
2294
2295
2296
2297 static void InternalAddGeneratedFile(const void* encoded_file_descriptor,
2298 int size);
2299
2300
2301 void DisallowEnforceUtf8() { disallow_enforce_utf8_ = true; }
2302
2303
2304 ABSL_DEPRECATED("Deprecated treatment of field name conflicts is enabled.")
2305 void UseDeprecatedLegacyJsonFieldConflicts() {
2306 deprecated_legacy_json_field_conflicts_ = true;
2307 }
2308
2309
2310
2311
2312
2313
2314 static DescriptorPool* internal_generated_pool();
2315
2316
2317
2318
2319 static DescriptorDatabase* internal_generated_database();
2320
2321
2322
2323
2324 void InternalDontEnforceDependencies();
2325
2326
2327
2328
2329
2330
2331
2332
2333
2334 void InternalSetLazilyBuildDependencies() {
2335 lazily_build_dependencies_ = true;
2336
2337
2338 InternalDontEnforceDependencies();
2339 }
2340
2341
2342 void internal_set_underlay(const DescriptorPool* underlay) {
2343 underlay_ = underlay;
2344 }
2345
2346
2347
2348
2349 bool InternalIsFileLoaded(absl::string_view filename) const;
2350
2351
2352
2353 void AddUnusedImportTrackFile(absl::string_view file_name,
2354 bool is_error = false);
2355 void ClearUnusedImportTrackFiles();
2356
2357 private:
2358 friend class Descriptor;
2359 friend class internal::LazyDescriptor;
2360 friend class FieldDescriptor;
2361 friend class EnumDescriptor;
2362 friend class ServiceDescriptor;
2363 friend class MethodDescriptor;
2364 friend class FileDescriptor;
2365 friend class DescriptorBuilder;
2366 friend class FileDescriptorTables;
2367 friend class google::protobuf::descriptor_unittest::ValidationErrorTest;
2368 friend class ::google::protobuf::compiler::CommandLineInterface;
2369
2370
2371
2372
2373 bool IsSubSymbolOfBuiltType(absl::string_view name) const;
2374
2375
2376
2377
2378
2379
2380
2381
2382 class DeferredValidation;
2383 bool TryFindFileInFallbackDatabase(
2384 absl::string_view name, DeferredValidation& deferred_validation) const;
2385 bool TryFindSymbolInFallbackDatabase(
2386 absl::string_view name, DeferredValidation& deferred_validation) const;
2387 bool TryFindExtensionInFallbackDatabase(
2388 const Descriptor* containing_type, int field_number,
2389 DeferredValidation& deferred_validation) const;
2390
2391
2392
2393
2394 const FieldDescriptor* InternalFindExtensionByNumberNoLock(
2395 const Descriptor* extendee, int number) const;
2396
2397
2398
2399
2400 const FileDescriptor* BuildFileFromDatabase(
2401 const FileDescriptorProto& proto,
2402 DeferredValidation& deferred_validation) const;
2403
2404
2405
2406
2407
2408
2409 Symbol CrossLinkOnDemandHelper(absl::string_view name,
2410 bool expecting_enum) const;
2411
2412
2413 FileDescriptor* NewPlaceholderFile(absl::string_view name) const;
2414 FileDescriptor* NewPlaceholderFileWithMutexHeld(
2415 absl::string_view name, internal::FlatAllocator& alloc) const;
2416
2417 enum PlaceholderType {
2418 PLACEHOLDER_MESSAGE,
2419 PLACEHOLDER_ENUM,
2420 PLACEHOLDER_EXTENDABLE_MESSAGE
2421 };
2422
2423 Symbol NewPlaceholder(absl::string_view name,
2424 PlaceholderType placeholder_type) const;
2425 Symbol NewPlaceholderWithMutexHeld(absl::string_view name,
2426 PlaceholderType placeholder_type) const;
2427
2428
2429
2430 absl::Mutex* mutex_;
2431
2432
2433 DescriptorDatabase* fallback_database_;
2434 ErrorCollector* default_error_collector_;
2435 const DescriptorPool* underlay_;
2436
2437 #ifndef SWIG
2438
2439 std::unique_ptr<absl::AnyInvocable<void(absl::FunctionRef<void()>) const>>
2440 dispatcher_;
2441 #endif
2442
2443
2444
2445 class Tables;
2446 std::unique_ptr<Tables> tables_;
2447
2448 bool enforce_dependencies_;
2449 bool lazily_build_dependencies_;
2450 bool allow_unknown_;
2451 bool enforce_weak_;
2452 bool enforce_extension_declarations_;
2453 bool disallow_enforce_utf8_;
2454 bool deprecated_legacy_json_field_conflicts_;
2455 mutable bool build_started_ = false;
2456
2457
2458
2459 absl::flat_hash_map<std::string, bool> unused_import_track_files_;
2460
2461
2462
2463 std::unique_ptr<FeatureSetDefaults> feature_set_defaults_spec_;
2464
2465
2466 bool IsReadyForCheckingDescriptorExtDecl(
2467 absl::string_view message_name) const;
2468
2469 };
2470
2471
2472
2473
2474
2475 #define PROTOBUF_DEFINE_ACCESSOR(CLASS, FIELD, TYPE) \
2476 inline TYPE CLASS::FIELD() const { return FIELD##_; }
2477
2478
2479 #define PROTOBUF_DEFINE_STRING_ACCESSOR(CLASS, FIELD) \
2480 inline const std::string& CLASS::FIELD() const { return *FIELD##_; }
2481
2482
2483 #define PROTOBUF_DEFINE_NAME_ACCESSOR(CLASS) \
2484 inline const std::string& CLASS::name() const { return all_names_[0]; } \
2485 inline const std::string& CLASS::full_name() const { return all_names_[1]; }
2486
2487
2488 #define PROTOBUF_DEFINE_ARRAY_ACCESSOR(CLASS, FIELD, TYPE) \
2489 inline TYPE CLASS::FIELD(int index) const { \
2490 ABSL_DCHECK_LE(0, index); \
2491 ABSL_DCHECK_LT(index, FIELD##_count()); \
2492 return FIELD##s_ + index; \
2493 }
2494
2495 #define PROTOBUF_DEFINE_OPTIONS_ACCESSOR(CLASS, TYPE) \
2496 inline const TYPE& CLASS::options() const { return *options_; }
2497
2498 PROTOBUF_DEFINE_NAME_ACCESSOR(Descriptor)
2499 PROTOBUF_DEFINE_ACCESSOR(Descriptor, file, const FileDescriptor*)
2500 PROTOBUF_DEFINE_ACCESSOR(Descriptor, containing_type, const Descriptor*)
2501
2502 PROTOBUF_DEFINE_ACCESSOR(Descriptor, field_count, int)
2503 PROTOBUF_DEFINE_ACCESSOR(Descriptor, oneof_decl_count, int)
2504 PROTOBUF_DEFINE_ACCESSOR(Descriptor, real_oneof_decl_count, int)
2505 PROTOBUF_DEFINE_ACCESSOR(Descriptor, nested_type_count, int)
2506 PROTOBUF_DEFINE_ACCESSOR(Descriptor, enum_type_count, int)
2507
2508 PROTOBUF_DEFINE_ARRAY_ACCESSOR(Descriptor, field, const FieldDescriptor*)
2509 PROTOBUF_DEFINE_ARRAY_ACCESSOR(Descriptor, oneof_decl, const OneofDescriptor*)
2510 PROTOBUF_DEFINE_ARRAY_ACCESSOR(Descriptor, nested_type, const Descriptor*)
2511 PROTOBUF_DEFINE_ARRAY_ACCESSOR(Descriptor, enum_type, const EnumDescriptor*)
2512 inline const OneofDescriptor* Descriptor::real_oneof_decl(int index) const {
2513 ABSL_DCHECK(index < real_oneof_decl_count());
2514 return oneof_decl(index);
2515 }
2516
2517 PROTOBUF_DEFINE_ACCESSOR(Descriptor, extension_range_count, int)
2518 PROTOBUF_DEFINE_ACCESSOR(Descriptor, extension_count, int)
2519 PROTOBUF_DEFINE_ARRAY_ACCESSOR(Descriptor, extension_range,
2520 const Descriptor::ExtensionRange*)
2521 PROTOBUF_DEFINE_ARRAY_ACCESSOR(Descriptor, extension, const FieldDescriptor*)
2522
2523 PROTOBUF_DEFINE_ACCESSOR(Descriptor, reserved_range_count, int)
2524 PROTOBUF_DEFINE_ARRAY_ACCESSOR(Descriptor, reserved_range,
2525 const Descriptor::ReservedRange*)
2526 PROTOBUF_DEFINE_ACCESSOR(Descriptor, reserved_name_count, int)
2527
2528 PROTOBUF_DEFINE_OPTIONS_ACCESSOR(Descriptor, MessageOptions)
2529 PROTOBUF_DEFINE_ACCESSOR(Descriptor, is_placeholder, bool)
2530
2531 PROTOBUF_DEFINE_NAME_ACCESSOR(FieldDescriptor)
2532 PROTOBUF_DEFINE_ACCESSOR(FieldDescriptor, file, const FileDescriptor*)
2533 PROTOBUF_DEFINE_ACCESSOR(FieldDescriptor, number, int)
2534 PROTOBUF_DEFINE_ACCESSOR(FieldDescriptor, is_extension, bool)
2535 PROTOBUF_DEFINE_ACCESSOR(FieldDescriptor, containing_type, const Descriptor*)
2536 PROTOBUF_DEFINE_OPTIONS_ACCESSOR(FieldDescriptor, FieldOptions)
2537 PROTOBUF_DEFINE_ACCESSOR(FieldDescriptor, has_default_value, bool)
2538 PROTOBUF_DEFINE_ACCESSOR(FieldDescriptor, has_json_name, bool)
2539 PROTOBUF_DEFINE_ACCESSOR(FieldDescriptor, default_value_int32_t, int32_t)
2540 PROTOBUF_DEFINE_ACCESSOR(FieldDescriptor, default_value_int64_t, int64_t)
2541 PROTOBUF_DEFINE_ACCESSOR(FieldDescriptor, default_value_uint32_t, uint32_t)
2542 PROTOBUF_DEFINE_ACCESSOR(FieldDescriptor, default_value_uint64_t, uint64_t)
2543 PROTOBUF_DEFINE_ACCESSOR(FieldDescriptor, default_value_float, float)
2544 PROTOBUF_DEFINE_ACCESSOR(FieldDescriptor, default_value_double, double)
2545 PROTOBUF_DEFINE_ACCESSOR(FieldDescriptor, default_value_bool, bool)
2546 PROTOBUF_DEFINE_STRING_ACCESSOR(FieldDescriptor, default_value_string)
2547
2548 PROTOBUF_DEFINE_NAME_ACCESSOR(OneofDescriptor)
2549 PROTOBUF_DEFINE_ACCESSOR(OneofDescriptor, containing_type, const Descriptor*)
2550 PROTOBUF_DEFINE_ACCESSOR(OneofDescriptor, field_count, int)
2551 PROTOBUF_DEFINE_ARRAY_ACCESSOR(OneofDescriptor, field, const FieldDescriptor*)
2552 PROTOBUF_DEFINE_OPTIONS_ACCESSOR(OneofDescriptor, OneofOptions)
2553
2554 PROTOBUF_DEFINE_NAME_ACCESSOR(EnumDescriptor)
2555 PROTOBUF_DEFINE_ACCESSOR(EnumDescriptor, file, const FileDescriptor*)
2556 PROTOBUF_DEFINE_ACCESSOR(EnumDescriptor, containing_type, const Descriptor*)
2557 PROTOBUF_DEFINE_ACCESSOR(EnumDescriptor, value_count, int)
2558 PROTOBUF_DEFINE_ARRAY_ACCESSOR(EnumDescriptor, value,
2559 const EnumValueDescriptor*)
2560 PROTOBUF_DEFINE_OPTIONS_ACCESSOR(EnumDescriptor, EnumOptions)
2561 PROTOBUF_DEFINE_ACCESSOR(EnumDescriptor, is_placeholder, bool)
2562 PROTOBUF_DEFINE_ACCESSOR(EnumDescriptor, reserved_range_count, int)
2563 PROTOBUF_DEFINE_ARRAY_ACCESSOR(EnumDescriptor, reserved_range,
2564 const EnumDescriptor::ReservedRange*)
2565 PROTOBUF_DEFINE_ACCESSOR(EnumDescriptor, reserved_name_count, int)
2566
2567 PROTOBUF_DEFINE_NAME_ACCESSOR(EnumValueDescriptor)
2568 PROTOBUF_DEFINE_ACCESSOR(EnumValueDescriptor, number, int)
2569 PROTOBUF_DEFINE_ACCESSOR(EnumValueDescriptor, type, const EnumDescriptor*)
2570 PROTOBUF_DEFINE_OPTIONS_ACCESSOR(EnumValueDescriptor, EnumValueOptions)
2571
2572 PROTOBUF_DEFINE_NAME_ACCESSOR(ServiceDescriptor)
2573 PROTOBUF_DEFINE_ACCESSOR(ServiceDescriptor, file, const FileDescriptor*)
2574 PROTOBUF_DEFINE_ACCESSOR(ServiceDescriptor, method_count, int)
2575 PROTOBUF_DEFINE_ARRAY_ACCESSOR(ServiceDescriptor, method,
2576 const MethodDescriptor*)
2577 PROTOBUF_DEFINE_OPTIONS_ACCESSOR(ServiceDescriptor, ServiceOptions)
2578
2579 PROTOBUF_DEFINE_NAME_ACCESSOR(MethodDescriptor)
2580 PROTOBUF_DEFINE_ACCESSOR(MethodDescriptor, service, const ServiceDescriptor*)
2581 PROTOBUF_DEFINE_OPTIONS_ACCESSOR(MethodDescriptor, MethodOptions)
2582 PROTOBUF_DEFINE_ACCESSOR(MethodDescriptor, client_streaming, bool)
2583 PROTOBUF_DEFINE_ACCESSOR(MethodDescriptor, server_streaming, bool)
2584
2585 PROTOBUF_DEFINE_STRING_ACCESSOR(FileDescriptor, name)
2586 PROTOBUF_DEFINE_STRING_ACCESSOR(FileDescriptor, package)
2587 PROTOBUF_DEFINE_ACCESSOR(FileDescriptor, pool, const DescriptorPool*)
2588 PROTOBUF_DEFINE_ACCESSOR(FileDescriptor, dependency_count, int)
2589 PROTOBUF_DEFINE_ACCESSOR(FileDescriptor, public_dependency_count, int)
2590 PROTOBUF_DEFINE_ACCESSOR(FileDescriptor, weak_dependency_count, int)
2591 PROTOBUF_DEFINE_ACCESSOR(FileDescriptor, message_type_count, int)
2592 PROTOBUF_DEFINE_ACCESSOR(FileDescriptor, enum_type_count, int)
2593 PROTOBUF_DEFINE_ACCESSOR(FileDescriptor, service_count, int)
2594 PROTOBUF_DEFINE_ACCESSOR(FileDescriptor, extension_count, int)
2595 PROTOBUF_DEFINE_OPTIONS_ACCESSOR(FileDescriptor, FileOptions)
2596 PROTOBUF_DEFINE_ACCESSOR(FileDescriptor, is_placeholder, bool)
2597
2598 PROTOBUF_DEFINE_ARRAY_ACCESSOR(FileDescriptor, message_type, const Descriptor*)
2599 PROTOBUF_DEFINE_ARRAY_ACCESSOR(FileDescriptor, enum_type, const EnumDescriptor*)
2600 PROTOBUF_DEFINE_ARRAY_ACCESSOR(FileDescriptor, service,
2601 const ServiceDescriptor*)
2602 PROTOBUF_DEFINE_ARRAY_ACCESSOR(FileDescriptor, extension,
2603 const FieldDescriptor*)
2604
2605 #undef PROTOBUF_DEFINE_ACCESSOR
2606 #undef PROTOBUF_DEFINE_STRING_ACCESSOR
2607 #undef PROTOBUF_DEFINE_ARRAY_ACCESSOR
2608
2609
2610
2611 inline Descriptor::WellKnownType Descriptor::well_known_type() const {
2612 return static_cast<Descriptor::WellKnownType>(well_known_type_);
2613 }
2614
2615 inline bool Descriptor::IsExtensionNumber(int number) const {
2616 return FindExtensionRangeContainingNumber(number) != nullptr;
2617 }
2618
2619 inline bool Descriptor::IsReservedNumber(int number) const {
2620 return FindReservedRangeContainingNumber(number) != nullptr;
2621 }
2622
2623 inline bool Descriptor::IsReservedName(absl::string_view name) const {
2624 for (int i = 0; i < reserved_name_count(); i++) {
2625 if (name == static_cast<absl::string_view>(reserved_name(i))) {
2626 return true;
2627 }
2628 }
2629 return false;
2630 }
2631
2632
2633
2634 inline const std::string& Descriptor::reserved_name(int index) const {
2635 return *reserved_names_[index];
2636 }
2637
2638 inline bool EnumDescriptor::IsReservedNumber(int number) const {
2639 return FindReservedRangeContainingNumber(number) != nullptr;
2640 }
2641
2642 inline bool EnumDescriptor::IsReservedName(absl::string_view name) const {
2643 for (int i = 0; i < reserved_name_count(); i++) {
2644 if (name == static_cast<absl::string_view>(reserved_name(i))) {
2645 return true;
2646 }
2647 }
2648 return false;
2649 }
2650
2651
2652
2653 inline const std::string& EnumDescriptor::reserved_name(int index) const {
2654 return *reserved_names_[index];
2655 }
2656
2657 inline const std::string& FieldDescriptor::lowercase_name() const {
2658 return all_names_[lowercase_name_index_];
2659 }
2660
2661 inline const std::string& FieldDescriptor::camelcase_name() const {
2662 return all_names_[camelcase_name_index_];
2663 }
2664
2665 inline const std::string& FieldDescriptor::json_name() const {
2666 return all_names_[json_name_index_];
2667 }
2668
2669 inline const OneofDescriptor* FieldDescriptor::containing_oneof() const {
2670 if (is_oneof_) {
2671 auto* res = scope_.containing_oneof;
2672 PROTOBUF_ASSUME(res != nullptr);
2673 return res;
2674 }
2675 return nullptr;
2676 }
2677
2678 inline int FieldDescriptor::index_in_oneof() const {
2679 ABSL_DCHECK(is_oneof_);
2680 return static_cast<int>(this - scope_.containing_oneof->field(0));
2681 }
2682
2683 inline const Descriptor* FieldDescriptor::extension_scope() const {
2684 ABSL_CHECK(is_extension_);
2685 return scope_.extension_scope;
2686 }
2687
2688 inline FieldDescriptor::Label FieldDescriptor::label() const {
2689 return static_cast<Label>(label_);
2690 }
2691
2692 inline FieldDescriptor::Type FieldDescriptor::type() const {
2693 return static_cast<Type>(type_);
2694 }
2695
2696 inline bool FieldDescriptor::is_optional() const {
2697 return label() == LABEL_OPTIONAL;
2698 }
2699
2700 inline bool FieldDescriptor::is_repeated() const {
2701 ABSL_DCHECK_EQ(is_repeated_, label() == LABEL_REPEATED);
2702 return is_repeated_;
2703 }
2704
2705 inline bool FieldDescriptor::is_packable() const {
2706 return is_repeated() && IsTypePackable(type());
2707 }
2708
2709 inline bool FieldDescriptor::is_map() const {
2710 return type() == TYPE_MESSAGE && is_map_message_type();
2711 }
2712
2713 inline const OneofDescriptor* FieldDescriptor::real_containing_oneof() const {
2714 if (in_real_oneof_) {
2715 auto* res = containing_oneof();
2716 PROTOBUF_ASSUME(res != nullptr);
2717 ABSL_DCHECK(!res->is_synthetic());
2718 return res;
2719 }
2720 return nullptr;
2721 }
2722
2723
2724
2725 inline int FieldDescriptor::index() const {
2726 if (!is_extension_) {
2727 return static_cast<int>(this - containing_type()->fields_);
2728 } else if (extension_scope() != nullptr) {
2729 return static_cast<int>(this - extension_scope()->extensions_);
2730 } else {
2731 return static_cast<int>(this - file_->extensions_);
2732 }
2733 }
2734
2735 inline int Descriptor::index() const {
2736 if (containing_type_ == nullptr) {
2737 return static_cast<int>(this - file_->message_types_);
2738 } else {
2739 return static_cast<int>(this - containing_type_->nested_types_);
2740 }
2741 }
2742
2743 inline int Descriptor::ExtensionRange::index() const {
2744 return static_cast<int>(this - containing_type_->extension_ranges_);
2745 }
2746
2747 inline const FileDescriptor* OneofDescriptor::file() const {
2748 return containing_type()->file();
2749 }
2750
2751 inline int OneofDescriptor::index() const {
2752 return static_cast<int>(this - containing_type_->oneof_decls_);
2753 }
2754
2755 inline bool OneofDescriptor::is_synthetic() const {
2756 return field_count() == 1 && field(0)->proto3_optional_;
2757 }
2758
2759 inline int EnumDescriptor::index() const {
2760 if (containing_type_ == nullptr) {
2761 return static_cast<int>(this - file_->enum_types_);
2762 } else {
2763 return static_cast<int>(this - containing_type_->enum_types_);
2764 }
2765 }
2766
2767 inline const FileDescriptor* EnumValueDescriptor::file() const {
2768 return type()->file();
2769 }
2770
2771 inline int EnumValueDescriptor::index() const {
2772 return static_cast<int>(this - type_->values_);
2773 }
2774
2775 inline int ServiceDescriptor::index() const {
2776 return static_cast<int>(this - file_->services_);
2777 }
2778
2779 inline const FileDescriptor* MethodDescriptor::file() const {
2780 return service()->file();
2781 }
2782
2783 inline int MethodDescriptor::index() const {
2784 return static_cast<int>(this - service_->methods_);
2785 }
2786
2787 inline const char* FieldDescriptor::type_name() const {
2788 return kTypeToName[type()];
2789 }
2790
2791 inline FieldDescriptor::CppType FieldDescriptor::cpp_type() const {
2792 return kTypeToCppTypeMap[type()];
2793 }
2794
2795 inline const char* FieldDescriptor::cpp_type_name() const {
2796 return kCppTypeToName[kTypeToCppTypeMap[type()]];
2797 }
2798
2799 inline FieldDescriptor::CppType FieldDescriptor::TypeToCppType(Type type) {
2800 return kTypeToCppTypeMap[type];
2801 }
2802
2803 inline const char* FieldDescriptor::TypeName(Type type) {
2804 return kTypeToName[type];
2805 }
2806
2807 inline const char* FieldDescriptor::CppTypeName(CppType cpp_type) {
2808 return kCppTypeToName[cpp_type];
2809 }
2810
2811 inline bool FieldDescriptor::IsTypePackable(Type field_type) {
2812 return (field_type != FieldDescriptor::TYPE_STRING &&
2813 field_type != FieldDescriptor::TYPE_GROUP &&
2814 field_type != FieldDescriptor::TYPE_MESSAGE &&
2815 field_type != FieldDescriptor::TYPE_BYTES);
2816 }
2817
2818 inline const FileDescriptor* FileDescriptor::public_dependency(
2819 int index) const {
2820 return dependency(public_dependencies_[index]);
2821 }
2822
2823 inline const FileDescriptor* FileDescriptor::weak_dependency(int index) const {
2824 return dependency(weak_dependencies_[index]);
2825 }
2826
2827 namespace internal {
2828
2829 inline bool IsEnumFullySequential(const EnumDescriptor* enum_desc) {
2830 return enum_desc->sequential_value_limit_ == enum_desc->value_count() - 1;
2831 }
2832
2833
2834
2835
2836 template <typename T>
2837 struct FieldRangeImpl;
2838
2839 template <typename T>
2840 FieldRangeImpl<T> FieldRange(const T* desc) {
2841 return {desc};
2842 }
2843
2844 template <typename T>
2845 struct FieldRangeImpl {
2846 struct Iterator {
2847 using iterator_category = std::forward_iterator_tag;
2848 using value_type = const FieldDescriptor*;
2849 using difference_type = int;
2850
2851 value_type operator*() { return descriptor->field(idx); }
2852
2853 friend bool operator==(const Iterator& a, const Iterator& b) {
2854 ABSL_DCHECK(a.descriptor == b.descriptor);
2855 return a.idx == b.idx;
2856 }
2857 friend bool operator!=(const Iterator& a, const Iterator& b) {
2858 return !(a == b);
2859 }
2860
2861 Iterator& operator++() {
2862 idx++;
2863 return *this;
2864 }
2865
2866 int idx;
2867 const T* descriptor;
2868 };
2869
2870 Iterator begin() const { return {0, descriptor}; }
2871 Iterator end() const { return {descriptor->field_count(), descriptor}; }
2872
2873 const T* descriptor;
2874 };
2875
2876
2877
2878
2879
2880
2881 bool ParseNoReflection(absl::string_view from, google::protobuf::MessageLite& to);
2882
2883
2884
2885
2886 namespace cpp {
2887
2888
2889
2890 constexpr int MaxMessageDeclarationNestingDepth() { return 32; }
2891
2892
2893
2894 PROTOBUF_EXPORT bool HasPreservingUnknownEnumSemantics(
2895 const FieldDescriptor* field);
2896
2897 PROTOBUF_EXPORT bool HasHasbit(const FieldDescriptor* field);
2898
2899 #ifndef SWIG
2900
2901
2902 template <typename FieldDesc = FieldDescriptor,
2903 typename FieldOpts = FieldOptions>
2904 typename FieldOpts::CType EffectiveStringCType(const FieldDesc* field) {
2905
2906 switch (field->cpp_string_type()) {
2907 case FieldDescriptor::CppStringType::kCord:
2908 return FieldOpts::CORD;
2909 default:
2910 return FieldOpts::STRING;
2911 }
2912 }
2913
2914 enum class Utf8CheckMode : uint8_t {
2915 kStrict = 0,
2916 kVerify = 1,
2917 kNone = 2,
2918 };
2919 PROTOBUF_EXPORT Utf8CheckMode GetUtf8CheckMode(const FieldDescriptor* field,
2920 bool is_lite);
2921
2922
2923
2924
2925
2926
2927 PROTOBUF_EXPORT bool IsGroupLike(const FieldDescriptor& field);
2928
2929
2930
2931
2932 PROTOBUF_EXPORT bool IsLazilyInitializedFile(absl::string_view filename);
2933
2934 template <typename F>
2935 auto VisitDescriptorsInFileOrder(const Descriptor* desc,
2936 F& f) -> decltype(f(desc)) {
2937 for (int i = 0; i < desc->nested_type_count(); i++) {
2938 if (auto res = VisitDescriptorsInFileOrder(desc->nested_type(i), f)) {
2939 return res;
2940 }
2941 }
2942 if (auto res = f(desc)) return res;
2943 return {};
2944 }
2945
2946
2947
2948
2949
2950
2951 template <typename F>
2952 auto VisitDescriptorsInFileOrder(const FileDescriptor* file,
2953 F f) -> decltype(f(file->message_type(0))) {
2954 for (int i = 0; i < file->message_type_count(); i++) {
2955 if (auto res = VisitDescriptorsInFileOrder(file->message_type(i), f)) {
2956 return res;
2957 }
2958 }
2959 return {};
2960 }
2961 #endif
2962
2963 }
2964 }
2965
2966 }
2967 }
2968
2969 #undef PROTOBUF_INTERNAL_CHECK_CLASS_SIZE
2970 #include "google/protobuf/port_undef.inc"
2971
2972 #endif