诸暨麻将添加redis
您不能選擇超過 %s 個話題 話題必須以字母或數字為開頭,可包含連接號 ('-') 且最長為 35 個字
 
 
 
 
 
 

392 行
14 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. // Contains classes used to keep track of unrecognized fields seen while
  35. // parsing a protocol message.
  36. #ifndef GOOGLE_PROTOBUF_UNKNOWN_FIELD_SET_H__
  37. #define GOOGLE_PROTOBUF_UNKNOWN_FIELD_SET_H__
  38. #include <assert.h>
  39. #include <string>
  40. #include <vector>
  41. #include <google/protobuf/stubs/common.h>
  42. #include <google/protobuf/stubs/logging.h>
  43. #include <google/protobuf/parse_context.h>
  44. #include <google/protobuf/io/coded_stream.h>
  45. #include <google/protobuf/message_lite.h>
  46. #include <google/protobuf/port.h>
  47. #include <google/protobuf/port_def.inc>
  48. #ifdef SWIG
  49. #error "You cannot SWIG proto headers"
  50. #endif
  51. namespace google {
  52. namespace protobuf {
  53. namespace internal {
  54. class InternalMetadataWithArena; // metadata.h
  55. class WireFormat; // wire_format.h
  56. class MessageSetFieldSkipperUsingCord;
  57. // extension_set_heavy.cc
  58. } // namespace internal
  59. class Message; // message.h
  60. class UnknownField; // below
  61. // An UnknownFieldSet contains fields that were encountered while parsing a
  62. // message but were not defined by its type. Keeping track of these can be
  63. // useful, especially in that they may be written if the message is serialized
  64. // again without being cleared in between. This means that software which
  65. // simply receives messages and forwards them to other servers does not need
  66. // to be updated every time a new field is added to the message definition.
  67. //
  68. // To get the UnknownFieldSet attached to any message, call
  69. // Reflection::GetUnknownFields().
  70. //
  71. // This class is necessarily tied to the protocol buffer wire format, unlike
  72. // the Reflection interface which is independent of any serialization scheme.
  73. class PROTOBUF_EXPORT UnknownFieldSet {
  74. public:
  75. UnknownFieldSet();
  76. ~UnknownFieldSet();
  77. // Remove all fields.
  78. inline void Clear();
  79. // Remove all fields and deallocate internal data objects
  80. void ClearAndFreeMemory();
  81. // Is this set empty?
  82. inline bool empty() const;
  83. // Merge the contents of some other UnknownFieldSet with this one.
  84. void MergeFrom(const UnknownFieldSet& other);
  85. // Similar to above, but this function will destroy the contents of other.
  86. void MergeFromAndDestroy(UnknownFieldSet* other);
  87. // Merge the contents an UnknownFieldSet with the UnknownFieldSet in
  88. // *metadata, if there is one. If *metadata doesn't have an UnknownFieldSet
  89. // then add one to it and make it be a copy of the first arg.
  90. static void MergeToInternalMetdata(
  91. const UnknownFieldSet& other,
  92. internal::InternalMetadataWithArena* metadata);
  93. // Swaps the contents of some other UnknownFieldSet with this one.
  94. inline void Swap(UnknownFieldSet* x);
  95. // Computes (an estimate of) the total number of bytes currently used for
  96. // storing the unknown fields in memory. Does NOT include
  97. // sizeof(*this) in the calculation.
  98. size_t SpaceUsedExcludingSelfLong() const;
  99. int SpaceUsedExcludingSelf() const {
  100. return internal::ToIntSize(SpaceUsedExcludingSelfLong());
  101. }
  102. // Version of SpaceUsed() including sizeof(*this).
  103. size_t SpaceUsedLong() const;
  104. int SpaceUsed() const { return internal::ToIntSize(SpaceUsedLong()); }
  105. // Returns the number of fields present in the UnknownFieldSet.
  106. inline int field_count() const;
  107. // Get a field in the set, where 0 <= index < field_count(). The fields
  108. // appear in the order in which they were added.
  109. inline const UnknownField& field(int index) const;
  110. // Get a mutable pointer to a field in the set, where
  111. // 0 <= index < field_count(). The fields appear in the order in which
  112. // they were added.
  113. inline UnknownField* mutable_field(int index);
  114. // Adding fields ---------------------------------------------------
  115. void AddVarint(int number, uint64 value);
  116. void AddFixed32(int number, uint32 value);
  117. void AddFixed64(int number, uint64 value);
  118. void AddLengthDelimited(int number, const std::string& value);
  119. std::string* AddLengthDelimited(int number);
  120. UnknownFieldSet* AddGroup(int number);
  121. // Adds an unknown field from another set.
  122. void AddField(const UnknownField& field);
  123. // Delete fields with indices in the range [start .. start+num-1].
  124. // Caution: implementation moves all fields with indices [start+num .. ].
  125. void DeleteSubrange(int start, int num);
  126. // Delete all fields with a specific field number. The order of left fields
  127. // is preserved.
  128. // Caution: implementation moves all fields after the first deleted field.
  129. void DeleteByNumber(int number);
  130. // Parsing helpers -------------------------------------------------
  131. // These work exactly like the similarly-named methods of Message.
  132. bool MergeFromCodedStream(io::CodedInputStream* input);
  133. bool ParseFromCodedStream(io::CodedInputStream* input);
  134. bool ParseFromZeroCopyStream(io::ZeroCopyInputStream* input);
  135. bool ParseFromArray(const void* data, int size);
  136. inline bool ParseFromString(const std::string& data) {
  137. return ParseFromArray(data.data(), static_cast<int>(data.size()));
  138. }
  139. static const UnknownFieldSet* default_instance();
  140. private:
  141. // For InternalMergeFrom
  142. friend class UnknownField;
  143. // Merges from other UnknownFieldSet. This method assumes, that this object
  144. // is newly created and has no fields.
  145. void InternalMergeFrom(const UnknownFieldSet& other);
  146. void ClearFallback();
  147. std::vector<UnknownField> fields_;
  148. GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(UnknownFieldSet);
  149. };
  150. namespace internal {
  151. inline void WriteVarint(uint32 num, uint64 val, UnknownFieldSet* unknown) {
  152. unknown->AddVarint(num, val);
  153. }
  154. inline void WriteLengthDelimited(uint32 num, StringPiece val,
  155. UnknownFieldSet* unknown) {
  156. unknown->AddLengthDelimited(num)->assign(val.data(), val.size());
  157. }
  158. PROTOBUF_EXPORT
  159. const char* PackedEnumParser(void* object, const char* ptr, ParseContext* ctx,
  160. bool (*is_valid)(int),
  161. InternalMetadataWithArena* unknown, int field_num);
  162. PROTOBUF_EXPORT
  163. const char* PackedEnumParserArg(void* object, const char* ptr,
  164. ParseContext* ctx,
  165. bool (*is_valid)(const void*, int),
  166. const void* data,
  167. InternalMetadataWithArena* unknown,
  168. int field_num);
  169. PROTOBUF_EXPORT
  170. const char* UnknownGroupParse(UnknownFieldSet* unknown, const char* ptr,
  171. ParseContext* ctx);
  172. PROTOBUF_EXPORT
  173. const char* UnknownFieldParse(uint64 tag, UnknownFieldSet* unknown,
  174. const char* ptr, ParseContext* ctx);
  175. PROTOBUF_EXPORT
  176. const char* UnknownFieldParse(uint32 tag, InternalMetadataWithArena* metadata,
  177. const char* ptr, ParseContext* ctx);
  178. } // namespace internal
  179. // Represents one field in an UnknownFieldSet.
  180. class PROTOBUF_EXPORT UnknownField {
  181. public:
  182. enum Type {
  183. TYPE_VARINT,
  184. TYPE_FIXED32,
  185. TYPE_FIXED64,
  186. TYPE_LENGTH_DELIMITED,
  187. TYPE_GROUP
  188. };
  189. // The field's field number, as seen on the wire.
  190. inline int number() const;
  191. // The field type.
  192. inline Type type() const;
  193. // Accessors -------------------------------------------------------
  194. // Each method works only for UnknownFields of the corresponding type.
  195. inline uint64 varint() const;
  196. inline uint32 fixed32() const;
  197. inline uint64 fixed64() const;
  198. inline const std::string& length_delimited() const;
  199. inline const UnknownFieldSet& group() const;
  200. inline void set_varint(uint64 value);
  201. inline void set_fixed32(uint32 value);
  202. inline void set_fixed64(uint64 value);
  203. inline void set_length_delimited(const std::string& value);
  204. inline std::string* mutable_length_delimited();
  205. inline UnknownFieldSet* mutable_group();
  206. // Serialization API.
  207. // These methods can take advantage of the underlying implementation and may
  208. // archieve a better performance than using getters to retrieve the data and
  209. // do the serialization yourself.
  210. void SerializeLengthDelimitedNoTag(io::CodedOutputStream* output) const {
  211. output->SetCur(InternalSerializeLengthDelimitedNoTag(output->Cur(),
  212. output->EpsCopy()));
  213. }
  214. inline size_t GetLengthDelimitedSize() const;
  215. uint8* InternalSerializeLengthDelimitedNoTag(
  216. uint8* target, io::EpsCopyOutputStream* stream) const;
  217. // If this UnknownField contains a pointer, delete it.
  218. void Delete();
  219. // Make a deep copy of any pointers in this UnknownField.
  220. void DeepCopy(const UnknownField& other);
  221. // Set the wire type of this UnknownField. Should only be used when this
  222. // UnknownField is being created.
  223. inline void SetType(Type type);
  224. union LengthDelimited {
  225. std::string* string_value;
  226. };
  227. uint32 number_;
  228. uint32 type_;
  229. union {
  230. uint64 varint_;
  231. uint32 fixed32_;
  232. uint64 fixed64_;
  233. mutable union LengthDelimited length_delimited_;
  234. UnknownFieldSet* group_;
  235. } data_;
  236. };
  237. // ===================================================================
  238. // inline implementations
  239. inline UnknownFieldSet::UnknownFieldSet() {}
  240. inline UnknownFieldSet::~UnknownFieldSet() { Clear(); }
  241. inline void UnknownFieldSet::ClearAndFreeMemory() { Clear(); }
  242. inline void UnknownFieldSet::Clear() {
  243. if (!fields_.empty()) {
  244. ClearFallback();
  245. }
  246. }
  247. inline bool UnknownFieldSet::empty() const { return fields_.empty(); }
  248. inline void UnknownFieldSet::Swap(UnknownFieldSet* x) {
  249. fields_.swap(x->fields_);
  250. }
  251. inline int UnknownFieldSet::field_count() const {
  252. return static_cast<int>(fields_.size());
  253. }
  254. inline const UnknownField& UnknownFieldSet::field(int index) const {
  255. return (fields_)[static_cast<size_t>(index)];
  256. }
  257. inline UnknownField* UnknownFieldSet::mutable_field(int index) {
  258. return &(fields_)[static_cast<size_t>(index)];
  259. }
  260. inline void UnknownFieldSet::AddLengthDelimited(int number,
  261. const std::string& value) {
  262. AddLengthDelimited(number)->assign(value);
  263. }
  264. inline int UnknownField::number() const { return static_cast<int>(number_); }
  265. inline UnknownField::Type UnknownField::type() const {
  266. return static_cast<Type>(type_);
  267. }
  268. inline uint64 UnknownField::varint() const {
  269. assert(type() == TYPE_VARINT);
  270. return data_.varint_;
  271. }
  272. inline uint32 UnknownField::fixed32() const {
  273. assert(type() == TYPE_FIXED32);
  274. return data_.fixed32_;
  275. }
  276. inline uint64 UnknownField::fixed64() const {
  277. assert(type() == TYPE_FIXED64);
  278. return data_.fixed64_;
  279. }
  280. inline const std::string& UnknownField::length_delimited() const {
  281. assert(type() == TYPE_LENGTH_DELIMITED);
  282. return *data_.length_delimited_.string_value;
  283. }
  284. inline const UnknownFieldSet& UnknownField::group() const {
  285. assert(type() == TYPE_GROUP);
  286. return *data_.group_;
  287. }
  288. inline void UnknownField::set_varint(uint64 value) {
  289. assert(type() == TYPE_VARINT);
  290. data_.varint_ = value;
  291. }
  292. inline void UnknownField::set_fixed32(uint32 value) {
  293. assert(type() == TYPE_FIXED32);
  294. data_.fixed32_ = value;
  295. }
  296. inline void UnknownField::set_fixed64(uint64 value) {
  297. assert(type() == TYPE_FIXED64);
  298. data_.fixed64_ = value;
  299. }
  300. inline void UnknownField::set_length_delimited(const std::string& value) {
  301. assert(type() == TYPE_LENGTH_DELIMITED);
  302. data_.length_delimited_.string_value->assign(value);
  303. }
  304. inline std::string* UnknownField::mutable_length_delimited() {
  305. assert(type() == TYPE_LENGTH_DELIMITED);
  306. return data_.length_delimited_.string_value;
  307. }
  308. inline UnknownFieldSet* UnknownField::mutable_group() {
  309. assert(type() == TYPE_GROUP);
  310. return data_.group_;
  311. }
  312. inline size_t UnknownField::GetLengthDelimitedSize() const {
  313. GOOGLE_DCHECK_EQ(TYPE_LENGTH_DELIMITED, type());
  314. return data_.length_delimited_.string_value->size();
  315. }
  316. inline void UnknownField::SetType(Type type) {
  317. type_ = type;
  318. }
  319. } // namespace protobuf
  320. } // namespace google
  321. #include <google/protobuf/port_undef.inc>
  322. #endif // GOOGLE_PROTOBUF_UNKNOWN_FIELD_SET_H__