诸暨麻将添加redis
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

311 lines
13 KiB

  1. // Protocol Buffers - Google's data interchange format
  2. // Copyright 2008 Google Inc. All rights reserved.
  3. // https://developers.google.com/protocol-buffers/
  4. //
  5. // Redistribution and use in source and binary forms, with or without
  6. // modification, are permitted provided that the following conditions are
  7. // met:
  8. //
  9. // * Redistributions of source code must retain the above copyright
  10. // notice, this list of conditions and the following disclaimer.
  11. // * Redistributions in binary form must reproduce the above
  12. // copyright notice, this list of conditions and the following disclaimer
  13. // in the documentation and/or other materials provided with the
  14. // distribution.
  15. // * Neither the name of Google Inc. nor the names of its
  16. // contributors may be used to endorse or promote products derived from
  17. // this software without specific prior written permission.
  18. //
  19. // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  20. // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  21. // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  22. // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  23. // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  24. // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  25. // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  26. // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  27. // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  28. // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  29. // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  30. // Author: kenton@google.com (Kenton Varda)
  31. // Based on original Protocol Buffers design by
  32. // Sanjay Ghemawat, Jeff Dean, and others.
  33. //
  34. // This header is logically internal, but is made public because it is used
  35. // from protocol-compiler-generated code, which may reside in other components.
  36. #ifndef GOOGLE_PROTOBUF_GENERATED_MESSAGE_REFLECTION_H__
  37. #define GOOGLE_PROTOBUF_GENERATED_MESSAGE_REFLECTION_H__
  38. #include <string>
  39. #include <vector>
  40. #include <google/protobuf/stubs/casts.h>
  41. #include <google/protobuf/stubs/common.h>
  42. // TODO(jasonh): Remove this once the compiler change to directly include this
  43. // is released to components.
  44. #include <google/protobuf/descriptor.h>
  45. #include <google/protobuf/generated_enum_reflection.h>
  46. #include <google/protobuf/metadata.h>
  47. #include <google/protobuf/stubs/once.h>
  48. #include <google/protobuf/port.h>
  49. #include <google/protobuf/unknown_field_set.h>
  50. #include <google/protobuf/port_def.inc>
  51. #ifdef SWIG
  52. #error "You cannot SWIG proto headers"
  53. #endif
  54. namespace google {
  55. namespace protobuf {
  56. class DescriptorPool;
  57. class MapKey;
  58. class MapValueRef;
  59. class MessageLayoutInspector;
  60. class Message;
  61. struct Metadata;
  62. } // namespace protobuf
  63. } // namespace google
  64. namespace google {
  65. namespace protobuf {
  66. namespace internal {
  67. class DefaultEmptyOneof;
  68. class ReflectionAccessor;
  69. // Defined in other files.
  70. class ExtensionSet; // extension_set.h
  71. class WeakFieldMap; // weak_field_map.h
  72. // This struct describes the internal layout of the message, hence this is
  73. // used to act on the message reflectively.
  74. // default_instance: The default instance of the message. This is only
  75. // used to obtain pointers to default instances of embedded
  76. // messages, which GetMessage() will return if the particular
  77. // sub-message has not been initialized yet. (Thus, all
  78. // embedded message fields *must* have non-null pointers
  79. // in the default instance.)
  80. // offsets: An array of ints giving the byte offsets.
  81. // For each oneof or weak field, the offset is relative to the
  82. // default_instance. These can be computed at compile time
  83. // using the
  84. // PROTO2_GENERATED_DEFAULT_ONEOF_FIELD_OFFSET()
  85. // macro. For each none oneof field, the offset is related to
  86. // the start of the message object. These can be computed at
  87. // compile time using the
  88. // PROTO2_GENERATED_MESSAGE_FIELD_OFFSET() macro.
  89. // Besides offsets for all fields, this array also contains
  90. // offsets for oneof unions. The offset of the i-th oneof union
  91. // is offsets[descriptor->field_count() + i].
  92. // has_bit_indices: Mapping from field indexes to their index in the has
  93. // bit array.
  94. // has_bits_offset: Offset in the message of an array of uint32s of size
  95. // descriptor->field_count()/32, rounded up. This is a
  96. // bitfield where each bit indicates whether or not the
  97. // corresponding field of the message has been initialized.
  98. // The bit for field index i is obtained by the expression:
  99. // has_bits[i / 32] & (1 << (i % 32))
  100. // unknown_fields_offset: Offset in the message of the UnknownFieldSet for
  101. // the message.
  102. // extensions_offset: Offset in the message of the ExtensionSet for the
  103. // message, or -1 if the message type has no extension
  104. // ranges.
  105. // oneof_case_offset: Offset in the message of an array of uint32s of
  106. // size descriptor->oneof_decl_count(). Each uint32
  107. // indicates what field is set for each oneof.
  108. // object_size: The size of a message object of this type, as measured
  109. // by sizeof().
  110. // arena_offset: If a message doesn't have a unknown_field_set that stores
  111. // the arena, it must have a direct pointer to the arena.
  112. // weak_field_map_offset: If the message proto has weak fields, this is the
  113. // offset of _weak_field_map_ in the generated proto. Otherwise
  114. // -1.
  115. struct ReflectionSchema {
  116. public:
  117. // Size of a google::protobuf::Message object of this type.
  118. uint32 GetObjectSize() const { return static_cast<uint32>(object_size_); }
  119. // Offset of a non-oneof field. Getting a field offset is slightly more
  120. // efficient when we know statically that it is not a oneof field.
  121. uint32 GetFieldOffsetNonOneof(const FieldDescriptor* field) const {
  122. GOOGLE_DCHECK(!field->containing_oneof());
  123. return OffsetValue(offsets_[field->index()], field->type());
  124. }
  125. // Offset of any field.
  126. uint32 GetFieldOffset(const FieldDescriptor* field) const {
  127. if (field->containing_oneof()) {
  128. size_t offset =
  129. static_cast<size_t>(field->containing_type()->field_count() +
  130. field->containing_oneof()->index());
  131. return OffsetValue(offsets_[offset], field->type());
  132. } else {
  133. return GetFieldOffsetNonOneof(field);
  134. }
  135. }
  136. bool IsFieldInlined(const FieldDescriptor* field) const {
  137. if (field->containing_oneof()) {
  138. size_t offset =
  139. static_cast<size_t>(field->containing_type()->field_count() +
  140. field->containing_oneof()->index());
  141. return Inlined(offsets_[offset], field->type());
  142. } else {
  143. return Inlined(offsets_[field->index()], field->type());
  144. }
  145. }
  146. uint32 GetOneofCaseOffset(const OneofDescriptor* oneof_descriptor) const {
  147. return static_cast<uint32>(oneof_case_offset_) +
  148. static_cast<uint32>(static_cast<size_t>(oneof_descriptor->index()) *
  149. sizeof(uint32));
  150. }
  151. bool HasHasbits() const { return has_bits_offset_ != -1; }
  152. // Bit index within the bit array of hasbits. Bit order is low-to-high.
  153. uint32 HasBitIndex(const FieldDescriptor* field) const {
  154. GOOGLE_DCHECK(HasHasbits());
  155. return has_bit_indices_[field->index()];
  156. }
  157. // Byte offset of the hasbits array.
  158. uint32 HasBitsOffset() const {
  159. GOOGLE_DCHECK(HasHasbits());
  160. return static_cast<uint32>(has_bits_offset_);
  161. }
  162. // The offset of the InternalMetadataWithArena member.
  163. // For Lite this will actually be an InternalMetadataWithArenaLite.
  164. // The schema doesn't contain enough information to distinguish between
  165. // these two cases.
  166. uint32 GetMetadataOffset() const {
  167. return static_cast<uint32>(metadata_offset_);
  168. }
  169. // Whether this message has an ExtensionSet.
  170. bool HasExtensionSet() const { return extensions_offset_ != -1; }
  171. // The offset of the ExtensionSet in this message.
  172. uint32 GetExtensionSetOffset() const {
  173. GOOGLE_DCHECK(HasExtensionSet());
  174. return static_cast<uint32>(extensions_offset_);
  175. }
  176. // The off set of WeakFieldMap when the message contains weak fields.
  177. // The default is 0 for now.
  178. int GetWeakFieldMapOffset() const { return weak_field_map_offset_; }
  179. bool IsDefaultInstance(const Message& message) const {
  180. return &message == default_instance_;
  181. }
  182. // Returns a pointer to the default value for this field. The size and type
  183. // of the underlying data depends on the field's type.
  184. const void* GetFieldDefault(const FieldDescriptor* field) const {
  185. return reinterpret_cast<const uint8*>(default_instance_) +
  186. OffsetValue(offsets_[field->index()], field->type());
  187. }
  188. bool HasWeakFields() const { return weak_field_map_offset_ > 0; }
  189. // These members are intended to be private, but we cannot actually make them
  190. // private because this prevents us from using aggregate initialization of
  191. // them, ie.
  192. //
  193. // ReflectionSchema schema = {a, b, c, d, e, ...};
  194. // private:
  195. const Message* default_instance_;
  196. const uint32* offsets_;
  197. const uint32* has_bit_indices_;
  198. int has_bits_offset_;
  199. int metadata_offset_;
  200. int extensions_offset_;
  201. int oneof_case_offset_;
  202. int object_size_;
  203. int weak_field_map_offset_;
  204. // We tag offset values to provide additional data about fields (such as
  205. // inlined).
  206. static uint32 OffsetValue(uint32 v, FieldDescriptor::Type type) {
  207. if (type == FieldDescriptor::TYPE_STRING ||
  208. type == FieldDescriptor::TYPE_BYTES) {
  209. return v & ~1u;
  210. } else {
  211. return v;
  212. }
  213. }
  214. static bool Inlined(uint32 v, FieldDescriptor::Type type) {
  215. if (type == FieldDescriptor::TYPE_STRING ||
  216. type == FieldDescriptor::TYPE_BYTES) {
  217. return v & 1u;
  218. } else {
  219. // Non string/byte fields are not inlined.
  220. return false;
  221. }
  222. }
  223. };
  224. // Structs that the code generator emits directly to describe a message.
  225. // These should never used directly except to build a ReflectionSchema
  226. // object.
  227. //
  228. // EXPERIMENTAL: these are changing rapidly, and may completely disappear
  229. // or merge with ReflectionSchema.
  230. struct MigrationSchema {
  231. int32 offsets_index;
  232. int32 has_bit_indices_index;
  233. int object_size;
  234. };
  235. struct PROTOBUF_EXPORT DescriptorTable {
  236. bool* is_initialized;
  237. const char* descriptor;
  238. const char* filename;
  239. int size; // of serialized descriptor
  240. once_flag* once;
  241. SCCInfoBase* const* init_default_instances;
  242. const DescriptorTable* const* deps;
  243. int num_sccs;
  244. int num_deps;
  245. const MigrationSchema* schemas;
  246. const Message* const* default_instances;
  247. const uint32* offsets;
  248. // update the following descriptor arrays.
  249. Metadata* file_level_metadata;
  250. int num_messages;
  251. const EnumDescriptor** file_level_enum_descriptors;
  252. const ServiceDescriptor** file_level_service_descriptors;
  253. };
  254. // AssignDescriptors() pulls the compiled FileDescriptor from the DescriptorPool
  255. // and uses it to populate all of the global variables which store pointers to
  256. // the descriptor objects. It also constructs the reflection objects. It is
  257. // called the first time anyone calls descriptor() or GetReflection() on one of
  258. // the types defined in the file. AssignDescriptors() is thread-safe.
  259. void PROTOBUF_EXPORT AssignDescriptors(const DescriptorTable* table);
  260. // AddDescriptors() is a file-level procedure which adds the encoded
  261. // FileDescriptorProto for this .proto file to the global DescriptorPool for
  262. // generated files (DescriptorPool::generated_pool()). It ordinarily runs at
  263. // static initialization time, but is not used at all in LITE_RUNTIME mode.
  264. // AddDescriptors() is *not* thread-safe.
  265. void PROTOBUF_EXPORT AddDescriptors(const DescriptorTable* table);
  266. // These cannot be in lite so we put them in the reflection.
  267. PROTOBUF_EXPORT void UnknownFieldSetSerializer(const uint8* base, uint32 offset,
  268. uint32 tag, uint32 has_offset,
  269. io::CodedOutputStream* output);
  270. } // namespace internal
  271. } // namespace protobuf
  272. } // namespace google
  273. #include <google/protobuf/port_undef.inc>
  274. #endif // GOOGLE_PROTOBUF_GENERATED_MESSAGE_REFLECTION_H__