File indexing completed on 2025-01-31 10:12:20
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015 #ifndef GOOGLE_PROTOBUF_GENERATED_MESSAGE_REFLECTION_H__
0016 #define GOOGLE_PROTOBUF_GENERATED_MESSAGE_REFLECTION_H__
0017
0018 #include <atomic>
0019 #include <cstddef>
0020 #include <cstdint>
0021 #include <string>
0022
0023 #include "absl/base/call_once.h"
0024 #include "absl/log/absl_check.h"
0025 #include "google/protobuf/descriptor.h"
0026 #include "google/protobuf/generated_enum_reflection.h"
0027 #include "google/protobuf/port.h"
0028 #include "google/protobuf/unknown_field_set.h"
0029
0030
0031 #include "google/protobuf/port_def.inc"
0032
0033 #ifdef SWIG
0034 #error "You cannot SWIG proto headers"
0035 #endif
0036
0037 namespace google {
0038 namespace protobuf {
0039 class MapKey;
0040 class MapValueRef;
0041 class MessageLayoutInspector;
0042 class Message;
0043 struct Metadata;
0044
0045 namespace io {
0046 class CodedOutputStream;
0047 }
0048 }
0049 }
0050
0051 namespace google {
0052 namespace protobuf {
0053 namespace internal {
0054 class DefaultEmptyOneof;
0055
0056 class ExtensionSet;
0057 class WeakFieldMap;
0058
0059
0060
0061
0062 constexpr uint32_t kInvalidFieldOffsetTag = 0x40000000u;
0063
0064
0065 constexpr uint32_t kSplitFieldOffsetMask = 0x80000000u;
0066 constexpr uint32_t kLazyMask = 0x1u;
0067 constexpr uint32_t kInlinedMask = 0x1u;
0068
0069
0070
0071
0072
0073
0074
0075
0076
0077
0078
0079
0080
0081
0082
0083
0084
0085
0086
0087
0088
0089
0090
0091
0092
0093
0094
0095
0096
0097
0098
0099
0100
0101
0102
0103
0104
0105
0106
0107
0108
0109
0110
0111
0112 struct ReflectionSchema {
0113 public:
0114
0115 uint32_t GetObjectSize() const { return static_cast<uint32_t>(object_size_); }
0116
0117 bool InRealOneof(const FieldDescriptor* field) const {
0118 return field->real_containing_oneof();
0119 }
0120
0121
0122
0123 uint32_t GetFieldOffsetNonOneof(const FieldDescriptor* field) const {
0124 ABSL_DCHECK(!InRealOneof(field));
0125 return OffsetValue(offsets_[field->index()], field->type());
0126 }
0127
0128
0129 uint32_t GetFieldOffset(const FieldDescriptor* field) const {
0130 if (InRealOneof(field)) {
0131 size_t offset =
0132 static_cast<size_t>(field->containing_type()->field_count()) +
0133 field->containing_oneof()->index();
0134 return OffsetValue(offsets_[offset], field->type());
0135 } else {
0136 return GetFieldOffsetNonOneof(field);
0137 }
0138 }
0139
0140 bool IsFieldInlined(const FieldDescriptor* field) const {
0141 return Inlined(offsets_[field->index()], field->type());
0142 }
0143
0144 uint32_t GetOneofCaseOffset(const OneofDescriptor* oneof_descriptor) const {
0145 return static_cast<uint32_t>(oneof_case_offset_) +
0146 static_cast<uint32_t>(
0147 static_cast<size_t>(oneof_descriptor->index()) *
0148 sizeof(uint32_t));
0149 }
0150
0151 bool HasHasbits() const { return has_bits_offset_ != -1; }
0152
0153
0154 uint32_t HasBitIndex(const FieldDescriptor* field) const {
0155 if (has_bits_offset_ == -1) return static_cast<uint32_t>(-1);
0156 ABSL_DCHECK(HasHasbits());
0157 return has_bit_indices_[field->index()];
0158 }
0159
0160
0161 uint32_t HasBitsOffset() const {
0162 ABSL_DCHECK(HasHasbits());
0163 return static_cast<uint32_t>(has_bits_offset_);
0164 }
0165
0166 bool HasInlinedString() const { return inlined_string_donated_offset_ != -1; }
0167
0168
0169
0170 uint32_t InlinedStringIndex(const FieldDescriptor* field) const {
0171 ABSL_DCHECK(HasInlinedString());
0172 return inlined_string_indices_[field->index()];
0173 }
0174
0175
0176 uint32_t InlinedStringDonatedOffset() const {
0177 ABSL_DCHECK(HasInlinedString());
0178 return static_cast<uint32_t>(inlined_string_donated_offset_);
0179 }
0180
0181
0182
0183
0184
0185 uint32_t GetMetadataOffset() const {
0186 return static_cast<uint32_t>(metadata_offset_);
0187 }
0188
0189
0190 bool HasExtensionSet() const { return extensions_offset_ != -1; }
0191
0192
0193 uint32_t GetExtensionSetOffset() const {
0194 ABSL_DCHECK(HasExtensionSet());
0195 return static_cast<uint32_t>(extensions_offset_);
0196 }
0197
0198
0199
0200 int GetWeakFieldMapOffset() const { return weak_field_map_offset_; }
0201
0202 bool IsDefaultInstance(const Message& message) const {
0203 return &message == default_instance_;
0204 }
0205
0206
0207
0208 const void* GetFieldDefault(const FieldDescriptor* field) const {
0209 return reinterpret_cast<const uint8_t*>(default_instance_) +
0210 OffsetValue(offsets_[field->index()], field->type());
0211 }
0212
0213
0214 bool IsEagerlyVerifiedLazyField(const FieldDescriptor* field) const {
0215 ABSL_DCHECK_EQ(field->type(), FieldDescriptor::TYPE_MESSAGE);
0216 (void)field;
0217 return false;
0218 }
0219
0220 bool IsSplit() const { return split_offset_ != -1; }
0221
0222 bool IsSplit(const FieldDescriptor* field) const {
0223 return split_offset_ != -1 &&
0224 (offsets_[field->index()] & kSplitFieldOffsetMask) != 0;
0225 }
0226
0227
0228 uint32_t SplitOffset() const {
0229 ABSL_DCHECK(IsSplit());
0230 return static_cast<uint32_t>(split_offset_);
0231 }
0232
0233 uint32_t SizeofSplit() const {
0234 ABSL_DCHECK(IsSplit());
0235 return static_cast<uint32_t>(sizeof_split_);
0236 }
0237
0238
0239 bool HasWeakFields() const { return weak_field_map_offset_ > 0; }
0240
0241
0242
0243
0244
0245
0246
0247 const Message* default_instance_;
0248 const uint32_t* offsets_;
0249 const uint32_t* has_bit_indices_;
0250 int has_bits_offset_;
0251 int metadata_offset_;
0252 int extensions_offset_;
0253 int oneof_case_offset_;
0254 int object_size_;
0255 int weak_field_map_offset_;
0256 const uint32_t* inlined_string_indices_;
0257 int inlined_string_donated_offset_;
0258 int split_offset_;
0259 int sizeof_split_;
0260
0261
0262
0263 static uint32_t OffsetValue(uint32_t v, FieldDescriptor::Type type) {
0264 if (type == FieldDescriptor::TYPE_MESSAGE ||
0265 type == FieldDescriptor::TYPE_STRING ||
0266 type == FieldDescriptor::TYPE_BYTES) {
0267 return v & (~kSplitFieldOffsetMask) & (~kInlinedMask) & (~kLazyMask);
0268 }
0269 return v & (~kSplitFieldOffsetMask);
0270 }
0271
0272 static bool Inlined(uint32_t v, FieldDescriptor::Type type) {
0273 if (type == FieldDescriptor::TYPE_STRING ||
0274 type == FieldDescriptor::TYPE_BYTES) {
0275 return (v & kInlinedMask) != 0u;
0276 } else {
0277
0278 return false;
0279 }
0280 }
0281 };
0282
0283
0284
0285
0286
0287
0288
0289 struct MigrationSchema {
0290 int32_t offsets_index;
0291 int32_t has_bit_indices_index;
0292 int32_t inlined_string_indices_index;
0293 int object_size;
0294 };
0295
0296
0297
0298
0299 struct PROTOBUF_EXPORT DescriptorTable {
0300 mutable bool is_initialized;
0301 bool is_eager;
0302 int size;
0303 const char* descriptor;
0304 const char* filename;
0305 absl::once_flag* once;
0306 const DescriptorTable* const* deps;
0307 int num_deps;
0308 int num_messages;
0309 const MigrationSchema* schemas;
0310 const Message* const* default_instances;
0311 const uint32_t* offsets;
0312
0313 const EnumDescriptor** file_level_enum_descriptors;
0314 const ServiceDescriptor** file_level_service_descriptors;
0315 };
0316
0317
0318
0319
0320
0321
0322 void PROTOBUF_EXPORT AssignDescriptors(const DescriptorTable* table);
0323
0324 void PROTOBUF_EXPORT
0325 AssignDescriptorsOnceInnerCall(const DescriptorTable* table);
0326
0327
0328 PROTOBUF_EXPORT void UnknownFieldSetSerializer(const uint8_t* base,
0329 uint32_t offset, uint32_t tag,
0330 uint32_t has_offset,
0331 io::CodedOutputStream* output);
0332
0333 PROTOBUF_EXPORT void InitializeFileDescriptorDefaultInstances();
0334
0335 PROTOBUF_EXPORT void AddDescriptors(const DescriptorTable* table);
0336
0337 struct PROTOBUF_EXPORT AddDescriptorsRunner {
0338 explicit AddDescriptorsRunner(const DescriptorTable* table);
0339 };
0340
0341
0342
0343
0344
0345 const Message* GetPrototypeForWeakDescriptor(const DescriptorTable* table,
0346 int index, bool force_build);
0347
0348 struct DenseEnumCacheInfo {
0349 std::atomic<const std::string**> cache;
0350 int min_val;
0351 int max_val;
0352 const EnumDescriptor* (*descriptor_fn)();
0353 };
0354 PROTOBUF_EXPORT const std::string& NameOfDenseEnumSlow(int v,
0355 DenseEnumCacheInfo*);
0356
0357
0358
0359
0360
0361
0362 template <const EnumDescriptor* (*descriptor_fn)(), int min_val, int max_val>
0363 const std::string& NameOfDenseEnum(int v) {
0364 static_assert(max_val - min_val >= 0, "Too many enums between min and max.");
0365 static DenseEnumCacheInfo deci = { {}, min_val, max_val,
0366 descriptor_fn};
0367 const std::string** cache = deci.cache.load(std::memory_order_acquire );
0368 if (PROTOBUF_PREDICT_TRUE(cache != nullptr)) {
0369 if (PROTOBUF_PREDICT_TRUE(v >= min_val && v <= max_val)) {
0370 return *cache[v - min_val];
0371 }
0372 }
0373 return NameOfDenseEnumSlow(v, &deci);
0374 }
0375
0376
0377
0378 PROTOBUF_EXPORT bool SplitFieldHasExtraIndirection(
0379 const FieldDescriptor* field);
0380
0381 }
0382 }
0383 }
0384
0385 #include "google/protobuf/port_undef.inc"
0386
0387 #endif