诸暨麻将添加redis
您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符
 
 
 
 
 
 

1589 行
78 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_EXTENSION_SET_H__
  37. #define GOOGLE_PROTOBUF_EXTENSION_SET_H__
  38. #include <algorithm>
  39. #include <cassert>
  40. #include <map>
  41. #include <string>
  42. #include <utility>
  43. #include <vector>
  44. #include <google/protobuf/stubs/common.h>
  45. #include <google/protobuf/stubs/logging.h>
  46. #include <google/protobuf/parse_context.h>
  47. #include <google/protobuf/io/coded_stream.h>
  48. #include <google/protobuf/port.h>
  49. #include <google/protobuf/repeated_field.h>
  50. #include <google/protobuf/wire_format_lite.h>
  51. #include <google/protobuf/port_def.inc>
  52. #ifdef SWIG
  53. #error "You cannot SWIG proto headers"
  54. #endif
  55. namespace google {
  56. namespace protobuf {
  57. class Arena;
  58. class Descriptor; // descriptor.h
  59. class FieldDescriptor; // descriptor.h
  60. class DescriptorPool; // descriptor.h
  61. class MessageLite; // message_lite.h
  62. class Message; // message.h
  63. class MessageFactory; // message.h
  64. class UnknownFieldSet; // unknown_field_set.h
  65. namespace internal {
  66. class FieldSkipper; // wire_format_lite.h
  67. } // namespace internal
  68. } // namespace protobuf
  69. } // namespace google
  70. namespace google {
  71. namespace protobuf {
  72. namespace internal {
  73. class InternalMetadataWithArenaLite;
  74. class InternalMetadataWithArena;
  75. // Used to store values of type WireFormatLite::FieldType without having to
  76. // #include wire_format_lite.h. Also, ensures that we use only one byte to
  77. // store these values, which is important to keep the layout of
  78. // ExtensionSet::Extension small.
  79. typedef uint8 FieldType;
  80. // A function which, given an integer value, returns true if the number
  81. // matches one of the defined values for the corresponding enum type. This
  82. // is used with RegisterEnumExtension, below.
  83. typedef bool EnumValidityFunc(int number);
  84. // Version of the above which takes an argument. This is needed to deal with
  85. // extensions that are not compiled in.
  86. typedef bool EnumValidityFuncWithArg(const void* arg, int number);
  87. // Information about a registered extension.
  88. struct ExtensionInfo {
  89. inline ExtensionInfo() {}
  90. inline ExtensionInfo(FieldType type_param, bool isrepeated, bool ispacked)
  91. : type(type_param),
  92. is_repeated(isrepeated),
  93. is_packed(ispacked),
  94. descriptor(NULL) {}
  95. FieldType type;
  96. bool is_repeated;
  97. bool is_packed;
  98. struct EnumValidityCheck {
  99. EnumValidityFuncWithArg* func;
  100. const void* arg;
  101. };
  102. struct MessageInfo {
  103. const MessageLite* prototype;
  104. };
  105. union {
  106. EnumValidityCheck enum_validity_check;
  107. MessageInfo message_info;
  108. };
  109. // The descriptor for this extension, if one exists and is known. May be
  110. // NULL. Must not be NULL if the descriptor for the extension does not
  111. // live in the same pool as the descriptor for the containing type.
  112. const FieldDescriptor* descriptor;
  113. };
  114. // Abstract interface for an object which looks up extension definitions. Used
  115. // when parsing.
  116. class PROTOBUF_EXPORT ExtensionFinder {
  117. public:
  118. virtual ~ExtensionFinder();
  119. // Find the extension with the given containing type and number.
  120. virtual bool Find(int number, ExtensionInfo* output) = 0;
  121. };
  122. // Implementation of ExtensionFinder which finds extensions defined in .proto
  123. // files which have been compiled into the binary.
  124. class PROTOBUF_EXPORT GeneratedExtensionFinder : public ExtensionFinder {
  125. public:
  126. GeneratedExtensionFinder(const MessageLite* containing_type)
  127. : containing_type_(containing_type) {}
  128. ~GeneratedExtensionFinder() override {}
  129. // Returns true and fills in *output if found, otherwise returns false.
  130. bool Find(int number, ExtensionInfo* output) override;
  131. private:
  132. const MessageLite* containing_type_;
  133. };
  134. // A FieldSkipper used for parsing MessageSet.
  135. class MessageSetFieldSkipper;
  136. // Note: extension_set_heavy.cc defines DescriptorPoolExtensionFinder for
  137. // finding extensions from a DescriptorPool.
  138. // This is an internal helper class intended for use within the protocol buffer
  139. // library and generated classes. Clients should not use it directly. Instead,
  140. // use the generated accessors such as GetExtension() of the class being
  141. // extended.
  142. //
  143. // This class manages extensions for a protocol message object. The
  144. // message's HasExtension(), GetExtension(), MutableExtension(), and
  145. // ClearExtension() methods are just thin wrappers around the embedded
  146. // ExtensionSet. When parsing, if a tag number is encountered which is
  147. // inside one of the message type's extension ranges, the tag is passed
  148. // off to the ExtensionSet for parsing. Etc.
  149. class PROTOBUF_EXPORT ExtensionSet {
  150. public:
  151. ExtensionSet();
  152. explicit ExtensionSet(Arena* arena);
  153. ~ExtensionSet();
  154. // These are called at startup by protocol-compiler-generated code to
  155. // register known extensions. The registrations are used by ParseField()
  156. // to look up extensions for parsed field numbers. Note that dynamic parsing
  157. // does not use ParseField(); only protocol-compiler-generated parsing
  158. // methods do.
  159. static void RegisterExtension(const MessageLite* containing_type, int number,
  160. FieldType type, bool is_repeated,
  161. bool is_packed);
  162. static void RegisterEnumExtension(const MessageLite* containing_type,
  163. int number, FieldType type,
  164. bool is_repeated, bool is_packed,
  165. EnumValidityFunc* is_valid);
  166. static void RegisterMessageExtension(const MessageLite* containing_type,
  167. int number, FieldType type,
  168. bool is_repeated, bool is_packed,
  169. const MessageLite* prototype);
  170. // =================================================================
  171. // Add all fields which are currently present to the given vector. This
  172. // is useful to implement Reflection::ListFields().
  173. void AppendToList(const Descriptor* containing_type,
  174. const DescriptorPool* pool,
  175. std::vector<const FieldDescriptor*>* output) const;
  176. // =================================================================
  177. // Accessors
  178. //
  179. // Generated message classes include type-safe templated wrappers around
  180. // these methods. Generally you should use those rather than call these
  181. // directly, unless you are doing low-level memory management.
  182. //
  183. // When calling any of these accessors, the extension number requested
  184. // MUST exist in the DescriptorPool provided to the constructor. Otherwise,
  185. // the method will fail an assert. Normally, though, you would not call
  186. // these directly; you would either call the generated accessors of your
  187. // message class (e.g. GetExtension()) or you would call the accessors
  188. // of the reflection interface. In both cases, it is impossible to
  189. // trigger this assert failure: the generated accessors only accept
  190. // linked-in extension types as parameters, while the Reflection interface
  191. // requires you to provide the FieldDescriptor describing the extension.
  192. //
  193. // When calling any of these accessors, a protocol-compiler-generated
  194. // implementation of the extension corresponding to the number MUST
  195. // be linked in, and the FieldDescriptor used to refer to it MUST be
  196. // the one generated by that linked-in code. Otherwise, the method will
  197. // die on an assert failure. The message objects returned by the message
  198. // accessors are guaranteed to be of the correct linked-in type.
  199. //
  200. // These methods pretty much match Reflection except that:
  201. // - They're not virtual.
  202. // - They identify fields by number rather than FieldDescriptors.
  203. // - They identify enum values using integers rather than descriptors.
  204. // - Strings provide Mutable() in addition to Set() accessors.
  205. bool Has(int number) const;
  206. int ExtensionSize(int number) const; // Size of a repeated extension.
  207. int NumExtensions() const; // The number of extensions
  208. FieldType ExtensionType(int number) const;
  209. void ClearExtension(int number);
  210. // singular fields -------------------------------------------------
  211. int32 GetInt32(int number, int32 default_value) const;
  212. int64 GetInt64(int number, int64 default_value) const;
  213. uint32 GetUInt32(int number, uint32 default_value) const;
  214. uint64 GetUInt64(int number, uint64 default_value) const;
  215. float GetFloat(int number, float default_value) const;
  216. double GetDouble(int number, double default_value) const;
  217. bool GetBool(int number, bool default_value) const;
  218. int GetEnum(int number, int default_value) const;
  219. const std::string& GetString(int number,
  220. const std::string& default_value) const;
  221. const MessageLite& GetMessage(int number,
  222. const MessageLite& default_value) const;
  223. const MessageLite& GetMessage(int number, const Descriptor* message_type,
  224. MessageFactory* factory) const;
  225. // |descriptor| may be NULL so long as it is known that the descriptor for
  226. // the extension lives in the same pool as the descriptor for the containing
  227. // type.
  228. #define desc const FieldDescriptor* descriptor // avoid line wrapping
  229. void SetInt32(int number, FieldType type, int32 value, desc);
  230. void SetInt64(int number, FieldType type, int64 value, desc);
  231. void SetUInt32(int number, FieldType type, uint32 value, desc);
  232. void SetUInt64(int number, FieldType type, uint64 value, desc);
  233. void SetFloat(int number, FieldType type, float value, desc);
  234. void SetDouble(int number, FieldType type, double value, desc);
  235. void SetBool(int number, FieldType type, bool value, desc);
  236. void SetEnum(int number, FieldType type, int value, desc);
  237. void SetString(int number, FieldType type, std::string value, desc);
  238. std::string* MutableString(int number, FieldType type, desc);
  239. MessageLite* MutableMessage(int number, FieldType type,
  240. const MessageLite& prototype, desc);
  241. MessageLite* MutableMessage(const FieldDescriptor* decsriptor,
  242. MessageFactory* factory);
  243. // Adds the given message to the ExtensionSet, taking ownership of the
  244. // message object. Existing message with the same number will be deleted.
  245. // If "message" is NULL, this is equivalent to "ClearExtension(number)".
  246. void SetAllocatedMessage(int number, FieldType type,
  247. const FieldDescriptor* descriptor,
  248. MessageLite* message);
  249. void UnsafeArenaSetAllocatedMessage(int number, FieldType type,
  250. const FieldDescriptor* descriptor,
  251. MessageLite* message);
  252. MessageLite* ReleaseMessage(int number, const MessageLite& prototype);
  253. MessageLite* UnsafeArenaReleaseMessage(int number,
  254. const MessageLite& prototype);
  255. MessageLite* ReleaseMessage(const FieldDescriptor* descriptor,
  256. MessageFactory* factory);
  257. MessageLite* UnsafeArenaReleaseMessage(const FieldDescriptor* descriptor,
  258. MessageFactory* factory);
  259. #undef desc
  260. Arena* GetArenaNoVirtual() const { return arena_; }
  261. // repeated fields -------------------------------------------------
  262. // Fetches a RepeatedField extension by number; returns |default_value|
  263. // if no such extension exists. User should not touch this directly; it is
  264. // used by the GetRepeatedExtension() method.
  265. const void* GetRawRepeatedField(int number, const void* default_value) const;
  266. // Fetches a mutable version of a RepeatedField extension by number,
  267. // instantiating one if none exists. Similar to above, user should not use
  268. // this directly; it underlies MutableRepeatedExtension().
  269. void* MutableRawRepeatedField(int number, FieldType field_type, bool packed,
  270. const FieldDescriptor* desc);
  271. // This is an overload of MutableRawRepeatedField to maintain compatibility
  272. // with old code using a previous API. This version of
  273. // MutableRawRepeatedField() will GOOGLE_CHECK-fail on a missing extension.
  274. // (E.g.: borg/clients/internal/proto1/proto2_reflection.cc.)
  275. void* MutableRawRepeatedField(int number);
  276. int32 GetRepeatedInt32(int number, int index) const;
  277. int64 GetRepeatedInt64(int number, int index) const;
  278. uint32 GetRepeatedUInt32(int number, int index) const;
  279. uint64 GetRepeatedUInt64(int number, int index) const;
  280. float GetRepeatedFloat(int number, int index) const;
  281. double GetRepeatedDouble(int number, int index) const;
  282. bool GetRepeatedBool(int number, int index) const;
  283. int GetRepeatedEnum(int number, int index) const;
  284. const std::string& GetRepeatedString(int number, int index) const;
  285. const MessageLite& GetRepeatedMessage(int number, int index) const;
  286. void SetRepeatedInt32(int number, int index, int32 value);
  287. void SetRepeatedInt64(int number, int index, int64 value);
  288. void SetRepeatedUInt32(int number, int index, uint32 value);
  289. void SetRepeatedUInt64(int number, int index, uint64 value);
  290. void SetRepeatedFloat(int number, int index, float value);
  291. void SetRepeatedDouble(int number, int index, double value);
  292. void SetRepeatedBool(int number, int index, bool value);
  293. void SetRepeatedEnum(int number, int index, int value);
  294. void SetRepeatedString(int number, int index, std::string value);
  295. std::string* MutableRepeatedString(int number, int index);
  296. MessageLite* MutableRepeatedMessage(int number, int index);
  297. #define desc const FieldDescriptor* descriptor // avoid line wrapping
  298. void AddInt32(int number, FieldType type, bool packed, int32 value, desc);
  299. void AddInt64(int number, FieldType type, bool packed, int64 value, desc);
  300. void AddUInt32(int number, FieldType type, bool packed, uint32 value, desc);
  301. void AddUInt64(int number, FieldType type, bool packed, uint64 value, desc);
  302. void AddFloat(int number, FieldType type, bool packed, float value, desc);
  303. void AddDouble(int number, FieldType type, bool packed, double value, desc);
  304. void AddBool(int number, FieldType type, bool packed, bool value, desc);
  305. void AddEnum(int number, FieldType type, bool packed, int value, desc);
  306. void AddString(int number, FieldType type, std::string value, desc);
  307. std::string* AddString(int number, FieldType type, desc);
  308. MessageLite* AddMessage(int number, FieldType type,
  309. const MessageLite& prototype, desc);
  310. MessageLite* AddMessage(const FieldDescriptor* descriptor,
  311. MessageFactory* factory);
  312. void AddAllocatedMessage(const FieldDescriptor* descriptor,
  313. MessageLite* new_entry);
  314. #undef desc
  315. void RemoveLast(int number);
  316. MessageLite* ReleaseLast(int number);
  317. void SwapElements(int number, int index1, int index2);
  318. // -----------------------------------------------------------------
  319. // TODO(kenton): Hardcore memory management accessors
  320. // =================================================================
  321. // convenience methods for implementing methods of Message
  322. //
  323. // These could all be implemented in terms of the other methods of this
  324. // class, but providing them here helps keep the generated code size down.
  325. void Clear();
  326. void MergeFrom(const ExtensionSet& other);
  327. void Swap(ExtensionSet* other);
  328. void SwapExtension(ExtensionSet* other, int number);
  329. bool IsInitialized() const;
  330. // Parses a single extension from the input. The input should start out
  331. // positioned immediately after the tag.
  332. bool ParseField(uint32 tag, io::CodedInputStream* input,
  333. ExtensionFinder* extension_finder,
  334. FieldSkipper* field_skipper);
  335. // Specific versions for lite or full messages (constructs the appropriate
  336. // FieldSkipper automatically). |containing_type| is the default
  337. // instance for the containing message; it is used only to look up the
  338. // extension by number. See RegisterExtension(), above. Unlike the other
  339. // methods of ExtensionSet, this only works for generated message types --
  340. // it looks up extensions registered using RegisterExtension().
  341. bool ParseField(uint32 tag, io::CodedInputStream* input,
  342. const MessageLite* containing_type);
  343. bool ParseField(uint32 tag, io::CodedInputStream* input,
  344. const Message* containing_type,
  345. UnknownFieldSet* unknown_fields);
  346. bool ParseField(uint32 tag, io::CodedInputStream* input,
  347. const MessageLite* containing_type,
  348. io::CodedOutputStream* unknown_fields);
  349. // Lite parser
  350. const char* ParseField(uint64 tag, const char* ptr,
  351. const MessageLite* containing_type,
  352. internal::InternalMetadataWithArenaLite* metadata,
  353. internal::ParseContext* ctx);
  354. // Full parser
  355. const char* ParseField(uint64 tag, const char* ptr,
  356. const Message* containing_type,
  357. internal::InternalMetadataWithArena* metadata,
  358. internal::ParseContext* ctx);
  359. template <typename Msg, typename Metadata>
  360. const char* ParseMessageSet(const char* ptr, const Msg* containing_type,
  361. Metadata* metadata, internal::ParseContext* ctx) {
  362. struct MessageSetItem {
  363. const char* _InternalParse(const char* ptr, ParseContext* ctx) {
  364. return me->ParseMessageSetItem(ptr, containing_type, metadata, ctx);
  365. }
  366. ExtensionSet* me;
  367. const Msg* containing_type;
  368. Metadata* metadata;
  369. } item{this, containing_type, metadata};
  370. while (!ctx->Done(&ptr)) {
  371. uint32 tag;
  372. ptr = ReadTag(ptr, &tag);
  373. GOOGLE_PROTOBUF_PARSER_ASSERT(ptr);
  374. if (tag == WireFormatLite::kMessageSetItemStartTag) {
  375. ptr = ctx->ParseGroup(&item, ptr, tag);
  376. GOOGLE_PROTOBUF_PARSER_ASSERT(ptr);
  377. } else {
  378. if (tag == 0 || (tag & 7) == 4) {
  379. ctx->SetLastTag(tag);
  380. return ptr;
  381. }
  382. ptr = ParseField(tag, ptr, containing_type, metadata, ctx);
  383. GOOGLE_PROTOBUF_PARSER_ASSERT(ptr);
  384. }
  385. }
  386. return ptr;
  387. }
  388. // Parse an entire message in MessageSet format. Such messages have no
  389. // fields, only extensions.
  390. bool ParseMessageSetLite(io::CodedInputStream* input,
  391. ExtensionFinder* extension_finder,
  392. FieldSkipper* field_skipper);
  393. bool ParseMessageSet(io::CodedInputStream* input,
  394. ExtensionFinder* extension_finder,
  395. MessageSetFieldSkipper* field_skipper);
  396. // Specific versions for lite or full messages (constructs the appropriate
  397. // FieldSkipper automatically).
  398. bool ParseMessageSet(io::CodedInputStream* input,
  399. const MessageLite* containing_type,
  400. std::string* unknown_fields);
  401. bool ParseMessageSet(io::CodedInputStream* input,
  402. const Message* containing_type,
  403. UnknownFieldSet* unknown_fields);
  404. // Write all extension fields with field numbers in the range
  405. // [start_field_number, end_field_number)
  406. // to the output stream, using the cached sizes computed when ByteSize() was
  407. // last called. Note that the range bounds are inclusive-exclusive.
  408. void SerializeWithCachedSizes(int start_field_number, int end_field_number,
  409. io::CodedOutputStream* output) const {
  410. output->SetCur(InternalSerializeWithCachedSizesToArray(
  411. start_field_number, end_field_number, output->Cur(),
  412. output->EpsCopy()));
  413. }
  414. // Same as SerializeWithCachedSizes, but without any bounds checking.
  415. // The caller must ensure that target has sufficient capacity for the
  416. // serialized extensions.
  417. //
  418. // Returns a pointer past the last written byte.
  419. uint8* InternalSerializeWithCachedSizesToArray(
  420. int start_field_number, int end_field_number, uint8* target,
  421. io::EpsCopyOutputStream* stream) const;
  422. // Like above but serializes in MessageSet format.
  423. void SerializeMessageSetWithCachedSizes(io::CodedOutputStream* output) const {
  424. output->SetCur(InternalSerializeMessageSetWithCachedSizesToArray(
  425. output->Cur(), output->EpsCopy()));
  426. }
  427. uint8* InternalSerializeMessageSetWithCachedSizesToArray(
  428. uint8* target, io::EpsCopyOutputStream* stream) const;
  429. // For backward-compatibility, versions of two of the above methods that
  430. // serialize deterministically iff SetDefaultSerializationDeterministic()
  431. // has been called.
  432. uint8* SerializeWithCachedSizesToArray(int start_field_number,
  433. int end_field_number,
  434. uint8* target) const;
  435. uint8* SerializeMessageSetWithCachedSizesToArray(uint8* target) const;
  436. // Returns the total serialized size of all the extensions.
  437. size_t ByteSize() const;
  438. // Like ByteSize() but uses MessageSet format.
  439. size_t MessageSetByteSize() const;
  440. // Returns (an estimate of) the total number of bytes used for storing the
  441. // extensions in memory, excluding sizeof(*this). If the ExtensionSet is
  442. // for a lite message (and thus possibly contains lite messages), the results
  443. // are undefined (might work, might crash, might corrupt data, might not even
  444. // be linked in). It's up to the protocol compiler to avoid calling this on
  445. // such ExtensionSets (easy enough since lite messages don't implement
  446. // SpaceUsed()).
  447. size_t SpaceUsedExcludingSelfLong() const;
  448. // This method just calls SpaceUsedExcludingSelfLong() but it can not be
  449. // inlined because the definition of SpaceUsedExcludingSelfLong() is not
  450. // included in lite runtime and when an inline method refers to it MSVC
  451. // will complain about unresolved symbols when building the lite runtime
  452. // as .dll.
  453. int SpaceUsedExcludingSelf() const;
  454. private:
  455. // Interface of a lazily parsed singular message extension.
  456. class PROTOBUF_EXPORT LazyMessageExtension {
  457. public:
  458. LazyMessageExtension() {}
  459. virtual ~LazyMessageExtension() {}
  460. virtual LazyMessageExtension* New(Arena* arena) const = 0;
  461. virtual const MessageLite& GetMessage(
  462. const MessageLite& prototype) const = 0;
  463. virtual MessageLite* MutableMessage(const MessageLite& prototype) = 0;
  464. virtual void SetAllocatedMessage(MessageLite* message) = 0;
  465. virtual void UnsafeArenaSetAllocatedMessage(MessageLite* message) = 0;
  466. virtual MessageLite* ReleaseMessage(const MessageLite& prototype) = 0;
  467. virtual MessageLite* UnsafeArenaReleaseMessage(
  468. const MessageLite& prototype) = 0;
  469. virtual bool IsInitialized() const = 0;
  470. PROTOBUF_DEPRECATED_MSG("Please use ByteSizeLong() instead")
  471. virtual int ByteSize() const { return internal::ToIntSize(ByteSizeLong()); }
  472. virtual size_t ByteSizeLong() const = 0;
  473. virtual size_t SpaceUsedLong() const = 0;
  474. virtual void MergeFrom(const LazyMessageExtension& other) = 0;
  475. virtual void Clear() = 0;
  476. virtual bool ReadMessage(const MessageLite& prototype,
  477. io::CodedInputStream* input) = 0;
  478. virtual const char* _InternalParse(const char* ptr, ParseContext* ctx) = 0;
  479. virtual uint8* WriteMessageToArray(
  480. int number, uint8* target, io::EpsCopyOutputStream* stream) const = 0;
  481. private:
  482. virtual void UnusedKeyMethod(); // Dummy key method to avoid weak vtable.
  483. GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(LazyMessageExtension);
  484. };
  485. struct Extension {
  486. // The order of these fields packs Extension into 24 bytes when using 8
  487. // byte alignment. Consider this when adding or removing fields here.
  488. union {
  489. int32 int32_value;
  490. int64 int64_value;
  491. uint32 uint32_value;
  492. uint64 uint64_value;
  493. float float_value;
  494. double double_value;
  495. bool bool_value;
  496. int enum_value;
  497. std::string* string_value;
  498. MessageLite* message_value;
  499. LazyMessageExtension* lazymessage_value;
  500. RepeatedField<int32>* repeated_int32_value;
  501. RepeatedField<int64>* repeated_int64_value;
  502. RepeatedField<uint32>* repeated_uint32_value;
  503. RepeatedField<uint64>* repeated_uint64_value;
  504. RepeatedField<float>* repeated_float_value;
  505. RepeatedField<double>* repeated_double_value;
  506. RepeatedField<bool>* repeated_bool_value;
  507. RepeatedField<int>* repeated_enum_value;
  508. RepeatedPtrField<std::string>* repeated_string_value;
  509. RepeatedPtrField<MessageLite>* repeated_message_value;
  510. };
  511. FieldType type;
  512. bool is_repeated;
  513. // For singular types, indicates if the extension is "cleared". This
  514. // happens when an extension is set and then later cleared by the caller.
  515. // We want to keep the Extension object around for reuse, so instead of
  516. // removing it from the map, we just set is_cleared = true. This has no
  517. // meaning for repeated types; for those, the size of the RepeatedField
  518. // simply becomes zero when cleared.
  519. bool is_cleared : 4;
  520. // For singular message types, indicates whether lazy parsing is enabled
  521. // for this extension. This field is only valid when type == TYPE_MESSAGE
  522. // and !is_repeated because we only support lazy parsing for singular
  523. // message types currently. If is_lazy = true, the extension is stored in
  524. // lazymessage_value. Otherwise, the extension will be message_value.
  525. bool is_lazy : 4;
  526. // For repeated types, this indicates if the [packed=true] option is set.
  527. bool is_packed;
  528. // For packed fields, the size of the packed data is recorded here when
  529. // ByteSize() is called then used during serialization.
  530. // TODO(kenton): Use atomic<int> when C++ supports it.
  531. mutable int cached_size;
  532. // The descriptor for this extension, if one exists and is known. May be
  533. // NULL. Must not be NULL if the descriptor for the extension does not
  534. // live in the same pool as the descriptor for the containing type.
  535. const FieldDescriptor* descriptor;
  536. // Some helper methods for operations on a single Extension.
  537. uint8* InternalSerializeFieldWithCachedSizesToArray(
  538. int number, uint8* target, io::EpsCopyOutputStream* stream) const;
  539. uint8* InternalSerializeMessageSetItemWithCachedSizesToArray(
  540. int number, uint8* target, io::EpsCopyOutputStream* stream) const;
  541. size_t ByteSize(int number) const;
  542. size_t MessageSetItemByteSize(int number) const;
  543. void Clear();
  544. int GetSize() const;
  545. void Free();
  546. size_t SpaceUsedExcludingSelfLong() const;
  547. bool IsInitialized() const;
  548. };
  549. // The Extension struct is small enough to be passed by value, so we use it
  550. // directly as the value type in mappings rather than use pointers. We use
  551. // sorted maps rather than hash-maps because we expect most ExtensionSets will
  552. // only contain a small number of extension. Also, we want AppendToList and
  553. // deterministic serialization to order fields by field number.
  554. struct KeyValue {
  555. int first;
  556. Extension second;
  557. struct FirstComparator {
  558. bool operator()(const KeyValue& lhs, const KeyValue& rhs) const {
  559. return lhs.first < rhs.first;
  560. }
  561. bool operator()(const KeyValue& lhs, int key) const {
  562. return lhs.first < key;
  563. }
  564. bool operator()(int key, const KeyValue& rhs) const {
  565. return key < rhs.first;
  566. }
  567. };
  568. };
  569. typedef std::map<int, Extension> LargeMap;
  570. // Wrapper API that switches between flat-map and LargeMap.
  571. // Finds a key (if present) in the ExtensionSet.
  572. const Extension* FindOrNull(int key) const;
  573. Extension* FindOrNull(int key);
  574. // Helper-functions that only inspect the LargeMap.
  575. const Extension* FindOrNullInLargeMap(int key) const;
  576. Extension* FindOrNullInLargeMap(int key);
  577. // Inserts a new (key, Extension) into the ExtensionSet (and returns true), or
  578. // finds the already-existing Extension for that key (returns false).
  579. // The Extension* will point to the new-or-found Extension.
  580. std::pair<Extension*, bool> Insert(int key);
  581. // Grows the flat_capacity_.
  582. // If flat_capacity_ > kMaximumFlatCapacity, converts to LargeMap.
  583. void GrowCapacity(size_t minimum_new_capacity);
  584. static constexpr uint16 kMaximumFlatCapacity = 256;
  585. bool is_large() const { return flat_capacity_ > kMaximumFlatCapacity; }
  586. // Removes a key from the ExtensionSet.
  587. void Erase(int key);
  588. size_t Size() const {
  589. return PROTOBUF_PREDICT_FALSE(is_large()) ? map_.large->size() : flat_size_;
  590. }
  591. // Similar to std::for_each.
  592. // Each Iterator is decomposed into ->first and ->second fields, so
  593. // that the KeyValueFunctor can be agnostic vis-a-vis KeyValue-vs-std::pair.
  594. template <typename Iterator, typename KeyValueFunctor>
  595. static KeyValueFunctor ForEach(Iterator begin, Iterator end,
  596. KeyValueFunctor func) {
  597. for (Iterator it = begin; it != end; ++it) func(it->first, it->second);
  598. return std::move(func);
  599. }
  600. // Applies a functor to the <int, Extension&> pairs in sorted order.
  601. template <typename KeyValueFunctor>
  602. KeyValueFunctor ForEach(KeyValueFunctor func) {
  603. if (PROTOBUF_PREDICT_FALSE(is_large())) {
  604. return ForEach(map_.large->begin(), map_.large->end(), std::move(func));
  605. }
  606. return ForEach(flat_begin(), flat_end(), std::move(func));
  607. }
  608. // Applies a functor to the <int, const Extension&> pairs in sorted order.
  609. template <typename KeyValueFunctor>
  610. KeyValueFunctor ForEach(KeyValueFunctor func) const {
  611. if (PROTOBUF_PREDICT_FALSE(is_large())) {
  612. return ForEach(map_.large->begin(), map_.large->end(), std::move(func));
  613. }
  614. return ForEach(flat_begin(), flat_end(), std::move(func));
  615. }
  616. // Merges existing Extension from other_extension
  617. void InternalExtensionMergeFrom(int number, const Extension& other_extension);
  618. // Returns true and fills field_number and extension if extension is found.
  619. // Note to support packed repeated field compatibility, it also fills whether
  620. // the tag on wire is packed, which can be different from
  621. // extension->is_packed (whether packed=true is specified).
  622. bool FindExtensionInfoFromTag(uint32 tag, ExtensionFinder* extension_finder,
  623. int* field_number, ExtensionInfo* extension,
  624. bool* was_packed_on_wire);
  625. // Returns true and fills extension if extension is found.
  626. // Note to support packed repeated field compatibility, it also fills whether
  627. // the tag on wire is packed, which can be different from
  628. // extension->is_packed (whether packed=true is specified).
  629. bool FindExtensionInfoFromFieldNumber(int wire_type, int field_number,
  630. ExtensionFinder* extension_finder,
  631. ExtensionInfo* extension,
  632. bool* was_packed_on_wire);
  633. // Parses a single extension from the input. The input should start out
  634. // positioned immediately after the wire tag. This method is called in
  635. // ParseField() after field number and was_packed_on_wire is extracted from
  636. // the wire tag and ExtensionInfo is found by the field number.
  637. bool ParseFieldWithExtensionInfo(int field_number, bool was_packed_on_wire,
  638. const ExtensionInfo& extension,
  639. io::CodedInputStream* input,
  640. FieldSkipper* field_skipper);
  641. // Like ParseField(), but this method may parse singular message extensions
  642. // lazily depending on the value of FLAGS_eagerly_parse_message_sets.
  643. bool ParseFieldMaybeLazily(int wire_type, int field_number,
  644. io::CodedInputStream* input,
  645. ExtensionFinder* extension_finder,
  646. MessageSetFieldSkipper* field_skipper);
  647. // Gets the extension with the given number, creating it if it does not
  648. // already exist. Returns true if the extension did not already exist.
  649. bool MaybeNewExtension(int number, const FieldDescriptor* descriptor,
  650. Extension** result);
  651. // Gets the repeated extension for the given descriptor, creating it if
  652. // it does not exist.
  653. Extension* MaybeNewRepeatedExtension(const FieldDescriptor* descriptor);
  654. // Parse a single MessageSet item -- called just after the item group start
  655. // tag has been read.
  656. bool ParseMessageSetItemLite(io::CodedInputStream* input,
  657. ExtensionFinder* extension_finder,
  658. FieldSkipper* field_skipper);
  659. // Parse a single MessageSet item -- called just after the item group start
  660. // tag has been read.
  661. bool ParseMessageSetItem(io::CodedInputStream* input,
  662. ExtensionFinder* extension_finder,
  663. MessageSetFieldSkipper* field_skipper);
  664. bool FindExtension(int wire_type, uint32 field,
  665. const MessageLite* containing_type,
  666. const internal::ParseContext* ctx,
  667. ExtensionInfo* extension, bool* was_packed_on_wire) {
  668. GeneratedExtensionFinder finder(containing_type);
  669. return FindExtensionInfoFromFieldNumber(wire_type, field, &finder,
  670. extension, was_packed_on_wire);
  671. }
  672. inline bool FindExtension(int wire_type, uint32 field,
  673. const Message* containing_type,
  674. const internal::ParseContext* ctx,
  675. ExtensionInfo* extension, bool* was_packed_on_wire);
  676. // Used for MessageSet only
  677. const char* ParseFieldMaybeLazily(
  678. uint64 tag, const char* ptr, const MessageLite* containing_type,
  679. internal::InternalMetadataWithArenaLite* metadata,
  680. internal::ParseContext* ctx) {
  681. // Lite MessageSet doesn't implement lazy.
  682. return ParseField(tag, ptr, containing_type, metadata, ctx);
  683. }
  684. const char* ParseFieldMaybeLazily(
  685. uint64 tag, const char* ptr, const Message* containing_type,
  686. internal::InternalMetadataWithArena* metadata,
  687. internal::ParseContext* ctx);
  688. const char* ParseMessageSetItem(
  689. const char* ptr, const MessageLite* containing_type,
  690. internal::InternalMetadataWithArenaLite* metadata,
  691. internal::ParseContext* ctx);
  692. const char* ParseMessageSetItem(const char* ptr,
  693. const Message* containing_type,
  694. internal::InternalMetadataWithArena* metadata,
  695. internal::ParseContext* ctx);
  696. // Implemented in extension_set_inl.h to keep code out of the header file.
  697. template <typename T>
  698. const char* ParseFieldWithExtensionInfo(int number, bool was_packed_on_wire,
  699. const ExtensionInfo& info,
  700. T* metadata, const char* ptr,
  701. internal::ParseContext* ctx);
  702. template <typename Msg, typename Metadata>
  703. const char* ParseMessageSetItemTmpl(const char* ptr,
  704. const Msg* containing_type,
  705. Metadata* metadata,
  706. internal::ParseContext* ctx);
  707. // Hack: RepeatedPtrFieldBase declares ExtensionSet as a friend. This
  708. // friendship should automatically extend to ExtensionSet::Extension, but
  709. // unfortunately some older compilers (e.g. GCC 3.4.4) do not implement this
  710. // correctly. So, we must provide helpers for calling methods of that
  711. // class.
  712. // Defined in extension_set_heavy.cc.
  713. static inline size_t RepeatedMessage_SpaceUsedExcludingSelfLong(
  714. RepeatedPtrFieldBase* field);
  715. KeyValue* flat_begin() {
  716. assert(!is_large());
  717. return map_.flat;
  718. }
  719. const KeyValue* flat_begin() const {
  720. assert(!is_large());
  721. return map_.flat;
  722. }
  723. KeyValue* flat_end() {
  724. assert(!is_large());
  725. return map_.flat + flat_size_;
  726. }
  727. const KeyValue* flat_end() const {
  728. assert(!is_large());
  729. return map_.flat + flat_size_;
  730. }
  731. Arena* arena_;
  732. // Manual memory-management:
  733. // map_.flat is an allocated array of flat_capacity_ elements.
  734. // [map_.flat, map_.flat + flat_size_) is the currently-in-use prefix.
  735. uint16 flat_capacity_;
  736. uint16 flat_size_;
  737. union AllocatedData {
  738. KeyValue* flat;
  739. // If flat_capacity_ > kMaximumFlatCapacity, switch to LargeMap,
  740. // which guarantees O(n lg n) CPU but larger constant factors.
  741. LargeMap* large;
  742. } map_;
  743. static void DeleteFlatMap(const KeyValue* flat, uint16 flat_capacity);
  744. GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(ExtensionSet);
  745. };
  746. // These are just for convenience...
  747. inline void ExtensionSet::SetString(int number, FieldType type,
  748. std::string value,
  749. const FieldDescriptor* descriptor) {
  750. MutableString(number, type, descriptor)->assign(std::move(value));
  751. }
  752. inline void ExtensionSet::SetRepeatedString(int number, int index,
  753. std::string value) {
  754. MutableRepeatedString(number, index)->assign(std::move(value));
  755. }
  756. inline void ExtensionSet::AddString(int number, FieldType type,
  757. std::string value,
  758. const FieldDescriptor* descriptor) {
  759. AddString(number, type, descriptor)->assign(std::move(value));
  760. }
  761. // ===================================================================
  762. // Glue for generated extension accessors
  763. // -------------------------------------------------------------------
  764. // Template magic
  765. // First we have a set of classes representing "type traits" for different
  766. // field types. A type traits class knows how to implement basic accessors
  767. // for extensions of a particular type given an ExtensionSet. The signature
  768. // for a type traits class looks like this:
  769. //
  770. // class TypeTraits {
  771. // public:
  772. // typedef ? ConstType;
  773. // typedef ? MutableType;
  774. // // TypeTraits for singular fields and repeated fields will define the
  775. // // symbol "Singular" or "Repeated" respectively. These two symbols will
  776. // // be used in extension accessors to distinguish between singular
  777. // // extensions and repeated extensions. If the TypeTraits for the passed
  778. // // in extension doesn't have the expected symbol defined, it means the
  779. // // user is passing a repeated extension to a singular accessor, or the
  780. // // opposite. In that case the C++ compiler will generate an error
  781. // // message "no matching member function" to inform the user.
  782. // typedef ? Singular
  783. // typedef ? Repeated
  784. //
  785. // static inline ConstType Get(int number, const ExtensionSet& set);
  786. // static inline void Set(int number, ConstType value, ExtensionSet* set);
  787. // static inline MutableType Mutable(int number, ExtensionSet* set);
  788. //
  789. // // Variants for repeated fields.
  790. // static inline ConstType Get(int number, const ExtensionSet& set,
  791. // int index);
  792. // static inline void Set(int number, int index,
  793. // ConstType value, ExtensionSet* set);
  794. // static inline MutableType Mutable(int number, int index,
  795. // ExtensionSet* set);
  796. // static inline void Add(int number, ConstType value, ExtensionSet* set);
  797. // static inline MutableType Add(int number, ExtensionSet* set);
  798. // This is used by the ExtensionIdentifier constructor to register
  799. // the extension at dynamic initialization.
  800. // template <typename ExtendeeT>
  801. // static void Register(int number, FieldType type, bool is_packed);
  802. // };
  803. //
  804. // Not all of these methods make sense for all field types. For example, the
  805. // "Mutable" methods only make sense for strings and messages, and the
  806. // repeated methods only make sense for repeated types. So, each type
  807. // traits class implements only the set of methods from this signature that it
  808. // actually supports. This will cause a compiler error if the user tries to
  809. // access an extension using a method that doesn't make sense for its type.
  810. // For example, if "foo" is an extension of type "optional int32", then if you
  811. // try to write code like:
  812. // my_message.MutableExtension(foo)
  813. // you will get a compile error because PrimitiveTypeTraits<int32> does not
  814. // have a "Mutable()" method.
  815. // -------------------------------------------------------------------
  816. // PrimitiveTypeTraits
  817. // Since the ExtensionSet has different methods for each primitive type,
  818. // we must explicitly define the methods of the type traits class for each
  819. // known type.
  820. template <typename Type>
  821. class PrimitiveTypeTraits {
  822. public:
  823. typedef Type ConstType;
  824. typedef Type MutableType;
  825. typedef PrimitiveTypeTraits<Type> Singular;
  826. static inline ConstType Get(int number, const ExtensionSet& set,
  827. ConstType default_value);
  828. static inline void Set(int number, FieldType field_type, ConstType value,
  829. ExtensionSet* set);
  830. template <typename ExtendeeT>
  831. static void Register(int number, FieldType type, bool is_packed) {
  832. ExtensionSet::RegisterExtension(&ExtendeeT::default_instance(), number,
  833. type, false, is_packed);
  834. }
  835. };
  836. template <typename Type>
  837. class RepeatedPrimitiveTypeTraits {
  838. public:
  839. typedef Type ConstType;
  840. typedef Type MutableType;
  841. typedef RepeatedPrimitiveTypeTraits<Type> Repeated;
  842. typedef RepeatedField<Type> RepeatedFieldType;
  843. static inline Type Get(int number, const ExtensionSet& set, int index);
  844. static inline void Set(int number, int index, Type value, ExtensionSet* set);
  845. static inline void Add(int number, FieldType field_type, bool is_packed,
  846. Type value, ExtensionSet* set);
  847. static inline const RepeatedField<ConstType>& GetRepeated(
  848. int number, const ExtensionSet& set);
  849. static inline RepeatedField<Type>* MutableRepeated(int number,
  850. FieldType field_type,
  851. bool is_packed,
  852. ExtensionSet* set);
  853. static const RepeatedFieldType* GetDefaultRepeatedField();
  854. template <typename ExtendeeT>
  855. static void Register(int number, FieldType type, bool is_packed) {
  856. ExtensionSet::RegisterExtension(&ExtendeeT::default_instance(), number,
  857. type, true, is_packed);
  858. }
  859. };
  860. class PROTOBUF_EXPORT RepeatedPrimitiveDefaults {
  861. private:
  862. template <typename Type>
  863. friend class RepeatedPrimitiveTypeTraits;
  864. static const RepeatedPrimitiveDefaults* default_instance();
  865. RepeatedField<int32> default_repeated_field_int32_;
  866. RepeatedField<int64> default_repeated_field_int64_;
  867. RepeatedField<uint32> default_repeated_field_uint32_;
  868. RepeatedField<uint64> default_repeated_field_uint64_;
  869. RepeatedField<double> default_repeated_field_double_;
  870. RepeatedField<float> default_repeated_field_float_;
  871. RepeatedField<bool> default_repeated_field_bool_;
  872. };
  873. #define PROTOBUF_DEFINE_PRIMITIVE_TYPE(TYPE, METHOD) \
  874. template <> \
  875. inline TYPE PrimitiveTypeTraits<TYPE>::Get( \
  876. int number, const ExtensionSet& set, TYPE default_value) { \
  877. return set.Get##METHOD(number, default_value); \
  878. } \
  879. template <> \
  880. inline void PrimitiveTypeTraits<TYPE>::Set(int number, FieldType field_type, \
  881. TYPE value, ExtensionSet* set) { \
  882. set->Set##METHOD(number, field_type, value, NULL); \
  883. } \
  884. \
  885. template <> \
  886. inline TYPE RepeatedPrimitiveTypeTraits<TYPE>::Get( \
  887. int number, const ExtensionSet& set, int index) { \
  888. return set.GetRepeated##METHOD(number, index); \
  889. } \
  890. template <> \
  891. inline void RepeatedPrimitiveTypeTraits<TYPE>::Set( \
  892. int number, int index, TYPE value, ExtensionSet* set) { \
  893. set->SetRepeated##METHOD(number, index, value); \
  894. } \
  895. template <> \
  896. inline void RepeatedPrimitiveTypeTraits<TYPE>::Add( \
  897. int number, FieldType field_type, bool is_packed, TYPE value, \
  898. ExtensionSet* set) { \
  899. set->Add##METHOD(number, field_type, is_packed, value, NULL); \
  900. } \
  901. template <> \
  902. inline const RepeatedField<TYPE>* \
  903. RepeatedPrimitiveTypeTraits<TYPE>::GetDefaultRepeatedField() { \
  904. return &RepeatedPrimitiveDefaults::default_instance() \
  905. ->default_repeated_field_##TYPE##_; \
  906. } \
  907. template <> \
  908. inline const RepeatedField<TYPE>& \
  909. RepeatedPrimitiveTypeTraits<TYPE>::GetRepeated(int number, \
  910. const ExtensionSet& set) { \
  911. return *reinterpret_cast<const RepeatedField<TYPE>*>( \
  912. set.GetRawRepeatedField(number, GetDefaultRepeatedField())); \
  913. } \
  914. template <> \
  915. inline RepeatedField<TYPE>* \
  916. RepeatedPrimitiveTypeTraits<TYPE>::MutableRepeated( \
  917. int number, FieldType field_type, bool is_packed, ExtensionSet* set) { \
  918. return reinterpret_cast<RepeatedField<TYPE>*>( \
  919. set->MutableRawRepeatedField(number, field_type, is_packed, NULL)); \
  920. }
  921. PROTOBUF_DEFINE_PRIMITIVE_TYPE(int32, Int32)
  922. PROTOBUF_DEFINE_PRIMITIVE_TYPE(int64, Int64)
  923. PROTOBUF_DEFINE_PRIMITIVE_TYPE(uint32, UInt32)
  924. PROTOBUF_DEFINE_PRIMITIVE_TYPE(uint64, UInt64)
  925. PROTOBUF_DEFINE_PRIMITIVE_TYPE(float, Float)
  926. PROTOBUF_DEFINE_PRIMITIVE_TYPE(double, Double)
  927. PROTOBUF_DEFINE_PRIMITIVE_TYPE(bool, Bool)
  928. #undef PROTOBUF_DEFINE_PRIMITIVE_TYPE
  929. // -------------------------------------------------------------------
  930. // StringTypeTraits
  931. // Strings support both Set() and Mutable().
  932. class PROTOBUF_EXPORT StringTypeTraits {
  933. public:
  934. typedef const std::string& ConstType;
  935. typedef std::string* MutableType;
  936. typedef StringTypeTraits Singular;
  937. static inline const std::string& Get(int number, const ExtensionSet& set,
  938. ConstType default_value) {
  939. return set.GetString(number, default_value);
  940. }
  941. static inline void Set(int number, FieldType field_type,
  942. const std::string& value, ExtensionSet* set) {
  943. set->SetString(number, field_type, value, NULL);
  944. }
  945. static inline std::string* Mutable(int number, FieldType field_type,
  946. ExtensionSet* set) {
  947. return set->MutableString(number, field_type, NULL);
  948. }
  949. template <typename ExtendeeT>
  950. static void Register(int number, FieldType type, bool is_packed) {
  951. ExtensionSet::RegisterExtension(&ExtendeeT::default_instance(), number,
  952. type, false, is_packed);
  953. }
  954. };
  955. class PROTOBUF_EXPORT RepeatedStringTypeTraits {
  956. public:
  957. typedef const std::string& ConstType;
  958. typedef std::string* MutableType;
  959. typedef RepeatedStringTypeTraits Repeated;
  960. typedef RepeatedPtrField<std::string> RepeatedFieldType;
  961. static inline const std::string& Get(int number, const ExtensionSet& set,
  962. int index) {
  963. return set.GetRepeatedString(number, index);
  964. }
  965. static inline void Set(int number, int index, const std::string& value,
  966. ExtensionSet* set) {
  967. set->SetRepeatedString(number, index, value);
  968. }
  969. static inline std::string* Mutable(int number, int index, ExtensionSet* set) {
  970. return set->MutableRepeatedString(number, index);
  971. }
  972. static inline void Add(int number, FieldType field_type, bool /*is_packed*/,
  973. const std::string& value, ExtensionSet* set) {
  974. set->AddString(number, field_type, value, NULL);
  975. }
  976. static inline std::string* Add(int number, FieldType field_type,
  977. ExtensionSet* set) {
  978. return set->AddString(number, field_type, NULL);
  979. }
  980. static inline const RepeatedPtrField<std::string>& GetRepeated(
  981. int number, const ExtensionSet& set) {
  982. return *reinterpret_cast<const RepeatedPtrField<std::string>*>(
  983. set.GetRawRepeatedField(number, GetDefaultRepeatedField()));
  984. }
  985. static inline RepeatedPtrField<std::string>* MutableRepeated(
  986. int number, FieldType field_type, bool is_packed, ExtensionSet* set) {
  987. return reinterpret_cast<RepeatedPtrField<std::string>*>(
  988. set->MutableRawRepeatedField(number, field_type, is_packed, NULL));
  989. }
  990. static const RepeatedFieldType* GetDefaultRepeatedField();
  991. template <typename ExtendeeT>
  992. static void Register(int number, FieldType type, bool is_packed) {
  993. ExtensionSet::RegisterExtension(&ExtendeeT::default_instance(), number,
  994. type, true, is_packed);
  995. }
  996. private:
  997. static void InitializeDefaultRepeatedFields();
  998. static void DestroyDefaultRepeatedFields();
  999. };
  1000. // -------------------------------------------------------------------
  1001. // EnumTypeTraits
  1002. // ExtensionSet represents enums using integers internally, so we have to
  1003. // static_cast around.
  1004. template <typename Type, bool IsValid(int)>
  1005. class EnumTypeTraits {
  1006. public:
  1007. typedef Type ConstType;
  1008. typedef Type MutableType;
  1009. typedef EnumTypeTraits<Type, IsValid> Singular;
  1010. static inline ConstType Get(int number, const ExtensionSet& set,
  1011. ConstType default_value) {
  1012. return static_cast<Type>(set.GetEnum(number, default_value));
  1013. }
  1014. static inline void Set(int number, FieldType field_type, ConstType value,
  1015. ExtensionSet* set) {
  1016. GOOGLE_DCHECK(IsValid(value));
  1017. set->SetEnum(number, field_type, value, NULL);
  1018. }
  1019. template <typename ExtendeeT>
  1020. static void Register(int number, FieldType type, bool is_packed) {
  1021. ExtensionSet::RegisterEnumExtension(&ExtendeeT::default_instance(), number,
  1022. type, false, is_packed, IsValid);
  1023. }
  1024. };
  1025. template <typename Type, bool IsValid(int)>
  1026. class RepeatedEnumTypeTraits {
  1027. public:
  1028. typedef Type ConstType;
  1029. typedef Type MutableType;
  1030. typedef RepeatedEnumTypeTraits<Type, IsValid> Repeated;
  1031. typedef RepeatedField<Type> RepeatedFieldType;
  1032. static inline ConstType Get(int number, const ExtensionSet& set, int index) {
  1033. return static_cast<Type>(set.GetRepeatedEnum(number, index));
  1034. }
  1035. static inline void Set(int number, int index, ConstType value,
  1036. ExtensionSet* set) {
  1037. GOOGLE_DCHECK(IsValid(value));
  1038. set->SetRepeatedEnum(number, index, value);
  1039. }
  1040. static inline void Add(int number, FieldType field_type, bool is_packed,
  1041. ConstType value, ExtensionSet* set) {
  1042. GOOGLE_DCHECK(IsValid(value));
  1043. set->AddEnum(number, field_type, is_packed, value, NULL);
  1044. }
  1045. static inline const RepeatedField<Type>& GetRepeated(
  1046. int number, const ExtensionSet& set) {
  1047. // Hack: the `Extension` struct stores a RepeatedField<int> for enums.
  1048. // RepeatedField<int> cannot implicitly convert to RepeatedField<EnumType>
  1049. // so we need to do some casting magic. See message.h for similar
  1050. // contortions for non-extension fields.
  1051. return *reinterpret_cast<const RepeatedField<Type>*>(
  1052. set.GetRawRepeatedField(number, GetDefaultRepeatedField()));
  1053. }
  1054. static inline RepeatedField<Type>* MutableRepeated(int number,
  1055. FieldType field_type,
  1056. bool is_packed,
  1057. ExtensionSet* set) {
  1058. return reinterpret_cast<RepeatedField<Type>*>(
  1059. set->MutableRawRepeatedField(number, field_type, is_packed, NULL));
  1060. }
  1061. static const RepeatedFieldType* GetDefaultRepeatedField() {
  1062. // Hack: as noted above, repeated enum fields are internally stored as a
  1063. // RepeatedField<int>. We need to be able to instantiate global static
  1064. // objects to return as default (empty) repeated fields on non-existent
  1065. // extensions. We would not be able to know a-priori all of the enum types
  1066. // (values of |Type|) to instantiate all of these, so we just re-use int32's
  1067. // default repeated field object.
  1068. return reinterpret_cast<const RepeatedField<Type>*>(
  1069. RepeatedPrimitiveTypeTraits<int32>::GetDefaultRepeatedField());
  1070. }
  1071. template <typename ExtendeeT>
  1072. static void Register(int number, FieldType type, bool is_packed) {
  1073. ExtensionSet::RegisterEnumExtension(&ExtendeeT::default_instance(), number,
  1074. type, true, is_packed, IsValid);
  1075. }
  1076. };
  1077. // -------------------------------------------------------------------
  1078. // MessageTypeTraits
  1079. // ExtensionSet guarantees that when manipulating extensions with message
  1080. // types, the implementation used will be the compiled-in class representing
  1081. // that type. So, we can static_cast down to the exact type we expect.
  1082. template <typename Type>
  1083. class MessageTypeTraits {
  1084. public:
  1085. typedef const Type& ConstType;
  1086. typedef Type* MutableType;
  1087. typedef MessageTypeTraits<Type> Singular;
  1088. static inline ConstType Get(int number, const ExtensionSet& set,
  1089. ConstType default_value) {
  1090. return static_cast<const Type&>(set.GetMessage(number, default_value));
  1091. }
  1092. static inline MutableType Mutable(int number, FieldType field_type,
  1093. ExtensionSet* set) {
  1094. return static_cast<Type*>(set->MutableMessage(
  1095. number, field_type, Type::default_instance(), NULL));
  1096. }
  1097. static inline void SetAllocated(int number, FieldType field_type,
  1098. MutableType message, ExtensionSet* set) {
  1099. set->SetAllocatedMessage(number, field_type, NULL, message);
  1100. }
  1101. static inline void UnsafeArenaSetAllocated(int number, FieldType field_type,
  1102. MutableType message,
  1103. ExtensionSet* set) {
  1104. set->UnsafeArenaSetAllocatedMessage(number, field_type, NULL, message);
  1105. }
  1106. static inline MutableType Release(int number, FieldType /* field_type */,
  1107. ExtensionSet* set) {
  1108. return static_cast<Type*>(
  1109. set->ReleaseMessage(number, Type::default_instance()));
  1110. }
  1111. static inline MutableType UnsafeArenaRelease(int number,
  1112. FieldType /* field_type */,
  1113. ExtensionSet* set) {
  1114. return static_cast<Type*>(
  1115. set->UnsafeArenaReleaseMessage(number, Type::default_instance()));
  1116. }
  1117. template <typename ExtendeeT>
  1118. static void Register(int number, FieldType type, bool is_packed) {
  1119. ExtensionSet::RegisterMessageExtension(&ExtendeeT::default_instance(),
  1120. number, type, false, is_packed,
  1121. &Type::default_instance());
  1122. }
  1123. };
  1124. // forward declaration
  1125. class RepeatedMessageGenericTypeTraits;
  1126. template <typename Type>
  1127. class RepeatedMessageTypeTraits {
  1128. public:
  1129. typedef const Type& ConstType;
  1130. typedef Type* MutableType;
  1131. typedef RepeatedMessageTypeTraits<Type> Repeated;
  1132. typedef RepeatedPtrField<Type> RepeatedFieldType;
  1133. static inline ConstType Get(int number, const ExtensionSet& set, int index) {
  1134. return static_cast<const Type&>(set.GetRepeatedMessage(number, index));
  1135. }
  1136. static inline MutableType Mutable(int number, int index, ExtensionSet* set) {
  1137. return static_cast<Type*>(set->MutableRepeatedMessage(number, index));
  1138. }
  1139. static inline MutableType Add(int number, FieldType field_type,
  1140. ExtensionSet* set) {
  1141. return static_cast<Type*>(
  1142. set->AddMessage(number, field_type, Type::default_instance(), NULL));
  1143. }
  1144. static inline const RepeatedPtrField<Type>& GetRepeated(
  1145. int number, const ExtensionSet& set) {
  1146. // See notes above in RepeatedEnumTypeTraits::GetRepeated(): same
  1147. // casting hack applies here, because a RepeatedPtrField<MessageLite>
  1148. // cannot naturally become a RepeatedPtrType<Type> even though Type is
  1149. // presumably a message. google::protobuf::Message goes through similar contortions
  1150. // with a reinterpret_cast<>.
  1151. return *reinterpret_cast<const RepeatedPtrField<Type>*>(
  1152. set.GetRawRepeatedField(number, GetDefaultRepeatedField()));
  1153. }
  1154. static inline RepeatedPtrField<Type>* MutableRepeated(int number,
  1155. FieldType field_type,
  1156. bool is_packed,
  1157. ExtensionSet* set) {
  1158. return reinterpret_cast<RepeatedPtrField<Type>*>(
  1159. set->MutableRawRepeatedField(number, field_type, is_packed, NULL));
  1160. }
  1161. static const RepeatedFieldType* GetDefaultRepeatedField();
  1162. template <typename ExtendeeT>
  1163. static void Register(int number, FieldType type, bool is_packed) {
  1164. ExtensionSet::RegisterMessageExtension(&ExtendeeT::default_instance(),
  1165. number, type, true, is_packed,
  1166. &Type::default_instance());
  1167. }
  1168. };
  1169. template <typename Type>
  1170. inline const typename RepeatedMessageTypeTraits<Type>::RepeatedFieldType*
  1171. RepeatedMessageTypeTraits<Type>::GetDefaultRepeatedField() {
  1172. static auto instance = OnShutdownDelete(new RepeatedFieldType);
  1173. return instance;
  1174. }
  1175. // -------------------------------------------------------------------
  1176. // ExtensionIdentifier
  1177. // This is the type of actual extension objects. E.g. if you have:
  1178. // extends Foo with optional int32 bar = 1234;
  1179. // then "bar" will be defined in C++ as:
  1180. // ExtensionIdentifier<Foo, PrimitiveTypeTraits<int32>, 5, false> bar(1234);
  1181. //
  1182. // Note that we could, in theory, supply the field number as a template
  1183. // parameter, and thus make an instance of ExtensionIdentifier have no
  1184. // actual contents. However, if we did that, then using an extension
  1185. // identifier would not necessarily cause the compiler to output any sort
  1186. // of reference to any symbol defined in the extension's .pb.o file. Some
  1187. // linkers will actually drop object files that are not explicitly referenced,
  1188. // but that would be bad because it would cause this extension to not be
  1189. // registered at static initialization, and therefore using it would crash.
  1190. template <typename ExtendeeType, typename TypeTraitsType, FieldType field_type,
  1191. bool is_packed>
  1192. class ExtensionIdentifier {
  1193. public:
  1194. typedef TypeTraitsType TypeTraits;
  1195. typedef ExtendeeType Extendee;
  1196. ExtensionIdentifier(int number, typename TypeTraits::ConstType default_value)
  1197. : number_(number), default_value_(default_value) {
  1198. Register(number);
  1199. }
  1200. inline int number() const { return number_; }
  1201. typename TypeTraits::ConstType default_value() const {
  1202. return default_value_;
  1203. }
  1204. static void Register(int number) {
  1205. TypeTraits::template Register<ExtendeeType>(number, field_type, is_packed);
  1206. }
  1207. private:
  1208. const int number_;
  1209. typename TypeTraits::ConstType default_value_;
  1210. };
  1211. // -------------------------------------------------------------------
  1212. // Generated accessors
  1213. // This macro should be expanded in the context of a generated type which
  1214. // has extensions.
  1215. //
  1216. // We use "_proto_TypeTraits" as a type name below because "TypeTraits"
  1217. // causes problems if the class has a nested message or enum type with that
  1218. // name and "_TypeTraits" is technically reserved for the C++ library since
  1219. // it starts with an underscore followed by a capital letter.
  1220. //
  1221. // For similar reason, we use "_field_type" and "_is_packed" as parameter names
  1222. // below, so that "field_type" and "is_packed" can be used as field names.
  1223. #define GOOGLE_PROTOBUF_EXTENSION_ACCESSORS(CLASSNAME) \
  1224. /* Has, Size, Clear */ \
  1225. template <typename _proto_TypeTraits, \
  1226. ::PROTOBUF_NAMESPACE_ID::internal::FieldType _field_type, \
  1227. bool _is_packed> \
  1228. inline bool HasExtension( \
  1229. const ::PROTOBUF_NAMESPACE_ID::internal::ExtensionIdentifier< \
  1230. CLASSNAME, _proto_TypeTraits, _field_type, _is_packed>& id) const { \
  1231. return _extensions_.Has(id.number()); \
  1232. } \
  1233. \
  1234. template <typename _proto_TypeTraits, \
  1235. ::PROTOBUF_NAMESPACE_ID::internal::FieldType _field_type, \
  1236. bool _is_packed> \
  1237. inline void ClearExtension( \
  1238. const ::PROTOBUF_NAMESPACE_ID::internal::ExtensionIdentifier< \
  1239. CLASSNAME, _proto_TypeTraits, _field_type, _is_packed>& id) { \
  1240. _extensions_.ClearExtension(id.number()); \
  1241. } \
  1242. \
  1243. template <typename _proto_TypeTraits, \
  1244. ::PROTOBUF_NAMESPACE_ID::internal::FieldType _field_type, \
  1245. bool _is_packed> \
  1246. inline int ExtensionSize( \
  1247. const ::PROTOBUF_NAMESPACE_ID::internal::ExtensionIdentifier< \
  1248. CLASSNAME, _proto_TypeTraits, _field_type, _is_packed>& id) const { \
  1249. return _extensions_.ExtensionSize(id.number()); \
  1250. } \
  1251. \
  1252. /* Singular accessors */ \
  1253. template <typename _proto_TypeTraits, \
  1254. ::PROTOBUF_NAMESPACE_ID::internal::FieldType _field_type, \
  1255. bool _is_packed> \
  1256. inline typename _proto_TypeTraits::Singular::ConstType GetExtension( \
  1257. const ::PROTOBUF_NAMESPACE_ID::internal::ExtensionIdentifier< \
  1258. CLASSNAME, _proto_TypeTraits, _field_type, _is_packed>& id) const { \
  1259. return _proto_TypeTraits::Get(id.number(), _extensions_, \
  1260. id.default_value()); \
  1261. } \
  1262. \
  1263. template <typename _proto_TypeTraits, \
  1264. ::PROTOBUF_NAMESPACE_ID::internal::FieldType _field_type, \
  1265. bool _is_packed> \
  1266. inline typename _proto_TypeTraits::Singular::MutableType MutableExtension( \
  1267. const ::PROTOBUF_NAMESPACE_ID::internal::ExtensionIdentifier< \
  1268. CLASSNAME, _proto_TypeTraits, _field_type, _is_packed>& id) { \
  1269. return _proto_TypeTraits::Mutable(id.number(), _field_type, \
  1270. &_extensions_); \
  1271. } \
  1272. \
  1273. template <typename _proto_TypeTraits, \
  1274. ::PROTOBUF_NAMESPACE_ID::internal::FieldType _field_type, \
  1275. bool _is_packed> \
  1276. inline void SetExtension( \
  1277. const ::PROTOBUF_NAMESPACE_ID::internal::ExtensionIdentifier< \
  1278. CLASSNAME, _proto_TypeTraits, _field_type, _is_packed>& id, \
  1279. typename _proto_TypeTraits::Singular::ConstType value) { \
  1280. _proto_TypeTraits::Set(id.number(), _field_type, value, &_extensions_); \
  1281. } \
  1282. \
  1283. template <typename _proto_TypeTraits, \
  1284. ::PROTOBUF_NAMESPACE_ID::internal::FieldType _field_type, \
  1285. bool _is_packed> \
  1286. inline void SetAllocatedExtension( \
  1287. const ::PROTOBUF_NAMESPACE_ID::internal::ExtensionIdentifier< \
  1288. CLASSNAME, _proto_TypeTraits, _field_type, _is_packed>& id, \
  1289. typename _proto_TypeTraits::Singular::MutableType value) { \
  1290. _proto_TypeTraits::SetAllocated(id.number(), _field_type, value, \
  1291. &_extensions_); \
  1292. } \
  1293. template <typename _proto_TypeTraits, \
  1294. ::PROTOBUF_NAMESPACE_ID::internal::FieldType _field_type, \
  1295. bool _is_packed> \
  1296. inline void UnsafeArenaSetAllocatedExtension( \
  1297. const ::PROTOBUF_NAMESPACE_ID::internal::ExtensionIdentifier< \
  1298. CLASSNAME, _proto_TypeTraits, _field_type, _is_packed>& id, \
  1299. typename _proto_TypeTraits::Singular::MutableType value) { \
  1300. _proto_TypeTraits::UnsafeArenaSetAllocated(id.number(), _field_type, \
  1301. value, &_extensions_); \
  1302. } \
  1303. template <typename _proto_TypeTraits, \
  1304. ::PROTOBUF_NAMESPACE_ID::internal::FieldType _field_type, \
  1305. bool _is_packed> \
  1306. inline typename _proto_TypeTraits::Singular::MutableType ReleaseExtension( \
  1307. const ::PROTOBUF_NAMESPACE_ID::internal::ExtensionIdentifier< \
  1308. CLASSNAME, _proto_TypeTraits, _field_type, _is_packed>& id) { \
  1309. return _proto_TypeTraits::Release(id.number(), _field_type, \
  1310. &_extensions_); \
  1311. } \
  1312. template <typename _proto_TypeTraits, \
  1313. ::PROTOBUF_NAMESPACE_ID::internal::FieldType _field_type, \
  1314. bool _is_packed> \
  1315. inline typename _proto_TypeTraits::Singular::MutableType \
  1316. UnsafeArenaReleaseExtension( \
  1317. const ::PROTOBUF_NAMESPACE_ID::internal::ExtensionIdentifier< \
  1318. CLASSNAME, _proto_TypeTraits, _field_type, _is_packed>& id) { \
  1319. return _proto_TypeTraits::UnsafeArenaRelease(id.number(), _field_type, \
  1320. &_extensions_); \
  1321. } \
  1322. \
  1323. /* Repeated accessors */ \
  1324. template <typename _proto_TypeTraits, \
  1325. ::PROTOBUF_NAMESPACE_ID::internal::FieldType _field_type, \
  1326. bool _is_packed> \
  1327. inline typename _proto_TypeTraits::Repeated::ConstType GetExtension( \
  1328. const ::PROTOBUF_NAMESPACE_ID::internal::ExtensionIdentifier< \
  1329. CLASSNAME, _proto_TypeTraits, _field_type, _is_packed>& id, \
  1330. int index) const { \
  1331. return _proto_TypeTraits::Get(id.number(), _extensions_, index); \
  1332. } \
  1333. \
  1334. template <typename _proto_TypeTraits, \
  1335. ::PROTOBUF_NAMESPACE_ID::internal::FieldType _field_type, \
  1336. bool _is_packed> \
  1337. inline typename _proto_TypeTraits::Repeated::MutableType MutableExtension( \
  1338. const ::PROTOBUF_NAMESPACE_ID::internal::ExtensionIdentifier< \
  1339. CLASSNAME, _proto_TypeTraits, _field_type, _is_packed>& id, \
  1340. int index) { \
  1341. return _proto_TypeTraits::Mutable(id.number(), index, &_extensions_); \
  1342. } \
  1343. \
  1344. template <typename _proto_TypeTraits, \
  1345. ::PROTOBUF_NAMESPACE_ID::internal::FieldType _field_type, \
  1346. bool _is_packed> \
  1347. inline void SetExtension( \
  1348. const ::PROTOBUF_NAMESPACE_ID::internal::ExtensionIdentifier< \
  1349. CLASSNAME, _proto_TypeTraits, _field_type, _is_packed>& id, \
  1350. int index, typename _proto_TypeTraits::Repeated::ConstType value) { \
  1351. _proto_TypeTraits::Set(id.number(), index, value, &_extensions_); \
  1352. } \
  1353. \
  1354. template <typename _proto_TypeTraits, \
  1355. ::PROTOBUF_NAMESPACE_ID::internal::FieldType _field_type, \
  1356. bool _is_packed> \
  1357. inline typename _proto_TypeTraits::Repeated::MutableType AddExtension( \
  1358. const ::PROTOBUF_NAMESPACE_ID::internal::ExtensionIdentifier< \
  1359. CLASSNAME, _proto_TypeTraits, _field_type, _is_packed>& id) { \
  1360. return _proto_TypeTraits::Add(id.number(), _field_type, &_extensions_); \
  1361. } \
  1362. \
  1363. template <typename _proto_TypeTraits, \
  1364. ::PROTOBUF_NAMESPACE_ID::internal::FieldType _field_type, \
  1365. bool _is_packed> \
  1366. inline void AddExtension( \
  1367. const ::PROTOBUF_NAMESPACE_ID::internal::ExtensionIdentifier< \
  1368. CLASSNAME, _proto_TypeTraits, _field_type, _is_packed>& id, \
  1369. typename _proto_TypeTraits::Repeated::ConstType value) { \
  1370. _proto_TypeTraits::Add(id.number(), _field_type, _is_packed, value, \
  1371. &_extensions_); \
  1372. } \
  1373. \
  1374. template <typename _proto_TypeTraits, \
  1375. ::PROTOBUF_NAMESPACE_ID::internal::FieldType _field_type, \
  1376. bool _is_packed> \
  1377. inline const typename _proto_TypeTraits::Repeated::RepeatedFieldType& \
  1378. GetRepeatedExtension( \
  1379. const ::PROTOBUF_NAMESPACE_ID::internal::ExtensionIdentifier< \
  1380. CLASSNAME, _proto_TypeTraits, _field_type, _is_packed>& id) const { \
  1381. return _proto_TypeTraits::GetRepeated(id.number(), _extensions_); \
  1382. } \
  1383. \
  1384. template <typename _proto_TypeTraits, \
  1385. ::PROTOBUF_NAMESPACE_ID::internal::FieldType _field_type, \
  1386. bool _is_packed> \
  1387. inline typename _proto_TypeTraits::Repeated::RepeatedFieldType* \
  1388. MutableRepeatedExtension( \
  1389. const ::PROTOBUF_NAMESPACE_ID::internal::ExtensionIdentifier< \
  1390. CLASSNAME, _proto_TypeTraits, _field_type, _is_packed>& id) { \
  1391. return _proto_TypeTraits::MutableRepeated(id.number(), _field_type, \
  1392. _is_packed, &_extensions_); \
  1393. }
  1394. } // namespace internal
  1395. // Call this function to ensure that this extensions's reflection is linked into
  1396. // the binary:
  1397. //
  1398. // google::protobuf::LinkExtensionReflection(Foo::my_extension);
  1399. //
  1400. // This will ensure that the following lookup will succeed:
  1401. //
  1402. // DescriptorPool::generated_pool()->FindExtensionByName("Foo.my_extension");
  1403. //
  1404. // This is often relevant for parsing extensions in text mode.
  1405. //
  1406. // As a side-effect, it will also guarantee that anything else from the same
  1407. // .proto file will also be available for lookup in the generated pool.
  1408. //
  1409. // This function does not actually register the extension, so it does not need
  1410. // to be called before the lookup. However it does need to occur in a function
  1411. // that cannot be stripped from the binary (ie. it must be reachable from main).
  1412. //
  1413. // Best practice is to call this function as close as possible to where the
  1414. // reflection is actually needed. This function is very cheap to call, so you
  1415. // should not need to worry about its runtime overhead except in tight loops (on
  1416. // x86-64 it compiles into two "mov" instructions).
  1417. template <typename ExtendeeType, typename TypeTraitsType,
  1418. internal::FieldType field_type, bool is_packed>
  1419. void LinkExtensionReflection(
  1420. const google::protobuf::internal::ExtensionIdentifier<
  1421. ExtendeeType, TypeTraitsType, field_type, is_packed>& extension) {
  1422. internal::StrongReference(extension);
  1423. }
  1424. } // namespace protobuf
  1425. } // namespace google
  1426. #include <google/protobuf/port_undef.inc>
  1427. #endif // GOOGLE_PROTOBUF_EXTENSION_SET_H__