File indexing completed on 2026-08-23 09:12:51
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/base/optimization.h"
0025 #include "absl/log/absl_check.h"
0026 #include "google/protobuf/descriptor.h"
0027 #include "google/protobuf/generated_enum_reflection.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 inline constexpr uint32_t kInvalidFieldOffsetTag = 0x40000000u;
0063
0064
0065 inline constexpr uint32_t kSplitFieldOffsetMask = 0x80000000u;
0066 inline constexpr uint32_t kLazyMask = 0x1u;
0067 inline constexpr uint32_t kInlinedMask = 0x1u;
0068 inline constexpr uint32_t kMicroStringMask = 0x2u;
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
0113 struct ReflectionSchema {
0114 public:
0115
0116 uint32_t GetObjectSize() const { return static_cast<uint32_t>(object_size_); }
0117
0118 bool InRealOneof(const FieldDescriptor* field) const {
0119 return field->real_containing_oneof();
0120 }
0121
0122
0123 template <typename Type = void>
0124 uint32_t GetFieldOffset(const FieldDescriptor* field) const {
0125 return OffsetValue<Type>(offsets_[field->index()], field->type());
0126 }
0127
0128 bool IsFieldInlined(const FieldDescriptor* field) const {
0129 return Inlined(offsets_[field->index()], field->type());
0130 }
0131
0132 bool IsFieldMicroString(const FieldDescriptor* field) const {
0133 return IsMicroString(offsets_[field->index()], field->type());
0134 }
0135
0136 uint32_t GetOneofCaseOffset(const OneofDescriptor* oneof_descriptor) const {
0137 return static_cast<uint32_t>(oneof_case_offset_) +
0138 static_cast<uint32_t>(
0139 static_cast<size_t>(oneof_descriptor->index()) *
0140 sizeof(uint32_t));
0141 }
0142
0143
0144
0145
0146
0147 bool HasHasbits() const { return has_bits_offset_ != -1; }
0148
0149
0150 uint32_t HasBitIndex(const FieldDescriptor* field) const {
0151 ABSL_DCHECK(!field->is_extension());
0152 if (has_bits_offset_ == -1) return static_cast<uint32_t>(-1);
0153 ABSL_DCHECK(HasHasbits());
0154 return has_bit_indices_[field->index()];
0155 }
0156
0157
0158 uint32_t HasBitsOffset() const {
0159 ABSL_DCHECK(HasHasbits());
0160 return static_cast<uint32_t>(has_bits_offset_);
0161 }
0162
0163 bool HasInlinedString() const { return inlined_string_donated_offset_ != -1; }
0164
0165
0166
0167 uint32_t InlinedStringIndex(const FieldDescriptor* field) const {
0168 ABSL_DCHECK(HasInlinedString());
0169 return inlined_string_indices_[field->index()];
0170 }
0171
0172
0173 uint32_t InlinedStringDonatedOffset() const {
0174 ABSL_DCHECK(HasInlinedString());
0175 return static_cast<uint32_t>(inlined_string_donated_offset_);
0176 }
0177
0178
0179 bool HasExtensionSet() const { return extensions_offset_ != -1; }
0180
0181
0182 uint32_t GetExtensionSetOffset() const {
0183 ABSL_DCHECK(HasExtensionSet());
0184 return static_cast<uint32_t>(extensions_offset_);
0185 }
0186
0187
0188
0189 int GetWeakFieldMapOffset() const { return weak_field_map_offset_; }
0190
0191 bool IsDefaultInstance(const Message& message) const {
0192 return &message == default_instance_;
0193 }
0194
0195
0196
0197 const void* GetFieldDefault(const FieldDescriptor* field) const {
0198 return reinterpret_cast<const uint8_t*>(default_instance_) +
0199 OffsetValue<void>(offsets_[field->index()], field->type());
0200 }
0201
0202
0203 bool IsEagerlyVerifiedLazyField(const FieldDescriptor* field) const {
0204 ABSL_DCHECK_EQ(field->type(), FieldDescriptor::TYPE_MESSAGE);
0205 (void)field;
0206 return false;
0207 }
0208
0209 bool IsSplit() const { return split_offset_ != -1; }
0210
0211 bool IsSplit(const FieldDescriptor* field) const {
0212 return split_offset_ != -1 &&
0213 (offsets_[field->index()] & kSplitFieldOffsetMask) != 0;
0214 }
0215
0216
0217 uint32_t SplitOffset() const {
0218 ABSL_DCHECK(IsSplit());
0219 return static_cast<uint32_t>(split_offset_);
0220 }
0221
0222 uint32_t SizeofSplit() const {
0223 ABSL_DCHECK(IsSplit());
0224 return static_cast<uint32_t>(sizeof_split_);
0225 }
0226
0227
0228 bool HasWeakFields() const { return weak_field_map_offset_ > 0; }
0229
0230
0231
0232
0233
0234
0235
0236 const Message* default_instance_;
0237 const uint32_t* offsets_;
0238 const uint32_t* has_bit_indices_;
0239 int has_bits_offset_;
0240 int extensions_offset_;
0241 int oneof_case_offset_;
0242 int object_size_;
0243 int weak_field_map_offset_;
0244 const uint32_t* inlined_string_indices_;
0245 int inlined_string_donated_offset_;
0246 int split_offset_;
0247 int sizeof_split_;
0248
0249
0250
0251 template <typename Type>
0252 static uint32_t OffsetValue(uint32_t v, FieldDescriptor::Type type) {
0253 if constexpr (!std::is_void_v<Type>) {
0254
0255
0256 return v & ~kSplitFieldOffsetMask & ~(alignof(Type) - 1);
0257 }
0258 if (type == FieldDescriptor::TYPE_MESSAGE ||
0259 type == FieldDescriptor::TYPE_STRING ||
0260 type == FieldDescriptor::TYPE_BYTES) {
0261 return v & ~kSplitFieldOffsetMask & ~kInlinedMask & ~kLazyMask &
0262 ~kMicroStringMask;
0263 }
0264 return v & (~kSplitFieldOffsetMask);
0265 }
0266
0267 static bool Inlined(uint32_t v, FieldDescriptor::Type type) {
0268 if (type == FieldDescriptor::TYPE_STRING ||
0269 type == FieldDescriptor::TYPE_BYTES) {
0270 return (v & kInlinedMask) != 0u;
0271 } else {
0272
0273 return false;
0274 }
0275 }
0276
0277 static bool IsMicroString(uint32_t v, FieldDescriptor::Type type) {
0278 ABSL_DCHECK(type == FieldDescriptor::TYPE_STRING ||
0279 type == FieldDescriptor::TYPE_BYTES)
0280 << type;
0281 return (v & kMicroStringMask) != 0u;
0282 }
0283 };
0284
0285
0286
0287
0288
0289
0290
0291 struct MigrationSchema {
0292 int32_t offsets_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 (ABSL_PREDICT_TRUE(cache != nullptr)) {
0369 if (ABSL_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