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

275 行
12 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. #ifndef GOOGLE_PROTOBUF_EXTENSION_SET_INL_H__
  31. #define GOOGLE_PROTOBUF_EXTENSION_SET_INL_H__
  32. #include <google/protobuf/parse_context.h>
  33. #include <google/protobuf/extension_set.h>
  34. namespace google {
  35. namespace protobuf {
  36. namespace internal {
  37. template <typename T>
  38. const char* ExtensionSet::ParseFieldWithExtensionInfo(
  39. int number, bool was_packed_on_wire, const ExtensionInfo& extension,
  40. T* metadata, const char* ptr, internal::ParseContext* ctx) {
  41. if (was_packed_on_wire) {
  42. switch (extension.type) {
  43. #define HANDLE_TYPE(UPPERCASE, CPP_CAMELCASE) \
  44. case WireFormatLite::TYPE_##UPPERCASE: \
  45. return internal::Packed##CPP_CAMELCASE##Parser( \
  46. MutableRawRepeatedField(number, extension.type, extension.is_packed, \
  47. extension.descriptor), \
  48. ptr, ctx);
  49. HANDLE_TYPE(INT32, Int32);
  50. HANDLE_TYPE(INT64, Int64);
  51. HANDLE_TYPE(UINT32, UInt32);
  52. HANDLE_TYPE(UINT64, UInt64);
  53. HANDLE_TYPE(SINT32, SInt32);
  54. HANDLE_TYPE(SINT64, SInt64);
  55. HANDLE_TYPE(FIXED32, Fixed32);
  56. HANDLE_TYPE(FIXED64, Fixed64);
  57. HANDLE_TYPE(SFIXED32, SFixed32);
  58. HANDLE_TYPE(SFIXED64, SFixed64);
  59. HANDLE_TYPE(FLOAT, Float);
  60. HANDLE_TYPE(DOUBLE, Double);
  61. HANDLE_TYPE(BOOL, Bool);
  62. #undef HANDLE_TYPE
  63. case WireFormatLite::TYPE_ENUM:
  64. return internal::PackedEnumParserArg(
  65. MutableRawRepeatedField(number, extension.type, extension.is_packed,
  66. extension.descriptor),
  67. ptr, ctx, extension.enum_validity_check.func,
  68. extension.enum_validity_check.arg, metadata, number);
  69. case WireFormatLite::TYPE_STRING:
  70. case WireFormatLite::TYPE_BYTES:
  71. case WireFormatLite::TYPE_GROUP:
  72. case WireFormatLite::TYPE_MESSAGE:
  73. GOOGLE_LOG(FATAL) << "Non-primitive types can't be packed.";
  74. break;
  75. }
  76. } else {
  77. switch (extension.type) {
  78. #define HANDLE_VARINT_TYPE(UPPERCASE, CPP_CAMELCASE) \
  79. case WireFormatLite::TYPE_##UPPERCASE: { \
  80. uint64 value; \
  81. ptr = VarintParse(ptr, &value); \
  82. GOOGLE_PROTOBUF_PARSER_ASSERT(ptr); \
  83. if (extension.is_repeated) { \
  84. Add##CPP_CAMELCASE(number, WireFormatLite::TYPE_##UPPERCASE, \
  85. extension.is_packed, value, extension.descriptor); \
  86. } else { \
  87. Set##CPP_CAMELCASE(number, WireFormatLite::TYPE_##UPPERCASE, value, \
  88. extension.descriptor); \
  89. } \
  90. } break
  91. HANDLE_VARINT_TYPE(INT32, Int32);
  92. HANDLE_VARINT_TYPE(INT64, Int64);
  93. HANDLE_VARINT_TYPE(UINT32, UInt32);
  94. HANDLE_VARINT_TYPE(UINT64, UInt64);
  95. #undef HANDLE_VARINT_TYPE
  96. #define HANDLE_SVARINT_TYPE(UPPERCASE, CPP_CAMELCASE, SIZE) \
  97. case WireFormatLite::TYPE_##UPPERCASE: { \
  98. uint64 val; \
  99. ptr = VarintParse(ptr, &val); \
  100. GOOGLE_PROTOBUF_PARSER_ASSERT(ptr); \
  101. auto value = WireFormatLite::ZigZagDecode##SIZE(val); \
  102. if (extension.is_repeated) { \
  103. Add##CPP_CAMELCASE(number, WireFormatLite::TYPE_##UPPERCASE, \
  104. extension.is_packed, value, extension.descriptor); \
  105. } else { \
  106. Set##CPP_CAMELCASE(number, WireFormatLite::TYPE_##UPPERCASE, value, \
  107. extension.descriptor); \
  108. } \
  109. } break
  110. HANDLE_SVARINT_TYPE(SINT32, Int32, 32);
  111. HANDLE_SVARINT_TYPE(SINT64, Int64, 64);
  112. #undef HANDLE_SVARINT_TYPE
  113. #define HANDLE_FIXED_TYPE(UPPERCASE, CPP_CAMELCASE, CPPTYPE) \
  114. case WireFormatLite::TYPE_##UPPERCASE: { \
  115. auto value = UnalignedLoad<CPPTYPE>(ptr); \
  116. ptr += sizeof(CPPTYPE); \
  117. if (extension.is_repeated) { \
  118. Add##CPP_CAMELCASE(number, WireFormatLite::TYPE_##UPPERCASE, \
  119. extension.is_packed, value, extension.descriptor); \
  120. } else { \
  121. Set##CPP_CAMELCASE(number, WireFormatLite::TYPE_##UPPERCASE, value, \
  122. extension.descriptor); \
  123. } \
  124. } break
  125. HANDLE_FIXED_TYPE(FIXED32, UInt32, uint32);
  126. HANDLE_FIXED_TYPE(FIXED64, UInt64, uint64);
  127. HANDLE_FIXED_TYPE(SFIXED32, Int32, int32);
  128. HANDLE_FIXED_TYPE(SFIXED64, Int64, int64);
  129. HANDLE_FIXED_TYPE(FLOAT, Float, float);
  130. HANDLE_FIXED_TYPE(DOUBLE, Double, double);
  131. HANDLE_FIXED_TYPE(BOOL, Bool, bool);
  132. #undef HANDLE_FIXED_TYPE
  133. case WireFormatLite::TYPE_ENUM: {
  134. uint64 val;
  135. ptr = VarintParse(ptr, &val);
  136. GOOGLE_PROTOBUF_PARSER_ASSERT(ptr);
  137. int value = val;
  138. if (!extension.enum_validity_check.func(
  139. extension.enum_validity_check.arg, value)) {
  140. WriteVarint(number, val, metadata->mutable_unknown_fields());
  141. } else if (extension.is_repeated) {
  142. AddEnum(number, WireFormatLite::TYPE_ENUM, extension.is_packed, value,
  143. extension.descriptor);
  144. } else {
  145. SetEnum(number, WireFormatLite::TYPE_ENUM, value,
  146. extension.descriptor);
  147. }
  148. break;
  149. }
  150. case WireFormatLite::TYPE_BYTES:
  151. case WireFormatLite::TYPE_STRING: {
  152. std::string* value =
  153. extension.is_repeated
  154. ? AddString(number, WireFormatLite::TYPE_STRING,
  155. extension.descriptor)
  156. : MutableString(number, WireFormatLite::TYPE_STRING,
  157. extension.descriptor);
  158. int size = ReadSize(&ptr);
  159. GOOGLE_PROTOBUF_PARSER_ASSERT(ptr);
  160. return ctx->ReadString(ptr, size, value);
  161. }
  162. case WireFormatLite::TYPE_GROUP: {
  163. MessageLite* value =
  164. extension.is_repeated
  165. ? AddMessage(number, WireFormatLite::TYPE_GROUP,
  166. *extension.message_info.prototype,
  167. extension.descriptor)
  168. : MutableMessage(number, WireFormatLite::TYPE_GROUP,
  169. *extension.message_info.prototype,
  170. extension.descriptor);
  171. uint32 tag = (number << 3) + WireFormatLite::WIRETYPE_START_GROUP;
  172. return ctx->ParseGroup(value, ptr, tag);
  173. }
  174. case WireFormatLite::TYPE_MESSAGE: {
  175. MessageLite* value =
  176. extension.is_repeated
  177. ? AddMessage(number, WireFormatLite::TYPE_MESSAGE,
  178. *extension.message_info.prototype,
  179. extension.descriptor)
  180. : MutableMessage(number, WireFormatLite::TYPE_MESSAGE,
  181. *extension.message_info.prototype,
  182. extension.descriptor);
  183. return ctx->ParseMessage(value, ptr);
  184. }
  185. }
  186. }
  187. return ptr;
  188. }
  189. template <typename Msg, typename Metadata>
  190. const char* ExtensionSet::ParseMessageSetItemTmpl(const char* ptr,
  191. const Msg* containing_type,
  192. Metadata* metadata,
  193. internal::ParseContext* ctx) {
  194. std::string payload;
  195. uint32 type_id = 0;
  196. while (!ctx->Done(&ptr)) {
  197. uint32 tag = static_cast<uint8>(*ptr++);
  198. if (tag == WireFormatLite::kMessageSetTypeIdTag) {
  199. uint64 tmp;
  200. ptr = ParseBigVarint(ptr, &tmp);
  201. GOOGLE_PROTOBUF_PARSER_ASSERT(ptr);
  202. type_id = tmp;
  203. if (!payload.empty()) {
  204. ExtensionInfo extension;
  205. bool was_packed_on_wire;
  206. if (!FindExtension(2, type_id, containing_type, ctx, &extension,
  207. &was_packed_on_wire)) {
  208. WriteLengthDelimited(type_id, payload,
  209. metadata->mutable_unknown_fields());
  210. } else {
  211. MessageLite* value =
  212. extension.is_repeated
  213. ? AddMessage(type_id, WireFormatLite::TYPE_MESSAGE,
  214. *extension.message_info.prototype,
  215. extension.descriptor)
  216. : MutableMessage(type_id, WireFormatLite::TYPE_MESSAGE,
  217. *extension.message_info.prototype,
  218. extension.descriptor);
  219. const char* p;
  220. // We can't use regular parse from string as we have to track
  221. // proper recursion depth and descriptor pools.
  222. ParseContext tmp_ctx(ctx->depth(), false, &p, payload);
  223. tmp_ctx.data().pool = ctx->data().pool;
  224. tmp_ctx.data().factory = ctx->data().factory;
  225. GOOGLE_PROTOBUF_PARSER_ASSERT(value->_InternalParse(p, &tmp_ctx) &&
  226. tmp_ctx.EndedAtLimit());
  227. }
  228. type_id = 0;
  229. }
  230. } else if (tag == WireFormatLite::kMessageSetMessageTag) {
  231. if (type_id != 0) {
  232. ptr = ParseFieldMaybeLazily(static_cast<uint64>(type_id) * 8 + 2, ptr,
  233. containing_type, metadata, ctx);
  234. GOOGLE_PROTOBUF_PARSER_ASSERT(ptr != nullptr);
  235. type_id = 0;
  236. } else {
  237. int32 size = ReadSize(&ptr);
  238. GOOGLE_PROTOBUF_PARSER_ASSERT(ptr);
  239. ptr = ctx->ReadString(ptr, size, &payload);
  240. GOOGLE_PROTOBUF_PARSER_ASSERT(ptr);
  241. }
  242. } else {
  243. ptr = ReadTag(ptr - 1, &tag);
  244. if (tag == 0 || (tag & 7) == 4) {
  245. ctx->SetLastTag(tag);
  246. return ptr;
  247. }
  248. ptr = ParseField(tag, ptr, containing_type, metadata, ctx);
  249. GOOGLE_PROTOBUF_PARSER_ASSERT(ptr);
  250. }
  251. }
  252. return ptr;
  253. }
  254. } // namespace internal
  255. } // namespace protobuf
  256. } // namespace google
  257. #endif // GOOGLE_PROTOBUF_EXTENSION_SET_INL_H__