wire_format_lite_inl.h 41 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996
  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. // wink@google.com (Wink Saville) (refactored from wire_format.h)
  32. // Based on original Protocol Buffers design by
  33. // Sanjay Ghemawat, Jeff Dean, and others.
  34. #ifndef GOOGLE_PROTOBUF_WIRE_FORMAT_LITE_INL_H__
  35. #define GOOGLE_PROTOBUF_WIRE_FORMAT_LITE_INL_H__
  36. #include <algorithm>
  37. #include <string>
  38. #include <google/protobuf/stubs/common.h>
  39. #include <google/protobuf/stubs/logging.h>
  40. #include <google/protobuf/message_lite.h>
  41. #include <google/protobuf/repeated_field.h>
  42. #include <google/protobuf/wire_format_lite.h>
  43. #include <google/protobuf/io/coded_stream.h>
  44. #include <google/protobuf/arenastring.h>
  45. namespace google {
  46. namespace protobuf {
  47. namespace internal {
  48. // Implementation details of ReadPrimitive.
  49. template <>
  50. inline bool WireFormatLite::ReadPrimitive<int32, WireFormatLite::TYPE_INT32>(
  51. io::CodedInputStream* input,
  52. int32* value) {
  53. uint32 temp;
  54. if (!input->ReadVarint32(&temp)) return false;
  55. *value = static_cast<int32>(temp);
  56. return true;
  57. }
  58. template <>
  59. inline bool WireFormatLite::ReadPrimitive<int64, WireFormatLite::TYPE_INT64>(
  60. io::CodedInputStream* input,
  61. int64* value) {
  62. uint64 temp;
  63. if (!input->ReadVarint64(&temp)) return false;
  64. *value = static_cast<int64>(temp);
  65. return true;
  66. }
  67. template <>
  68. inline bool WireFormatLite::ReadPrimitive<uint32, WireFormatLite::TYPE_UINT32>(
  69. io::CodedInputStream* input,
  70. uint32* value) {
  71. return input->ReadVarint32(value);
  72. }
  73. template <>
  74. inline bool WireFormatLite::ReadPrimitive<uint64, WireFormatLite::TYPE_UINT64>(
  75. io::CodedInputStream* input,
  76. uint64* value) {
  77. return input->ReadVarint64(value);
  78. }
  79. template <>
  80. inline bool WireFormatLite::ReadPrimitive<int32, WireFormatLite::TYPE_SINT32>(
  81. io::CodedInputStream* input,
  82. int32* value) {
  83. uint32 temp;
  84. if (!input->ReadVarint32(&temp)) return false;
  85. *value = ZigZagDecode32(temp);
  86. return true;
  87. }
  88. template <>
  89. inline bool WireFormatLite::ReadPrimitive<int64, WireFormatLite::TYPE_SINT64>(
  90. io::CodedInputStream* input,
  91. int64* value) {
  92. uint64 temp;
  93. if (!input->ReadVarint64(&temp)) return false;
  94. *value = ZigZagDecode64(temp);
  95. return true;
  96. }
  97. template <>
  98. inline bool WireFormatLite::ReadPrimitive<uint32, WireFormatLite::TYPE_FIXED32>(
  99. io::CodedInputStream* input,
  100. uint32* value) {
  101. return input->ReadLittleEndian32(value);
  102. }
  103. template <>
  104. inline bool WireFormatLite::ReadPrimitive<uint64, WireFormatLite::TYPE_FIXED64>(
  105. io::CodedInputStream* input,
  106. uint64* value) {
  107. return input->ReadLittleEndian64(value);
  108. }
  109. template <>
  110. inline bool WireFormatLite::ReadPrimitive<int32, WireFormatLite::TYPE_SFIXED32>(
  111. io::CodedInputStream* input,
  112. int32* value) {
  113. uint32 temp;
  114. if (!input->ReadLittleEndian32(&temp)) return false;
  115. *value = static_cast<int32>(temp);
  116. return true;
  117. }
  118. template <>
  119. inline bool WireFormatLite::ReadPrimitive<int64, WireFormatLite::TYPE_SFIXED64>(
  120. io::CodedInputStream* input,
  121. int64* value) {
  122. uint64 temp;
  123. if (!input->ReadLittleEndian64(&temp)) return false;
  124. *value = static_cast<int64>(temp);
  125. return true;
  126. }
  127. template <>
  128. inline bool WireFormatLite::ReadPrimitive<float, WireFormatLite::TYPE_FLOAT>(
  129. io::CodedInputStream* input,
  130. float* value) {
  131. uint32 temp;
  132. if (!input->ReadLittleEndian32(&temp)) return false;
  133. *value = DecodeFloat(temp);
  134. return true;
  135. }
  136. template <>
  137. inline bool WireFormatLite::ReadPrimitive<double, WireFormatLite::TYPE_DOUBLE>(
  138. io::CodedInputStream* input,
  139. double* value) {
  140. uint64 temp;
  141. if (!input->ReadLittleEndian64(&temp)) return false;
  142. *value = DecodeDouble(temp);
  143. return true;
  144. }
  145. template <>
  146. inline bool WireFormatLite::ReadPrimitive<bool, WireFormatLite::TYPE_BOOL>(
  147. io::CodedInputStream* input,
  148. bool* value) {
  149. uint64 temp;
  150. if (!input->ReadVarint64(&temp)) return false;
  151. *value = temp != 0;
  152. return true;
  153. }
  154. template <>
  155. inline bool WireFormatLite::ReadPrimitive<int, WireFormatLite::TYPE_ENUM>(
  156. io::CodedInputStream* input,
  157. int* value) {
  158. uint32 temp;
  159. if (!input->ReadVarint32(&temp)) return false;
  160. *value = static_cast<int>(temp);
  161. return true;
  162. }
  163. template <>
  164. inline const uint8* WireFormatLite::ReadPrimitiveFromArray<
  165. uint32, WireFormatLite::TYPE_FIXED32>(
  166. const uint8* buffer,
  167. uint32* value) {
  168. return io::CodedInputStream::ReadLittleEndian32FromArray(buffer, value);
  169. }
  170. template <>
  171. inline const uint8* WireFormatLite::ReadPrimitiveFromArray<
  172. uint64, WireFormatLite::TYPE_FIXED64>(
  173. const uint8* buffer,
  174. uint64* value) {
  175. return io::CodedInputStream::ReadLittleEndian64FromArray(buffer, value);
  176. }
  177. template <>
  178. inline const uint8* WireFormatLite::ReadPrimitiveFromArray<
  179. int32, WireFormatLite::TYPE_SFIXED32>(
  180. const uint8* buffer,
  181. int32* value) {
  182. uint32 temp;
  183. buffer = io::CodedInputStream::ReadLittleEndian32FromArray(buffer, &temp);
  184. *value = static_cast<int32>(temp);
  185. return buffer;
  186. }
  187. template <>
  188. inline const uint8* WireFormatLite::ReadPrimitiveFromArray<
  189. int64, WireFormatLite::TYPE_SFIXED64>(
  190. const uint8* buffer,
  191. int64* value) {
  192. uint64 temp;
  193. buffer = io::CodedInputStream::ReadLittleEndian64FromArray(buffer, &temp);
  194. *value = static_cast<int64>(temp);
  195. return buffer;
  196. }
  197. template <>
  198. inline const uint8* WireFormatLite::ReadPrimitiveFromArray<
  199. float, WireFormatLite::TYPE_FLOAT>(
  200. const uint8* buffer,
  201. float* value) {
  202. uint32 temp;
  203. buffer = io::CodedInputStream::ReadLittleEndian32FromArray(buffer, &temp);
  204. *value = DecodeFloat(temp);
  205. return buffer;
  206. }
  207. template <>
  208. inline const uint8* WireFormatLite::ReadPrimitiveFromArray<
  209. double, WireFormatLite::TYPE_DOUBLE>(
  210. const uint8* buffer,
  211. double* value) {
  212. uint64 temp;
  213. buffer = io::CodedInputStream::ReadLittleEndian64FromArray(buffer, &temp);
  214. *value = DecodeDouble(temp);
  215. return buffer;
  216. }
  217. template <typename CType, enum WireFormatLite::FieldType DeclaredType>
  218. inline bool WireFormatLite::ReadRepeatedPrimitive(
  219. int, // tag_size, unused.
  220. uint32 tag,
  221. io::CodedInputStream* input,
  222. RepeatedField<CType>* values) {
  223. CType value;
  224. if (!ReadPrimitive<CType, DeclaredType>(input, &value)) return false;
  225. values->Add(value);
  226. int elements_already_reserved = values->Capacity() - values->size();
  227. while (elements_already_reserved > 0 && input->ExpectTag(tag)) {
  228. if (!ReadPrimitive<CType, DeclaredType>(input, &value)) return false;
  229. values->AddAlreadyReserved(value);
  230. elements_already_reserved--;
  231. }
  232. return true;
  233. }
  234. template <typename CType, enum WireFormatLite::FieldType DeclaredType>
  235. inline bool WireFormatLite::ReadRepeatedFixedSizePrimitive(
  236. int tag_size,
  237. uint32 tag,
  238. io::CodedInputStream* input,
  239. RepeatedField<CType>* values) {
  240. GOOGLE_DCHECK_EQ(UInt32Size(tag), static_cast<size_t>(tag_size));
  241. CType value;
  242. if (!ReadPrimitive<CType, DeclaredType>(input, &value))
  243. return false;
  244. values->Add(value);
  245. // For fixed size values, repeated values can be read more quickly by
  246. // reading directly from a raw array.
  247. //
  248. // We can get a tight loop by only reading as many elements as can be
  249. // added to the RepeatedField without having to do any resizing. Additionally,
  250. // we only try to read as many elements as are available from the current
  251. // buffer space. Doing so avoids having to perform boundary checks when
  252. // reading the value: the maximum number of elements that can be read is
  253. // known outside of the loop.
  254. const void* void_pointer;
  255. int size;
  256. input->GetDirectBufferPointerInline(&void_pointer, &size);
  257. if (size > 0) {
  258. const uint8* buffer = reinterpret_cast<const uint8*>(void_pointer);
  259. // The number of bytes each type occupies on the wire.
  260. const int per_value_size = tag_size + static_cast<int>(sizeof(value));
  261. // parentheses around (std::min) prevents macro expansion of min(...)
  262. int elements_available =
  263. (std::min)(values->Capacity() - values->size(), size / per_value_size);
  264. int num_read = 0;
  265. while (num_read < elements_available &&
  266. (buffer = io::CodedInputStream::ExpectTagFromArray(
  267. buffer, tag)) != NULL) {
  268. buffer = ReadPrimitiveFromArray<CType, DeclaredType>(buffer, &value);
  269. values->AddAlreadyReserved(value);
  270. ++num_read;
  271. }
  272. const int read_bytes = num_read * per_value_size;
  273. if (read_bytes > 0) {
  274. input->Skip(read_bytes);
  275. }
  276. }
  277. return true;
  278. }
  279. // Specializations of ReadRepeatedPrimitive for the fixed size types, which use
  280. // the optimized code path.
  281. #define READ_REPEATED_FIXED_SIZE_PRIMITIVE(CPPTYPE, DECLARED_TYPE) \
  282. template <> \
  283. inline bool WireFormatLite::ReadRepeatedPrimitive< \
  284. CPPTYPE, WireFormatLite::DECLARED_TYPE>( \
  285. int tag_size, \
  286. uint32 tag, \
  287. io::CodedInputStream* input, \
  288. RepeatedField<CPPTYPE>* values) { \
  289. return ReadRepeatedFixedSizePrimitive< \
  290. CPPTYPE, WireFormatLite::DECLARED_TYPE>( \
  291. tag_size, tag, input, values); \
  292. }
  293. READ_REPEATED_FIXED_SIZE_PRIMITIVE(uint32, TYPE_FIXED32)
  294. READ_REPEATED_FIXED_SIZE_PRIMITIVE(uint64, TYPE_FIXED64)
  295. READ_REPEATED_FIXED_SIZE_PRIMITIVE(int32, TYPE_SFIXED32)
  296. READ_REPEATED_FIXED_SIZE_PRIMITIVE(int64, TYPE_SFIXED64)
  297. READ_REPEATED_FIXED_SIZE_PRIMITIVE(float, TYPE_FLOAT)
  298. READ_REPEATED_FIXED_SIZE_PRIMITIVE(double, TYPE_DOUBLE)
  299. #undef READ_REPEATED_FIXED_SIZE_PRIMITIVE
  300. template <typename CType, enum WireFormatLite::FieldType DeclaredType>
  301. bool WireFormatLite::ReadRepeatedPrimitiveNoInline(
  302. int tag_size,
  303. uint32 tag,
  304. io::CodedInputStream* input,
  305. RepeatedField<CType>* value) {
  306. return ReadRepeatedPrimitive<CType, DeclaredType>(
  307. tag_size, tag, input, value);
  308. }
  309. template <typename CType, enum WireFormatLite::FieldType DeclaredType>
  310. inline bool WireFormatLite::ReadPackedPrimitive(io::CodedInputStream* input,
  311. RepeatedField<CType>* values) {
  312. int length;
  313. if (!input->ReadVarintSizeAsInt(&length)) return false;
  314. io::CodedInputStream::Limit limit = input->PushLimit(length);
  315. while (input->BytesUntilLimit() > 0) {
  316. CType value;
  317. if (!ReadPrimitive<CType, DeclaredType>(input, &value)) return false;
  318. values->Add(value);
  319. }
  320. input->PopLimit(limit);
  321. return true;
  322. }
  323. template <typename CType, enum WireFormatLite::FieldType DeclaredType>
  324. inline bool WireFormatLite::ReadPackedFixedSizePrimitive(
  325. io::CodedInputStream* input, RepeatedField<CType>* values) {
  326. int length;
  327. if (!input->ReadVarintSizeAsInt(&length)) return false;
  328. const int old_entries = values->size();
  329. const int new_entries = length / static_cast<int>(sizeof(CType));
  330. const int new_bytes = new_entries * static_cast<int>(sizeof(CType));
  331. if (new_bytes != length) return false;
  332. // We would *like* to pre-allocate the buffer to write into (for
  333. // speed), but *must* avoid performing a very large allocation due
  334. // to a malicious user-supplied "length" above. So we have a fast
  335. // path that pre-allocates when the "length" is less than a bound.
  336. // We determine the bound by calling BytesUntilTotalBytesLimit() and
  337. // BytesUntilLimit(). These return -1 to mean "no limit set".
  338. // There are four cases:
  339. // TotalBytesLimit Limit
  340. // -1 -1 Use slow path.
  341. // -1 >= 0 Use fast path if length <= Limit.
  342. // >= 0 -1 Use slow path.
  343. // >= 0 >= 0 Use fast path if length <= min(both limits).
  344. int64 bytes_limit = input->BytesUntilTotalBytesLimit();
  345. if (bytes_limit == -1) {
  346. bytes_limit = input->BytesUntilLimit();
  347. } else {
  348. // parentheses around (std::min) prevents macro expansion of min(...)
  349. bytes_limit =
  350. (std::min)(bytes_limit, static_cast<int64>(input->BytesUntilLimit()));
  351. }
  352. if (bytes_limit >= new_bytes) {
  353. // Fast-path that pre-allocates *values to the final size.
  354. #if defined(PROTOBUF_LITTLE_ENDIAN)
  355. values->Resize(old_entries + new_entries, 0);
  356. // values->mutable_data() may change after Resize(), so do this after:
  357. void* dest = reinterpret_cast<void*>(values->mutable_data() + old_entries);
  358. if (!input->ReadRaw(dest, new_bytes)) {
  359. values->Truncate(old_entries);
  360. return false;
  361. }
  362. #else
  363. values->Reserve(old_entries + new_entries);
  364. CType value;
  365. for (int i = 0; i < new_entries; ++i) {
  366. if (!ReadPrimitive<CType, DeclaredType>(input, &value)) return false;
  367. values->AddAlreadyReserved(value);
  368. }
  369. #endif
  370. } else {
  371. // This is the slow-path case where "length" may be too large to
  372. // safely allocate. We read as much as we can into *values
  373. // without pre-allocating "length" bytes.
  374. CType value;
  375. for (int i = 0; i < new_entries; ++i) {
  376. if (!ReadPrimitive<CType, DeclaredType>(input, &value)) return false;
  377. values->Add(value);
  378. }
  379. }
  380. return true;
  381. }
  382. // Specializations of ReadPackedPrimitive for the fixed size types, which use
  383. // an optimized code path.
  384. #define READ_REPEATED_PACKED_FIXED_SIZE_PRIMITIVE(CPPTYPE, DECLARED_TYPE) \
  385. template <> \
  386. inline bool WireFormatLite::ReadPackedPrimitive< \
  387. CPPTYPE, WireFormatLite::DECLARED_TYPE>( \
  388. io::CodedInputStream* input, \
  389. RepeatedField<CPPTYPE>* values) { \
  390. return ReadPackedFixedSizePrimitive< \
  391. CPPTYPE, WireFormatLite::DECLARED_TYPE>(input, values); \
  392. }
  393. READ_REPEATED_PACKED_FIXED_SIZE_PRIMITIVE(uint32, TYPE_FIXED32)
  394. READ_REPEATED_PACKED_FIXED_SIZE_PRIMITIVE(uint64, TYPE_FIXED64)
  395. READ_REPEATED_PACKED_FIXED_SIZE_PRIMITIVE(int32, TYPE_SFIXED32)
  396. READ_REPEATED_PACKED_FIXED_SIZE_PRIMITIVE(int64, TYPE_SFIXED64)
  397. READ_REPEATED_PACKED_FIXED_SIZE_PRIMITIVE(float, TYPE_FLOAT)
  398. READ_REPEATED_PACKED_FIXED_SIZE_PRIMITIVE(double, TYPE_DOUBLE)
  399. #undef READ_REPEATED_PACKED_FIXED_SIZE_PRIMITIVE
  400. template <typename CType, enum WireFormatLite::FieldType DeclaredType>
  401. bool WireFormatLite::ReadPackedPrimitiveNoInline(io::CodedInputStream* input,
  402. RepeatedField<CType>* values) {
  403. return ReadPackedPrimitive<CType, DeclaredType>(input, values);
  404. }
  405. template<typename MessageType>
  406. inline bool WireFormatLite::ReadGroup(
  407. int field_number, io::CodedInputStream* input,
  408. MessageType* value) {
  409. if (!input->IncrementRecursionDepth()) return false;
  410. if (!value->MergePartialFromCodedStream(input)) return false;
  411. input->UnsafeDecrementRecursionDepth();
  412. // Make sure the last thing read was an end tag for this group.
  413. if (!input->LastTagWas(MakeTag(field_number, WIRETYPE_END_GROUP))) {
  414. return false;
  415. }
  416. return true;
  417. }
  418. template<typename MessageType>
  419. inline bool WireFormatLite::ReadMessage(
  420. io::CodedInputStream* input, MessageType* value) {
  421. int length;
  422. if (!input->ReadVarintSizeAsInt(&length)) return false;
  423. std::pair<io::CodedInputStream::Limit, int> p =
  424. input->IncrementRecursionDepthAndPushLimit(length);
  425. if (p.second < 0 || !value->MergePartialFromCodedStream(input)) return false;
  426. // Make sure that parsing stopped when the limit was hit, not at an endgroup
  427. // tag.
  428. return input->DecrementRecursionDepthAndPopLimit(p.first);
  429. }
  430. // ===================================================================
  431. inline void WireFormatLite::WriteTag(int field_number, WireType type,
  432. io::CodedOutputStream* output) {
  433. output->WriteTag(MakeTag(field_number, type));
  434. }
  435. inline void WireFormatLite::WriteInt32NoTag(int32 value,
  436. io::CodedOutputStream* output) {
  437. output->WriteVarint32SignExtended(value);
  438. }
  439. inline void WireFormatLite::WriteInt64NoTag(int64 value,
  440. io::CodedOutputStream* output) {
  441. output->WriteVarint64(static_cast<uint64>(value));
  442. }
  443. inline void WireFormatLite::WriteUInt32NoTag(uint32 value,
  444. io::CodedOutputStream* output) {
  445. output->WriteVarint32(value);
  446. }
  447. inline void WireFormatLite::WriteUInt64NoTag(uint64 value,
  448. io::CodedOutputStream* output) {
  449. output->WriteVarint64(value);
  450. }
  451. inline void WireFormatLite::WriteSInt32NoTag(int32 value,
  452. io::CodedOutputStream* output) {
  453. output->WriteVarint32(ZigZagEncode32(value));
  454. }
  455. inline void WireFormatLite::WriteSInt64NoTag(int64 value,
  456. io::CodedOutputStream* output) {
  457. output->WriteVarint64(ZigZagEncode64(value));
  458. }
  459. inline void WireFormatLite::WriteFixed32NoTag(uint32 value,
  460. io::CodedOutputStream* output) {
  461. output->WriteLittleEndian32(value);
  462. }
  463. inline void WireFormatLite::WriteFixed64NoTag(uint64 value,
  464. io::CodedOutputStream* output) {
  465. output->WriteLittleEndian64(value);
  466. }
  467. inline void WireFormatLite::WriteSFixed32NoTag(int32 value,
  468. io::CodedOutputStream* output) {
  469. output->WriteLittleEndian32(static_cast<uint32>(value));
  470. }
  471. inline void WireFormatLite::WriteSFixed64NoTag(int64 value,
  472. io::CodedOutputStream* output) {
  473. output->WriteLittleEndian64(static_cast<uint64>(value));
  474. }
  475. inline void WireFormatLite::WriteFloatNoTag(float value,
  476. io::CodedOutputStream* output) {
  477. output->WriteLittleEndian32(EncodeFloat(value));
  478. }
  479. inline void WireFormatLite::WriteDoubleNoTag(double value,
  480. io::CodedOutputStream* output) {
  481. output->WriteLittleEndian64(EncodeDouble(value));
  482. }
  483. inline void WireFormatLite::WriteBoolNoTag(bool value,
  484. io::CodedOutputStream* output) {
  485. output->WriteVarint32(value ? 1 : 0);
  486. }
  487. inline void WireFormatLite::WriteEnumNoTag(int value,
  488. io::CodedOutputStream* output) {
  489. output->WriteVarint32SignExtended(value);
  490. }
  491. // See comment on ReadGroupNoVirtual to understand the need for this template
  492. // parameter name.
  493. template<typename MessageType_WorkAroundCppLookupDefect>
  494. inline void WireFormatLite::WriteGroupNoVirtual(
  495. int field_number, const MessageType_WorkAroundCppLookupDefect& value,
  496. io::CodedOutputStream* output) {
  497. WriteTag(field_number, WIRETYPE_START_GROUP, output);
  498. value.MessageType_WorkAroundCppLookupDefect::SerializeWithCachedSizes(output);
  499. WriteTag(field_number, WIRETYPE_END_GROUP, output);
  500. }
  501. template<typename MessageType_WorkAroundCppLookupDefect>
  502. inline void WireFormatLite::WriteMessageNoVirtual(
  503. int field_number, const MessageType_WorkAroundCppLookupDefect& value,
  504. io::CodedOutputStream* output) {
  505. WriteTag(field_number, WIRETYPE_LENGTH_DELIMITED, output);
  506. output->WriteVarint32(
  507. value.MessageType_WorkAroundCppLookupDefect::GetCachedSize());
  508. value.MessageType_WorkAroundCppLookupDefect::SerializeWithCachedSizes(output);
  509. }
  510. // ===================================================================
  511. inline uint8* WireFormatLite::WriteTagToArray(int field_number,
  512. WireType type,
  513. uint8* target) {
  514. return io::CodedOutputStream::WriteTagToArray(MakeTag(field_number, type),
  515. target);
  516. }
  517. inline uint8* WireFormatLite::WriteInt32NoTagToArray(int32 value,
  518. uint8* target) {
  519. return io::CodedOutputStream::WriteVarint32SignExtendedToArray(value, target);
  520. }
  521. inline uint8* WireFormatLite::WriteInt64NoTagToArray(int64 value,
  522. uint8* target) {
  523. return io::CodedOutputStream::WriteVarint64ToArray(
  524. static_cast<uint64>(value), target);
  525. }
  526. inline uint8* WireFormatLite::WriteUInt32NoTagToArray(uint32 value,
  527. uint8* target) {
  528. return io::CodedOutputStream::WriteVarint32ToArray(value, target);
  529. }
  530. inline uint8* WireFormatLite::WriteUInt64NoTagToArray(uint64 value,
  531. uint8* target) {
  532. return io::CodedOutputStream::WriteVarint64ToArray(value, target);
  533. }
  534. inline uint8* WireFormatLite::WriteSInt32NoTagToArray(int32 value,
  535. uint8* target) {
  536. return io::CodedOutputStream::WriteVarint32ToArray(ZigZagEncode32(value),
  537. target);
  538. }
  539. inline uint8* WireFormatLite::WriteSInt64NoTagToArray(int64 value,
  540. uint8* target) {
  541. return io::CodedOutputStream::WriteVarint64ToArray(ZigZagEncode64(value),
  542. target);
  543. }
  544. inline uint8* WireFormatLite::WriteFixed32NoTagToArray(uint32 value,
  545. uint8* target) {
  546. return io::CodedOutputStream::WriteLittleEndian32ToArray(value, target);
  547. }
  548. inline uint8* WireFormatLite::WriteFixed64NoTagToArray(uint64 value,
  549. uint8* target) {
  550. return io::CodedOutputStream::WriteLittleEndian64ToArray(value, target);
  551. }
  552. inline uint8* WireFormatLite::WriteSFixed32NoTagToArray(int32 value,
  553. uint8* target) {
  554. return io::CodedOutputStream::WriteLittleEndian32ToArray(
  555. static_cast<uint32>(value), target);
  556. }
  557. inline uint8* WireFormatLite::WriteSFixed64NoTagToArray(int64 value,
  558. uint8* target) {
  559. return io::CodedOutputStream::WriteLittleEndian64ToArray(
  560. static_cast<uint64>(value), target);
  561. }
  562. inline uint8* WireFormatLite::WriteFloatNoTagToArray(float value,
  563. uint8* target) {
  564. return io::CodedOutputStream::WriteLittleEndian32ToArray(EncodeFloat(value),
  565. target);
  566. }
  567. inline uint8* WireFormatLite::WriteDoubleNoTagToArray(double value,
  568. uint8* target) {
  569. return io::CodedOutputStream::WriteLittleEndian64ToArray(EncodeDouble(value),
  570. target);
  571. }
  572. inline uint8* WireFormatLite::WriteBoolNoTagToArray(bool value,
  573. uint8* target) {
  574. return io::CodedOutputStream::WriteVarint32ToArray(value ? 1 : 0, target);
  575. }
  576. inline uint8* WireFormatLite::WriteEnumNoTagToArray(int value,
  577. uint8* target) {
  578. return io::CodedOutputStream::WriteVarint32SignExtendedToArray(value, target);
  579. }
  580. template<typename T>
  581. inline uint8* WireFormatLite::WritePrimitiveNoTagToArray(
  582. const RepeatedField<T>& value,
  583. uint8* (*Writer)(T, uint8*), uint8* target) {
  584. const int n = value.size();
  585. GOOGLE_DCHECK_GT(n, 0);
  586. const T* ii = value.unsafe_data();
  587. int i = 0;
  588. do {
  589. target = Writer(ii[i], target);
  590. } while (++i < n);
  591. return target;
  592. }
  593. template<typename T>
  594. inline uint8* WireFormatLite::WriteFixedNoTagToArray(
  595. const RepeatedField<T>& value,
  596. uint8* (*Writer)(T, uint8*), uint8* target) {
  597. #if defined(PROTOBUF_LITTLE_ENDIAN)
  598. (void) Writer;
  599. const int n = value.size();
  600. GOOGLE_DCHECK_GT(n, 0);
  601. const T* ii = value.unsafe_data();
  602. const int bytes = n * static_cast<int>(sizeof(ii[0]));
  603. memcpy(target, ii, static_cast<size_t>(bytes));
  604. return target + bytes;
  605. #else
  606. return WritePrimitiveNoTagToArray(value, Writer, target);
  607. #endif
  608. }
  609. inline uint8* WireFormatLite::WriteInt32NoTagToArray(
  610. const RepeatedField< int32>& value, uint8* target) {
  611. return WritePrimitiveNoTagToArray(value, WriteInt32NoTagToArray, target);
  612. }
  613. inline uint8* WireFormatLite::WriteInt64NoTagToArray(
  614. const RepeatedField< int64>& value, uint8* target) {
  615. return WritePrimitiveNoTagToArray(value, WriteInt64NoTagToArray, target);
  616. }
  617. inline uint8* WireFormatLite::WriteUInt32NoTagToArray(
  618. const RepeatedField<uint32>& value, uint8* target) {
  619. return WritePrimitiveNoTagToArray(value, WriteUInt32NoTagToArray, target);
  620. }
  621. inline uint8* WireFormatLite::WriteUInt64NoTagToArray(
  622. const RepeatedField<uint64>& value, uint8* target) {
  623. return WritePrimitiveNoTagToArray(value, WriteUInt64NoTagToArray, target);
  624. }
  625. inline uint8* WireFormatLite::WriteSInt32NoTagToArray(
  626. const RepeatedField< int32>& value, uint8* target) {
  627. return WritePrimitiveNoTagToArray(value, WriteSInt32NoTagToArray, target);
  628. }
  629. inline uint8* WireFormatLite::WriteSInt64NoTagToArray(
  630. const RepeatedField< int64>& value, uint8* target) {
  631. return WritePrimitiveNoTagToArray(value, WriteSInt64NoTagToArray, target);
  632. }
  633. inline uint8* WireFormatLite::WriteFixed32NoTagToArray(
  634. const RepeatedField<uint32>& value, uint8* target) {
  635. return WriteFixedNoTagToArray(value, WriteFixed32NoTagToArray, target);
  636. }
  637. inline uint8* WireFormatLite::WriteFixed64NoTagToArray(
  638. const RepeatedField<uint64>& value, uint8* target) {
  639. return WriteFixedNoTagToArray(value, WriteFixed64NoTagToArray, target);
  640. }
  641. inline uint8* WireFormatLite::WriteSFixed32NoTagToArray(
  642. const RepeatedField< int32>& value, uint8* target) {
  643. return WriteFixedNoTagToArray(value, WriteSFixed32NoTagToArray, target);
  644. }
  645. inline uint8* WireFormatLite::WriteSFixed64NoTagToArray(
  646. const RepeatedField< int64>& value, uint8* target) {
  647. return WriteFixedNoTagToArray(value, WriteSFixed64NoTagToArray, target);
  648. }
  649. inline uint8* WireFormatLite::WriteFloatNoTagToArray(
  650. const RepeatedField< float>& value, uint8* target) {
  651. return WriteFixedNoTagToArray(value, WriteFloatNoTagToArray, target);
  652. }
  653. inline uint8* WireFormatLite::WriteDoubleNoTagToArray(
  654. const RepeatedField<double>& value, uint8* target) {
  655. return WriteFixedNoTagToArray(value, WriteDoubleNoTagToArray, target);
  656. }
  657. inline uint8* WireFormatLite::WriteBoolNoTagToArray(
  658. const RepeatedField< bool>& value, uint8* target) {
  659. return WritePrimitiveNoTagToArray(value, WriteBoolNoTagToArray, target);
  660. }
  661. inline uint8* WireFormatLite::WriteEnumNoTagToArray(
  662. const RepeatedField< int>& value, uint8* target) {
  663. return WritePrimitiveNoTagToArray(value, WriteEnumNoTagToArray, target);
  664. }
  665. inline uint8* WireFormatLite::WriteInt32ToArray(int field_number,
  666. int32 value,
  667. uint8* target) {
  668. target = WriteTagToArray(field_number, WIRETYPE_VARINT, target);
  669. return WriteInt32NoTagToArray(value, target);
  670. }
  671. inline uint8* WireFormatLite::WriteInt64ToArray(int field_number,
  672. int64 value,
  673. uint8* target) {
  674. target = WriteTagToArray(field_number, WIRETYPE_VARINT, target);
  675. return WriteInt64NoTagToArray(value, target);
  676. }
  677. inline uint8* WireFormatLite::WriteUInt32ToArray(int field_number,
  678. uint32 value,
  679. uint8* target) {
  680. target = WriteTagToArray(field_number, WIRETYPE_VARINT, target);
  681. return WriteUInt32NoTagToArray(value, target);
  682. }
  683. inline uint8* WireFormatLite::WriteUInt64ToArray(int field_number,
  684. uint64 value,
  685. uint8* target) {
  686. target = WriteTagToArray(field_number, WIRETYPE_VARINT, target);
  687. return WriteUInt64NoTagToArray(value, target);
  688. }
  689. inline uint8* WireFormatLite::WriteSInt32ToArray(int field_number,
  690. int32 value,
  691. uint8* target) {
  692. target = WriteTagToArray(field_number, WIRETYPE_VARINT, target);
  693. return WriteSInt32NoTagToArray(value, target);
  694. }
  695. inline uint8* WireFormatLite::WriteSInt64ToArray(int field_number,
  696. int64 value,
  697. uint8* target) {
  698. target = WriteTagToArray(field_number, WIRETYPE_VARINT, target);
  699. return WriteSInt64NoTagToArray(value, target);
  700. }
  701. inline uint8* WireFormatLite::WriteFixed32ToArray(int field_number,
  702. uint32 value,
  703. uint8* target) {
  704. target = WriteTagToArray(field_number, WIRETYPE_FIXED32, target);
  705. return WriteFixed32NoTagToArray(value, target);
  706. }
  707. inline uint8* WireFormatLite::WriteFixed64ToArray(int field_number,
  708. uint64 value,
  709. uint8* target) {
  710. target = WriteTagToArray(field_number, WIRETYPE_FIXED64, target);
  711. return WriteFixed64NoTagToArray(value, target);
  712. }
  713. inline uint8* WireFormatLite::WriteSFixed32ToArray(int field_number,
  714. int32 value,
  715. uint8* target) {
  716. target = WriteTagToArray(field_number, WIRETYPE_FIXED32, target);
  717. return WriteSFixed32NoTagToArray(value, target);
  718. }
  719. inline uint8* WireFormatLite::WriteSFixed64ToArray(int field_number,
  720. int64 value,
  721. uint8* target) {
  722. target = WriteTagToArray(field_number, WIRETYPE_FIXED64, target);
  723. return WriteSFixed64NoTagToArray(value, target);
  724. }
  725. inline uint8* WireFormatLite::WriteFloatToArray(int field_number,
  726. float value,
  727. uint8* target) {
  728. target = WriteTagToArray(field_number, WIRETYPE_FIXED32, target);
  729. return WriteFloatNoTagToArray(value, target);
  730. }
  731. inline uint8* WireFormatLite::WriteDoubleToArray(int field_number,
  732. double value,
  733. uint8* target) {
  734. target = WriteTagToArray(field_number, WIRETYPE_FIXED64, target);
  735. return WriteDoubleNoTagToArray(value, target);
  736. }
  737. inline uint8* WireFormatLite::WriteBoolToArray(int field_number,
  738. bool value,
  739. uint8* target) {
  740. target = WriteTagToArray(field_number, WIRETYPE_VARINT, target);
  741. return WriteBoolNoTagToArray(value, target);
  742. }
  743. inline uint8* WireFormatLite::WriteEnumToArray(int field_number,
  744. int value,
  745. uint8* target) {
  746. target = WriteTagToArray(field_number, WIRETYPE_VARINT, target);
  747. return WriteEnumNoTagToArray(value, target);
  748. }
  749. template<typename T>
  750. inline uint8* WireFormatLite::WritePrimitiveToArray(
  751. int field_number,
  752. const RepeatedField<T>& value,
  753. uint8* (*Writer)(int, T, uint8*), uint8* target) {
  754. const int n = value.size();
  755. if (n == 0) {
  756. return target;
  757. }
  758. const T* ii = value.unsafe_data();
  759. int i = 0;
  760. do {
  761. target = Writer(field_number, ii[i], target);
  762. } while (++i < n);
  763. return target;
  764. }
  765. inline uint8* WireFormatLite::WriteInt32ToArray(
  766. int field_number, const RepeatedField< int32>& value, uint8* target) {
  767. return WritePrimitiveToArray(field_number, value, WriteInt32ToArray, target);
  768. }
  769. inline uint8* WireFormatLite::WriteInt64ToArray(
  770. int field_number, const RepeatedField< int64>& value, uint8* target) {
  771. return WritePrimitiveToArray(field_number, value, WriteInt64ToArray, target);
  772. }
  773. inline uint8* WireFormatLite::WriteUInt32ToArray(
  774. int field_number, const RepeatedField<uint32>& value, uint8* target) {
  775. return WritePrimitiveToArray(field_number, value, WriteUInt32ToArray, target);
  776. }
  777. inline uint8* WireFormatLite::WriteUInt64ToArray(
  778. int field_number, const RepeatedField<uint64>& value, uint8* target) {
  779. return WritePrimitiveToArray(field_number, value, WriteUInt64ToArray, target);
  780. }
  781. inline uint8* WireFormatLite::WriteSInt32ToArray(
  782. int field_number, const RepeatedField< int32>& value, uint8* target) {
  783. return WritePrimitiveToArray(field_number, value, WriteSInt32ToArray, target);
  784. }
  785. inline uint8* WireFormatLite::WriteSInt64ToArray(
  786. int field_number, const RepeatedField< int64>& value, uint8* target) {
  787. return WritePrimitiveToArray(field_number, value, WriteSInt64ToArray, target);
  788. }
  789. inline uint8* WireFormatLite::WriteFixed32ToArray(
  790. int field_number, const RepeatedField<uint32>& value, uint8* target) {
  791. return WritePrimitiveToArray(
  792. field_number, value, WriteFixed32ToArray, target);
  793. }
  794. inline uint8* WireFormatLite::WriteFixed64ToArray(
  795. int field_number, const RepeatedField<uint64>& value, uint8* target) {
  796. return WritePrimitiveToArray(
  797. field_number, value, WriteFixed64ToArray, target);
  798. }
  799. inline uint8* WireFormatLite::WriteSFixed32ToArray(
  800. int field_number, const RepeatedField< int32>& value, uint8* target) {
  801. return WritePrimitiveToArray(
  802. field_number, value, WriteSFixed32ToArray, target);
  803. }
  804. inline uint8* WireFormatLite::WriteSFixed64ToArray(
  805. int field_number, const RepeatedField< int64>& value, uint8* target) {
  806. return WritePrimitiveToArray(
  807. field_number, value, WriteSFixed64ToArray, target);
  808. }
  809. inline uint8* WireFormatLite::WriteFloatToArray(
  810. int field_number, const RepeatedField< float>& value, uint8* target) {
  811. return WritePrimitiveToArray(field_number, value, WriteFloatToArray, target);
  812. }
  813. inline uint8* WireFormatLite::WriteDoubleToArray(
  814. int field_number, const RepeatedField<double>& value, uint8* target) {
  815. return WritePrimitiveToArray(field_number, value, WriteDoubleToArray, target);
  816. }
  817. inline uint8* WireFormatLite::WriteBoolToArray(
  818. int field_number, const RepeatedField< bool>& value, uint8* target) {
  819. return WritePrimitiveToArray(field_number, value, WriteBoolToArray, target);
  820. }
  821. inline uint8* WireFormatLite::WriteEnumToArray(
  822. int field_number, const RepeatedField< int>& value, uint8* target) {
  823. return WritePrimitiveToArray(field_number, value, WriteEnumToArray, target);
  824. }
  825. inline uint8* WireFormatLite::WriteStringToArray(int field_number,
  826. const string& value,
  827. uint8* target) {
  828. // String is for UTF-8 text only
  829. // WARNING: In wire_format.cc, both strings and bytes are handled by
  830. // WriteString() to avoid code duplication. If the implementations become
  831. // different, you will need to update that usage.
  832. target = WriteTagToArray(field_number, WIRETYPE_LENGTH_DELIMITED, target);
  833. return io::CodedOutputStream::WriteStringWithSizeToArray(value, target);
  834. }
  835. inline uint8* WireFormatLite::WriteBytesToArray(int field_number,
  836. const string& value,
  837. uint8* target) {
  838. target = WriteTagToArray(field_number, WIRETYPE_LENGTH_DELIMITED, target);
  839. return io::CodedOutputStream::WriteStringWithSizeToArray(value, target);
  840. }
  841. template<typename MessageType>
  842. inline uint8* WireFormatLite::InternalWriteGroupToArray(
  843. int field_number, const MessageType& value, bool deterministic,
  844. uint8* target) {
  845. target = WriteTagToArray(field_number, WIRETYPE_START_GROUP, target);
  846. target = value.InternalSerializeWithCachedSizesToArray(deterministic, target);
  847. return WriteTagToArray(field_number, WIRETYPE_END_GROUP, target);
  848. }
  849. template<typename MessageType>
  850. inline uint8* WireFormatLite::InternalWriteMessageToArray(
  851. int field_number, const MessageType& value, bool deterministic,
  852. uint8* target) {
  853. target = WriteTagToArray(field_number, WIRETYPE_LENGTH_DELIMITED, target);
  854. target = io::CodedOutputStream::WriteVarint32ToArray(
  855. static_cast<uint32>(value.GetCachedSize()), target);
  856. return value.InternalSerializeWithCachedSizesToArray(deterministic, target);
  857. }
  858. // See comment on ReadGroupNoVirtual to understand the need for this template
  859. // parameter name.
  860. template<typename MessageType_WorkAroundCppLookupDefect>
  861. inline uint8* WireFormatLite::InternalWriteGroupNoVirtualToArray(
  862. int field_number, const MessageType_WorkAroundCppLookupDefect& value,
  863. bool deterministic, uint8* target) {
  864. target = WriteTagToArray(field_number, WIRETYPE_START_GROUP, target);
  865. target = value.MessageType_WorkAroundCppLookupDefect::
  866. InternalSerializeWithCachedSizesToArray(deterministic, target);
  867. return WriteTagToArray(field_number, WIRETYPE_END_GROUP, target);
  868. }
  869. template<typename MessageType_WorkAroundCppLookupDefect>
  870. inline uint8* WireFormatLite::InternalWriteMessageNoVirtualToArray(
  871. int field_number, const MessageType_WorkAroundCppLookupDefect& value,
  872. bool deterministic, uint8* target) {
  873. target = WriteTagToArray(field_number, WIRETYPE_LENGTH_DELIMITED, target);
  874. target = io::CodedOutputStream::WriteVarint32ToArray(
  875. static_cast<uint32>(
  876. value.MessageType_WorkAroundCppLookupDefect::GetCachedSize()),
  877. target);
  878. return value.MessageType_WorkAroundCppLookupDefect::
  879. InternalSerializeWithCachedSizesToArray(deterministic, target);
  880. }
  881. // ===================================================================
  882. inline size_t WireFormatLite::Int32Size(int32 value) {
  883. return io::CodedOutputStream::VarintSize32SignExtended(value);
  884. }
  885. inline size_t WireFormatLite::Int64Size(int64 value) {
  886. return io::CodedOutputStream::VarintSize64(static_cast<uint64>(value));
  887. }
  888. inline size_t WireFormatLite::UInt32Size(uint32 value) {
  889. return io::CodedOutputStream::VarintSize32(value);
  890. }
  891. inline size_t WireFormatLite::UInt64Size(uint64 value) {
  892. return io::CodedOutputStream::VarintSize64(value);
  893. }
  894. inline size_t WireFormatLite::SInt32Size(int32 value) {
  895. return io::CodedOutputStream::VarintSize32(ZigZagEncode32(value));
  896. }
  897. inline size_t WireFormatLite::SInt64Size(int64 value) {
  898. return io::CodedOutputStream::VarintSize64(ZigZagEncode64(value));
  899. }
  900. inline size_t WireFormatLite::EnumSize(int value) {
  901. return io::CodedOutputStream::VarintSize32SignExtended(value);
  902. }
  903. inline size_t WireFormatLite::StringSize(const string& value) {
  904. return LengthDelimitedSize(value.size());
  905. }
  906. inline size_t WireFormatLite::BytesSize(const string& value) {
  907. return LengthDelimitedSize(value.size());
  908. }
  909. template<typename MessageType>
  910. inline size_t WireFormatLite::GroupSize(const MessageType& value) {
  911. return value.ByteSizeLong();
  912. }
  913. template<typename MessageType>
  914. inline size_t WireFormatLite::MessageSize(const MessageType& value) {
  915. return LengthDelimitedSize(value.ByteSizeLong());
  916. }
  917. // See comment on ReadGroupNoVirtual to understand the need for this template
  918. // parameter name.
  919. template<typename MessageType_WorkAroundCppLookupDefect>
  920. inline size_t WireFormatLite::GroupSizeNoVirtual(
  921. const MessageType_WorkAroundCppLookupDefect& value) {
  922. return value.MessageType_WorkAroundCppLookupDefect::ByteSizeLong();
  923. }
  924. template<typename MessageType_WorkAroundCppLookupDefect>
  925. inline size_t WireFormatLite::MessageSizeNoVirtual(
  926. const MessageType_WorkAroundCppLookupDefect& value) {
  927. return LengthDelimitedSize(
  928. value.MessageType_WorkAroundCppLookupDefect::ByteSizeLong());
  929. }
  930. inline size_t WireFormatLite::LengthDelimitedSize(size_t length) {
  931. // The static_cast here prevents an error in certain compiler configurations
  932. // but is not technically correct--if length is too large to fit in a uint32
  933. // then it will be silently truncated. We will need to fix this if we ever
  934. // decide to start supporting serialized messages greater than 2 GiB in size.
  935. return length + io::CodedOutputStream::VarintSize32(
  936. static_cast<uint32>(length));
  937. }
  938. } // namespace internal
  939. } // namespace protobuf
  940. } // namespace google
  941. #endif // GOOGLE_PROTOBUF_WIRE_FORMAT_LITE_INL_H__