TrinityCore
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
wire_format_lite_inl.h
Go to the documentation of this file.
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 
31 // Author: [email protected] (Kenton Varda)
32 // [email protected] (Wink Saville) (refactored from wire_format.h)
33 // Based on original Protocol Buffers design by
34 // Sanjay Ghemawat, Jeff Dean, and others.
35 
36 #ifndef GOOGLE_PROTOBUF_WIRE_FORMAT_LITE_INL_H__
37 #define GOOGLE_PROTOBUF_WIRE_FORMAT_LITE_INL_H__
38 
39 #ifdef _MSC_VER
40 // This is required for min/max on VS2013 only.
41 #include <algorithm>
42 #endif
43 
44 #include <string>
50 
51 
52 namespace google {
53 namespace protobuf {
54 namespace internal {
55 
56 // Implementation details of ReadPrimitive.
57 
58 template <>
59 inline bool WireFormatLite::ReadPrimitive<int32, WireFormatLite::TYPE_INT32>(
61  int32* value) {
62  uint32 temp;
63  if (!input->ReadVarint32(&temp)) return false;
64  *value = static_cast<int32>(temp);
65  return true;
66 }
67 template <>
68 inline bool WireFormatLite::ReadPrimitive<int64, WireFormatLite::TYPE_INT64>(
70  int64* value) {
71  uint64 temp;
72  if (!input->ReadVarint64(&temp)) return false;
73  *value = static_cast<int64>(temp);
74  return true;
75 }
76 template <>
77 inline bool WireFormatLite::ReadPrimitive<uint32, WireFormatLite::TYPE_UINT32>(
79  uint32* value) {
80  return input->ReadVarint32(value);
81 }
82 template <>
83 inline bool WireFormatLite::ReadPrimitive<uint64, WireFormatLite::TYPE_UINT64>(
85  uint64* value) {
86  return input->ReadVarint64(value);
87 }
88 template <>
89 inline bool WireFormatLite::ReadPrimitive<int32, WireFormatLite::TYPE_SINT32>(
91  int32* value) {
92  uint32 temp;
93  if (!input->ReadVarint32(&temp)) return false;
94  *value = ZigZagDecode32(temp);
95  return true;
96 }
97 template <>
98 inline bool WireFormatLite::ReadPrimitive<int64, WireFormatLite::TYPE_SINT64>(
100  int64* value) {
101  uint64 temp;
102  if (!input->ReadVarint64(&temp)) return false;
103  *value = ZigZagDecode64(temp);
104  return true;
105 }
106 template <>
107 inline bool WireFormatLite::ReadPrimitive<uint32, WireFormatLite::TYPE_FIXED32>(
109  uint32* value) {
110  return input->ReadLittleEndian32(value);
111 }
112 template <>
113 inline bool WireFormatLite::ReadPrimitive<uint64, WireFormatLite::TYPE_FIXED64>(
115  uint64* value) {
116  return input->ReadLittleEndian64(value);
117 }
118 template <>
119 inline bool WireFormatLite::ReadPrimitive<int32, WireFormatLite::TYPE_SFIXED32>(
121  int32* value) {
122  uint32 temp;
123  if (!input->ReadLittleEndian32(&temp)) return false;
124  *value = static_cast<int32>(temp);
125  return true;
126 }
127 template <>
128 inline bool WireFormatLite::ReadPrimitive<int64, WireFormatLite::TYPE_SFIXED64>(
130  int64* value) {
131  uint64 temp;
132  if (!input->ReadLittleEndian64(&temp)) return false;
133  *value = static_cast<int64>(temp);
134  return true;
135 }
136 template <>
137 inline bool WireFormatLite::ReadPrimitive<float, WireFormatLite::TYPE_FLOAT>(
139  float* value) {
140  uint32 temp;
141  if (!input->ReadLittleEndian32(&temp)) return false;
142  *value = DecodeFloat(temp);
143  return true;
144 }
145 template <>
146 inline bool WireFormatLite::ReadPrimitive<double, WireFormatLite::TYPE_DOUBLE>(
148  double* value) {
149  uint64 temp;
150  if (!input->ReadLittleEndian64(&temp)) return false;
151  *value = DecodeDouble(temp);
152  return true;
153 }
154 template <>
155 inline bool WireFormatLite::ReadPrimitive<bool, WireFormatLite::TYPE_BOOL>(
157  bool* value) {
158  uint64 temp;
159  if (!input->ReadVarint64(&temp)) return false;
160  *value = temp != 0;
161  return true;
162 }
163 template <>
164 inline bool WireFormatLite::ReadPrimitive<int, WireFormatLite::TYPE_ENUM>(
166  int* value) {
167  uint32 temp;
168  if (!input->ReadVarint32(&temp)) return false;
169  *value = static_cast<int>(temp);
170  return true;
171 }
172 
173 template <>
176  const uint8* buffer,
177  uint32* value) {
179 }
180 template <>
183  const uint8* buffer,
184  uint64* value) {
186 }
187 template <>
190  const uint8* buffer,
191  int32* value) {
192  uint32 temp;
194  *value = static_cast<int32>(temp);
195  return buffer;
196 }
197 template <>
200  const uint8* buffer,
201  int64* value) {
202  uint64 temp;
204  *value = static_cast<int64>(temp);
205  return buffer;
206 }
207 template <>
210  const uint8* buffer,
211  float* value) {
212  uint32 temp;
214  *value = DecodeFloat(temp);
215  return buffer;
216 }
217 template <>
220  const uint8* buffer,
221  double* value) {
222  uint64 temp;
224  *value = DecodeDouble(temp);
225  return buffer;
226 }
227 
228 template <typename CType, enum WireFormatLite::FieldType DeclaredType>
230  int, // tag_size, unused.
231  uint32 tag,
232  io::CodedInputStream* input,
233  RepeatedField<CType>* values) {
234  CType value;
235  if (!ReadPrimitive<CType, DeclaredType>(input, &value)) return false;
236  values->Add(value);
237  int elements_already_reserved = values->Capacity() - values->size();
238  while (elements_already_reserved > 0 && input->ExpectTag(tag)) {
239  if (!ReadPrimitive<CType, DeclaredType>(input, &value)) return false;
240  values->AddAlreadyReserved(value);
241  elements_already_reserved--;
242  }
243  return true;
244 }
245 
246 template <typename CType, enum WireFormatLite::FieldType DeclaredType>
248  int tag_size,
249  uint32 tag,
250  io::CodedInputStream* input,
251  RepeatedField<CType>* values) {
252  GOOGLE_DCHECK_EQ(UInt32Size(tag), tag_size);
253  CType value;
254  if (!ReadPrimitive<CType, DeclaredType>(input, &value))
255  return false;
256  values->Add(value);
257 
258  // For fixed size values, repeated values can be read more quickly by
259  // reading directly from a raw array.
260  //
261  // We can get a tight loop by only reading as many elements as can be
262  // added to the RepeatedField without having to do any resizing. Additionally,
263  // we only try to read as many elements as are available from the current
264  // buffer space. Doing so avoids having to perform boundary checks when
265  // reading the value: the maximum number of elements that can be read is
266  // known outside of the loop.
267  const void* void_pointer;
268  int size;
269  input->GetDirectBufferPointerInline(&void_pointer, &size);
270  if (size > 0) {
271  const uint8* buffer = reinterpret_cast<const uint8*>(void_pointer);
272  // The number of bytes each type occupies on the wire.
273  const int per_value_size = tag_size + sizeof(value);
274 
275  int elements_available = min(values->Capacity() - values->size(),
276  size / per_value_size);
277  int num_read = 0;
278  while (num_read < elements_available &&
280  buffer, tag)) != NULL) {
281  buffer = ReadPrimitiveFromArray<CType, DeclaredType>(buffer, &value);
282  values->AddAlreadyReserved(value);
283  ++num_read;
284  }
285  const int read_bytes = num_read * per_value_size;
286  if (read_bytes > 0) {
287  input->Skip(read_bytes);
288  }
289  }
290  return true;
291 }
292 
293 // Specializations of ReadRepeatedPrimitive for the fixed size types, which use
294 // the optimized code path.
295 #define READ_REPEATED_FIXED_SIZE_PRIMITIVE(CPPTYPE, DECLARED_TYPE) \
296 template <> \
297 inline bool WireFormatLite::ReadRepeatedPrimitive< \
298  CPPTYPE, WireFormatLite::DECLARED_TYPE>( \
299  int tag_size, \
300  uint32 tag, \
301  io::CodedInputStream* input, \
302  RepeatedField<CPPTYPE>* values) { \
303  return ReadRepeatedFixedSizePrimitive< \
304  CPPTYPE, WireFormatLite::DECLARED_TYPE>( \
305  tag_size, tag, input, values); \
306 }
307 
314 
315 #undef READ_REPEATED_FIXED_SIZE_PRIMITIVE
316 
317 template <typename CType, enum WireFormatLite::FieldType DeclaredType>
319  int tag_size,
320  uint32 tag,
321  io::CodedInputStream* input,
323  return ReadRepeatedPrimitive<CType, DeclaredType>(
324  tag_size, tag, input, value);
325 }
326 
327 template <typename CType, enum WireFormatLite::FieldType DeclaredType>
329  RepeatedField<CType>* values) {
330  uint32 length;
331  if (!input->ReadVarint32(&length)) return false;
332  io::CodedInputStream::Limit limit = input->PushLimit(length);
333  while (input->BytesUntilLimit() > 0) {
334  CType value;
335  if (!ReadPrimitive<CType, DeclaredType>(input, &value)) return false;
336  values->Add(value);
337  }
338  input->PopLimit(limit);
339  return true;
340 }
341 
342 template <typename CType, enum WireFormatLite::FieldType DeclaredType>
344  io::CodedInputStream* input, RepeatedField<CType>* values) {
345  uint32 length;
346  if (!input->ReadVarint32(&length)) return false;
347  const uint32 old_entries = values->size();
348  const uint32 new_entries = length / sizeof(CType);
349  const uint32 new_bytes = new_entries * sizeof(CType);
350  if (new_bytes != length) return false;
351  // We would *like* to pre-allocate the buffer to write into (for
352  // speed), but *must* avoid performing a very large allocation due
353  // to a malicious user-supplied "length" above. So we have a fast
354  // path that pre-allocates when the "length" is less than a bound.
355  // We determine the bound by calling BytesUntilTotalBytesLimit() and
356  // BytesUntilLimit(). These return -1 to mean "no limit set".
357  // There are four cases:
358  // TotalBytesLimit Limit
359  // -1 -1 Use slow path.
360  // -1 >= 0 Use fast path if length <= Limit.
361  // >= 0 -1 Use slow path.
362  // >= 0 >= 0 Use fast path if length <= min(both limits).
363  int64 bytes_limit = input->BytesUntilTotalBytesLimit();
364  if (bytes_limit == -1) {
365  bytes_limit = input->BytesUntilLimit();
366  } else {
367  bytes_limit =
368  min(bytes_limit, static_cast<int64>(input->BytesUntilLimit()));
369  }
370  if (bytes_limit >= new_bytes) {
371  // Fast-path that pre-allocates *values to the final size.
372 #if defined(PROTOBUF_LITTLE_ENDIAN)
373  values->Resize(old_entries + new_entries, 0);
374  // values->mutable_data() may change after Resize(), so do this after:
375  void* dest = reinterpret_cast<void*>(values->mutable_data() + old_entries);
376  if (!input->ReadRaw(dest, new_bytes)) {
377  values->Truncate(old_entries);
378  return false;
379  }
380 #else
381  values->Reserve(old_entries + new_entries);
382  CType value;
383  for (int i = 0; i < new_entries; ++i) {
384  if (!ReadPrimitive<CType, DeclaredType>(input, &value)) return false;
385  values->AddAlreadyReserved(value);
386  }
387 #endif
388  } else {
389  // This is the slow-path case where "length" may be too large to
390  // safely allocate. We read as much as we can into *values
391  // without pre-allocating "length" bytes.
392  CType value;
393  for (uint32 i = 0; i < new_entries; ++i) {
394  if (!ReadPrimitive<CType, DeclaredType>(input, &value)) return false;
395  values->Add(value);
396  }
397  }
398  return true;
399 }
400 
401 // Specializations of ReadPackedPrimitive for the fixed size types, which use
402 // an optimized code path.
403 #define READ_REPEATED_PACKED_FIXED_SIZE_PRIMITIVE(CPPTYPE, DECLARED_TYPE) \
404 template <> \
405 inline bool WireFormatLite::ReadPackedPrimitive< \
406  CPPTYPE, WireFormatLite::DECLARED_TYPE>( \
407  io::CodedInputStream* input, \
408  RepeatedField<CPPTYPE>* values) { \
409  return ReadPackedFixedSizePrimitive< \
410  CPPTYPE, WireFormatLite::DECLARED_TYPE>(input, values); \
411 }
412 
414 READ_REPEATED_PACKED_FIXED_SIZE_PRIMITIVE(uint64, TYPE_FIXED64);
415 READ_REPEATED_PACKED_FIXED_SIZE_PRIMITIVE(int32, TYPE_SFIXED32);
416 READ_REPEATED_PACKED_FIXED_SIZE_PRIMITIVE(int64, TYPE_SFIXED64);
419 
420 #undef READ_REPEATED_PACKED_FIXED_SIZE_PRIMITIVE
421 
422 template <typename CType, enum WireFormatLite::FieldType DeclaredType>
424  RepeatedField<CType>* values) {
425  return ReadPackedPrimitive<CType, DeclaredType>(input, values);
426 }
427 
428 
430  io::CodedInputStream* input,
431  MessageLite* value) {
432  if (!input->IncrementRecursionDepth()) return false;
433  if (!value->MergePartialFromCodedStream(input)) return false;
434  input->DecrementRecursionDepth();
435  // Make sure the last thing read was an end tag for this group.
436  if (!input->LastTagWas(MakeTag(field_number, WIRETYPE_END_GROUP))) {
437  return false;
438  }
439  return true;
440 }
442  MessageLite* value) {
443  uint32 length;
444  if (!input->ReadVarint32(&length)) return false;
445  if (!input->IncrementRecursionDepth()) return false;
446  io::CodedInputStream::Limit limit = input->PushLimit(length);
447  if (!value->MergePartialFromCodedStream(input)) return false;
448  // Make sure that parsing stopped when the limit was hit, not at an endgroup
449  // tag.
450  if (!input->ConsumedEntireMessage()) return false;
451  input->PopLimit(limit);
452  input->DecrementRecursionDepth();
453  return true;
454 }
455 
456 // We name the template parameter something long and extremely unlikely to occur
457 // elsewhere because a *qualified* member access expression designed to avoid
458 // virtual dispatch, C++03 [basic.lookup.classref] 3.4.5/4 requires that the
459 // name of the qualifying class to be looked up both in the context of the full
460 // expression (finding the template parameter) and in the context of the object
461 // whose member we are accessing. This could potentially find a nested type
462 // within that object. The standard goes on to require these names to refer to
463 // the same entity, which this collision would violate. The lack of a safe way
464 // to avoid this collision appears to be a defect in the standard, but until it
465 // is corrected, we choose the name to avoid accidental collisions.
466 template<typename MessageType_WorkAroundCppLookupDefect>
469  MessageType_WorkAroundCppLookupDefect* value) {
470  if (!input->IncrementRecursionDepth()) return false;
471  if (!value->
472  MessageType_WorkAroundCppLookupDefect::MergePartialFromCodedStream(input))
473  return false;
474  input->DecrementRecursionDepth();
475  // Make sure the last thing read was an end tag for this group.
476  if (!input->LastTagWas(MakeTag(field_number, WIRETYPE_END_GROUP))) {
477  return false;
478  }
479  return true;
480 }
481 template<typename MessageType_WorkAroundCppLookupDefect>
483  io::CodedInputStream* input, MessageType_WorkAroundCppLookupDefect* value) {
484  uint32 length;
485  if (!input->ReadVarint32(&length)) return false;
486  if (!input->IncrementRecursionDepth()) return false;
487  io::CodedInputStream::Limit limit = input->PushLimit(length);
488  if (!value->
489  MessageType_WorkAroundCppLookupDefect::MergePartialFromCodedStream(input))
490  return false;
491  // Make sure that parsing stopped when the limit was hit, not at an endgroup
492  // tag.
493  if (!input->ConsumedEntireMessage()) return false;
494  input->PopLimit(limit);
495  input->DecrementRecursionDepth();
496  return true;
497 }
498 
499 // ===================================================================
500 
503  output->WriteTag(MakeTag(field_number, type));
504 }
505 
508  output->WriteVarint32SignExtended(value);
509 }
512  output->WriteVarint64(static_cast<uint64>(value));
513 }
516  output->WriteVarint32(value);
517 }
520  output->WriteVarint64(value);
521 }
524  output->WriteVarint32(ZigZagEncode32(value));
525 }
528  output->WriteVarint64(ZigZagEncode64(value));
529 }
532  output->WriteLittleEndian32(value);
533 }
536  output->WriteLittleEndian64(value);
537 }
540  output->WriteLittleEndian32(static_cast<uint32>(value));
541 }
544  output->WriteLittleEndian64(static_cast<uint64>(value));
545 }
548  output->WriteLittleEndian32(EncodeFloat(value));
549 }
552  output->WriteLittleEndian64(EncodeDouble(value));
553 }
556  output->WriteVarint32(value ? 1 : 0);
557 }
560  output->WriteVarint32SignExtended(value);
561 }
562 
563 // See comment on ReadGroupNoVirtual to understand the need for this template
564 // parameter name.
565 template<typename MessageType_WorkAroundCppLookupDefect>
567  int field_number, const MessageType_WorkAroundCppLookupDefect& value,
569  WriteTag(field_number, WIRETYPE_START_GROUP, output);
570  value.MessageType_WorkAroundCppLookupDefect::SerializeWithCachedSizes(output);
571  WriteTag(field_number, WIRETYPE_END_GROUP, output);
572 }
573 template<typename MessageType_WorkAroundCppLookupDefect>
575  int field_number, const MessageType_WorkAroundCppLookupDefect& value,
577  WriteTag(field_number, WIRETYPE_LENGTH_DELIMITED, output);
578  output->WriteVarint32(
579  value.MessageType_WorkAroundCppLookupDefect::GetCachedSize());
580  value.MessageType_WorkAroundCppLookupDefect::SerializeWithCachedSizes(output);
581 }
582 
583 // ===================================================================
584 
586  WireType type,
587  uint8* target) {
588  return io::CodedOutputStream::WriteTagToArray(MakeTag(field_number, type),
589  target);
590 }
591 
593  uint8* target) {
595 }
597  uint8* target) {
599  static_cast<uint64>(value), target);
600 }
602  uint8* target) {
603  return io::CodedOutputStream::WriteVarint32ToArray(value, target);
604 }
606  uint8* target) {
607  return io::CodedOutputStream::WriteVarint64ToArray(value, target);
608 }
610  uint8* target) {
612  target);
613 }
615  uint8* target) {
617  target);
618 }
620  uint8* target) {
622 }
624  uint8* target) {
626 }
628  uint8* target) {
630  static_cast<uint32>(value), target);
631 }
633  uint8* target) {
635  static_cast<uint64>(value), target);
636 }
638  uint8* target) {
640  target);
641 }
643  uint8* target) {
645  target);
646 }
648  uint8* target) {
649  return io::CodedOutputStream::WriteVarint32ToArray(value ? 1 : 0, target);
650 }
652  uint8* target) {
654 }
655 
657  int32 value,
658  uint8* target) {
659  target = WriteTagToArray(field_number, WIRETYPE_VARINT, target);
660  return WriteInt32NoTagToArray(value, target);
661 }
663  int64 value,
664  uint8* target) {
665  target = WriteTagToArray(field_number, WIRETYPE_VARINT, target);
666  return WriteInt64NoTagToArray(value, target);
667 }
669  uint32 value,
670  uint8* target) {
671  target = WriteTagToArray(field_number, WIRETYPE_VARINT, target);
672  return WriteUInt32NoTagToArray(value, target);
673 }
675  uint64 value,
676  uint8* target) {
677  target = WriteTagToArray(field_number, WIRETYPE_VARINT, target);
678  return WriteUInt64NoTagToArray(value, target);
679 }
681  int32 value,
682  uint8* target) {
683  target = WriteTagToArray(field_number, WIRETYPE_VARINT, target);
684  return WriteSInt32NoTagToArray(value, target);
685 }
687  int64 value,
688  uint8* target) {
689  target = WriteTagToArray(field_number, WIRETYPE_VARINT, target);
690  return WriteSInt64NoTagToArray(value, target);
691 }
693  uint32 value,
694  uint8* target) {
695  target = WriteTagToArray(field_number, WIRETYPE_FIXED32, target);
696  return WriteFixed32NoTagToArray(value, target);
697 }
699  uint64 value,
700  uint8* target) {
701  target = WriteTagToArray(field_number, WIRETYPE_FIXED64, target);
702  return WriteFixed64NoTagToArray(value, target);
703 }
705  int32 value,
706  uint8* target) {
707  target = WriteTagToArray(field_number, WIRETYPE_FIXED32, target);
708  return WriteSFixed32NoTagToArray(value, target);
709 }
711  int64 value,
712  uint8* target) {
713  target = WriteTagToArray(field_number, WIRETYPE_FIXED64, target);
714  return WriteSFixed64NoTagToArray(value, target);
715 }
717  float value,
718  uint8* target) {
719  target = WriteTagToArray(field_number, WIRETYPE_FIXED32, target);
720  return WriteFloatNoTagToArray(value, target);
721 }
723  double value,
724  uint8* target) {
725  target = WriteTagToArray(field_number, WIRETYPE_FIXED64, target);
726  return WriteDoubleNoTagToArray(value, target);
727 }
729  bool value,
730  uint8* target) {
731  target = WriteTagToArray(field_number, WIRETYPE_VARINT, target);
732  return WriteBoolNoTagToArray(value, target);
733 }
735  int value,
736  uint8* target) {
737  target = WriteTagToArray(field_number, WIRETYPE_VARINT, target);
738  return WriteEnumNoTagToArray(value, target);
739 }
740 
742  const string& value,
743  uint8* target) {
744  // String is for UTF-8 text only
745  // WARNING: In wire_format.cc, both strings and bytes are handled by
746  // WriteString() to avoid code duplication. If the implementations become
747  // different, you will need to update that usage.
748  target = WriteTagToArray(field_number, WIRETYPE_LENGTH_DELIMITED, target);
750 }
752  const string& value,
753  uint8* target) {
754  target = WriteTagToArray(field_number, WIRETYPE_LENGTH_DELIMITED, target);
756 }
757 
758 
760  const MessageLite& value,
761  uint8* target) {
762  target = WriteTagToArray(field_number, WIRETYPE_START_GROUP, target);
763  target = value.SerializeWithCachedSizesToArray(target);
764  return WriteTagToArray(field_number, WIRETYPE_END_GROUP, target);
765 }
767  const MessageLite& value,
768  uint8* target) {
769  target = WriteTagToArray(field_number, WIRETYPE_LENGTH_DELIMITED, target);
771  value.GetCachedSize(), target);
772  return value.SerializeWithCachedSizesToArray(target);
773 }
774 
775 // See comment on ReadGroupNoVirtual to understand the need for this template
776 // parameter name.
777 template<typename MessageType_WorkAroundCppLookupDefect>
779  int field_number, const MessageType_WorkAroundCppLookupDefect& value,
780  uint8* target) {
781  target = WriteTagToArray(field_number, WIRETYPE_START_GROUP, target);
782  target = value.MessageType_WorkAroundCppLookupDefect ::SerializeWithCachedSizesToArray(target);
783  return WriteTagToArray(field_number, WIRETYPE_END_GROUP, target);
784 }
785 template<typename MessageType_WorkAroundCppLookupDefect>
787  int field_number, const MessageType_WorkAroundCppLookupDefect& value,
788  uint8* target) {
789  target = WriteTagToArray(field_number, WIRETYPE_LENGTH_DELIMITED, target);
791  value.MessageType_WorkAroundCppLookupDefect::GetCachedSize(), target);
792  return value.MessageType_WorkAroundCppLookupDefect ::SerializeWithCachedSizesToArray(target);
793 }
794 
795 // ===================================================================
796 
797 inline int WireFormatLite::Int32Size(int32 value) {
799 }
800 inline int WireFormatLite::Int64Size(int64 value) {
801  return io::CodedOutputStream::VarintSize64(static_cast<uint64>(value));
802 }
805 }
806 inline int WireFormatLite::UInt64Size(uint64 value) {
808 }
809 inline int WireFormatLite::SInt32Size(int32 value) {
811 }
812 inline int WireFormatLite::SInt64Size(int64 value) {
814 }
815 inline int WireFormatLite::EnumSize(int value) {
817 }
818 
819 inline int WireFormatLite::StringSize(const string& value) {
820  return io::CodedOutputStream::VarintSize32(value.size()) +
821  value.size();
822 }
823 inline int WireFormatLite::BytesSize(const string& value) {
824  return io::CodedOutputStream::VarintSize32(value.size()) +
825  value.size();
826 }
827 
828 
829 inline int WireFormatLite::GroupSize(const MessageLite& value) {
830  return value.ByteSize();
831 }
832 inline int WireFormatLite::MessageSize(const MessageLite& value) {
833  return LengthDelimitedSize(value.ByteSize());
834 }
835 
836 // See comment on ReadGroupNoVirtual to understand the need for this template
837 // parameter name.
838 template<typename MessageType_WorkAroundCppLookupDefect>
840  const MessageType_WorkAroundCppLookupDefect& value) {
841  return value.MessageType_WorkAroundCppLookupDefect::ByteSize();
842 }
843 template<typename MessageType_WorkAroundCppLookupDefect>
845  const MessageType_WorkAroundCppLookupDefect& value) {
847  value.MessageType_WorkAroundCppLookupDefect::ByteSize());
848 }
849 
852 }
853 
854 } // namespace internal
855 } // namespace protobuf
856 
857 } // namespace google
858 #endif // GOOGLE_PROTOBUF_WIRE_FORMAT_LITE_INL_H__
859 
static uint8 * WriteInt32ToArray(field_number, int32 value, output) INL
Definition: wire_format_lite_inl.h:656
static uint8 * WriteFixed32ToArray(field_number, uint32 value, output) INL
Definition: wire_format_lite_inl.h:692
static uint8 * WriteFloatNoTagToArray(float value, output) INL
Definition: wire_format_lite_inl.h:637
static void WriteBoolNoTag(bool value, output) INL
Definition: wire_format_lite_inl.h:554
static const uint8 * ReadLittleEndian64FromArray(const uint8 *buffer, uint64 *value)
Definition: coded_stream.h:829
static void WriteSFixed64NoTag(int64 value, output) INL
Definition: wire_format_lite_inl.h:542
static int GroupSize(const MessageLite &value)
Definition: wire_format_lite_inl.h:831
virtual int ByteSize() const =0
static void WriteFloatNoTag(float value, output) INL
Definition: wire_format_lite_inl.h:546
static uint8 * WriteDoubleNoTagToArray(double value, output) INL
Definition: wire_format_lite_inl.h:642
static void WriteUInt32NoTag(uint32 value, output) INL
Definition: wire_format_lite_inl.h:514
Definition: message.h:144
static uint8 * WriteBoolNoTagToArray(bool value, output) INL
Definition: wire_format_lite_inl.h:647
static uint8 * WriteMessageToArray(field_number, const MessageLite &value, output) INL
Definition: wire_format_lite_inl.h:766
static uint8 * WriteUInt32NoTagToArray(uint32 value, output) INL
Definition: wire_format_lite_inl.h:601
Definition: message_lite.h:77
static uint8 * WriteSFixed64NoTagToArray(int64 value, output) INL
Definition: wire_format_lite_inl.h:632
static uint8 * WriteSInt32NoTagToArray(int32 value, output) INL
Definition: wire_format_lite_inl.h:609
static bool ReadPackedPrimitiveNoInline(input, RepeatedField< CType > *value)
static const uint8 * ReadLittleEndian32FromArray(const uint8 *buffer, uint32 *value)
Definition: coded_stream.h:814
void DecrementRecursionDepth()
Definition: coded_stream.h:1143
int Limit
Definition: coded_stream.h:307
static bool ReadGroup(field_number, input, MessageLite *value)
Definition: wire_format_lite_inl.h:429
static int UInt64Size(uint64 value)
Definition: wire_format_lite_inl.h:808
static int StringSize(const string &value)
Definition: wire_format_lite_inl.h:821
static uint8 * WriteStringToArray(field_number, const string &value, output) INL
Definition: wire_format_lite_inl.h:741
int64_t int64
Definition: Define.h:145
static uint8 * WriteVarint32ToArray(uint32 value, uint8 *target)
Definition: coded_stream.h:1009
bool ConsumedEntireMessage()
Definition: coded_stream.h:932
READ_REPEATED_PACKED_FIXED_SIZE_PRIMITIVE(uint32, TYPE_FIXED32)
static uint8 * WriteSInt32ToArray(field_number, int32 value, output) INL
Definition: wire_format_lite_inl.h:680
virtual int GetCachedSize() const =0
#define GOOGLE_DCHECK_EQ
Definition: common.h:753
static uint8 * WriteFixed64NoTagToArray(uint64 value, output) INL
Definition: wire_format_lite_inl.h:623
static uint64 EncodeDouble(double value)
Definition: wire_format_lite.h:603
uint8_t uint8
Definition: common.h:175
static uint8 * WriteMessageNoVirtualToArray(field_number, const MessageType &value, output) INL
static int VarintSize64(uint64 value)
static int BytesSize(const string &value)
Definition: wire_format_lite_inl.h:825
static uint32 EncodeFloat(float value)
Definition: wire_format_lite.h:591
void Resize(int new_size, const Element &value)
Definition: repeated_field.h:653
arena_t NULL
Definition: jemalloc_internal.h:624
bool ReadVarint32(uint32 *value)
Definition: coded_stream.h:793
static int SInt64Size(int64 value)
Definition: wire_format_lite_inl.h:814
static uint8 * WriteUInt64ToArray(field_number, uint64 value, output) INL
Definition: wire_format_lite_inl.h:674
static uint8 * WriteInt32NoTagToArray(int32 value, output) INL
Definition: wire_format_lite_inl.h:592
Definition: PreparedStatement.h:56
void Truncate(int new_size)
Definition: repeated_field.h:820
static void WriteTag(field_number, WireType type, output) INL
Definition: wire_format_lite_inl.h:501
static int MessageSize(const MessageLite &value)
Definition: wire_format_lite_inl.h:834
int size() const
Definition: repeated_field.h:631
void WriteTag(uint32 value)
Definition: coded_stream.h:1069
static void WriteSInt64NoTag(int64 value, output) INL
Definition: wire_format_lite_inl.h:526
#define output
Definition: wire_format_lite.h:381
static void WriteDoubleNoTag(double value, output) INL
Definition: wire_format_lite_inl.h:550
static const uint8 * ReadPrimitiveFromArray(const uint8 *buffer, CType *value) INL
static int GroupSizeNoVirtual(const MessageType &value)
static uint8 * WriteEnumToArray(field_number, int value, output) INL
Definition: wire_format_lite_inl.h:734
static uint8 * WriteSFixed32NoTagToArray(int32 value, output) INL
Definition: wire_format_lite_inl.h:627
static uint8 * WriteInt64ToArray(field_number, int64 value, output) INL
Definition: wire_format_lite_inl.h:662
Definition: coded_stream.h:156
int32_t int32
Definition: common.h:172
static bool ReadRepeatedFixedSizePrimitive(int tag_size, uint32 tag, google::protobuf::io::CodedInputStream *input, RepeatedField< CType > *value) GOOGLE_ATTRIBUTE_ALWAYS_INLINE
Definition: wire_format_lite_inl.h:247
static void WriteUInt64NoTag(uint64 value, output) INL
Definition: wire_format_lite_inl.h:518
static int Int32Size(int32 value)
Definition: wire_format_lite_inl.h:799
T min(const T &x, const T &y)
Definition: g3dmath.h:305
static uint8 * WriteFixed32NoTagToArray(uint32 value, output) INL
Definition: wire_format_lite_inl.h:619
virtual bool MergePartialFromCodedStream(io::CodedInputStream *input)=0
static bool ReadPackedFixedSizePrimitive(google::protobuf::io::CodedInputStream *input, RepeatedField< CType > *value) GOOGLE_ATTRIBUTE_ALWAYS_INLINE
Definition: wire_format_lite_inl.h:343
static const uint8 * ExpectTagFromArray(const uint8 *buffer, uint32 expected) GOOGLE_ATTRIBUTE_ALWAYS_INLINE
Definition: coded_stream.h:959
static int LengthDelimitedSize(int length)
Definition: wire_format_lite_inl.h:852
static uint8 * WriteBoolToArray(field_number, bool value, output) INL
Definition: wire_format_lite_inl.h:728
Definition: coded_stream.h:621
static uint32 ZigZagEncode32(int32 n)
Definition: wire_format_lite.h:639
static void WriteEnumNoTag(int value, output) INL
Definition: wire_format_lite_inl.h:558
static int Int64Size(int64 value)
Definition: wire_format_lite_inl.h:802
static uint8 * WriteVarint64ToArray(uint64 value, uint8 *target)
static void WriteFixed64NoTag(uint64 value, output) INL
Definition: wire_format_lite_inl.h:534
static uint8 * WriteTagToArray(field_number, WireType type, output) INL
Definition: wire_format_lite_inl.h:585
static int UInt32Size(uint32 value)
Definition: wire_format_lite_inl.h:805
static void WriteInt64NoTag(int64 value, output) INL
Definition: wire_format_lite_inl.h:510
static bool ReadGroupNoVirtual(field_number, input, MessageType *value)
static uint8 * WriteSFixed64ToArray(field_number, int64 value, output) INL
Definition: wire_format_lite_inl.h:710
static uint8 * WriteInt64NoTagToArray(int64 value, output) INL
Definition: wire_format_lite_inl.h:596
Element * mutable_data()
Definition: repeated_field.h:745
static void WriteSInt32NoTag(int32 value, output) INL
Definition: wire_format_lite_inl.h:522
#define input
Definition: wire_format_lite.h:242
static int EnumSize(int value)
Definition: wire_format_lite_inl.h:817
int32_t int32
Definition: Define.h:146
static uint8 * WriteEnumNoTagToArray(int value, output) INL
Definition: wire_format_lite_inl.h:651
uint32_t uint32
Definition: common.h:177
uint32_t uint32
Definition: Define.h:150
static int VarintSize32SignExtended(int32 value)
Definition: coded_stream.h:1095
static uint8 * WriteStringWithSizeToArray(const string &str, uint8 *target)
virtual uint8 * SerializeWithCachedSizesToArray(uint8 *target) const
uint64_t uint64
Definition: Define.h:149
bool LastTagWas(uint32 expected)
Definition: coded_stream.h:928
uint64_t uint64
Definition: common.h:178
static void WriteInt32NoTag(int32 value, output) INL
Definition: wire_format_lite_inl.h:506
static int MessageSizeNoVirtual(const MessageType &value)
static bool ReadMessageNoVirtual(input, MessageType *value)
static bool ReadPackedPrimitive(input, RepeatedField< CType > *value) INL
float length(float v)
Definition: vectorMath.h:208
static uint8 * WriteBytesToArray(field_number, const string &value, output) INL
Definition: wire_format_lite_inl.h:751
static uint32 MakeTag(int field_number, WireType type)
Definition: wire_format_lite.h:567
static bool ReadRepeatedPrimitiveNoInline(int tag_size, uint32 tag, input, RepeatedField< CType > *value)
Definition: document.h:390
void AddAlreadyReserved(const Element &value)
Definition: repeated_field.h:641
void Add(const Element &value)
Definition: repeated_field.h:684
void Reserve(int new_size)
Definition: repeated_field.h:806
int Capacity() const
Definition: repeated_field.h:636
static void WriteSFixed32NoTag(int32 value, output) INL
Definition: wire_format_lite_inl.h:538
static uint8 * WriteDoubleToArray(field_number, double value, output) INL
Definition: wire_format_lite_inl.h:722
static uint8 * WriteGroupToArray(field_number, const MessageLite &value, output) INL
Definition: wire_format_lite_inl.h:759
static uint64 ZigZagEncode64(int64 n)
Definition: wire_format_lite.h:648
int64_t int64
Definition: common.h:173
bool IncrementRecursionDepth()
Definition: coded_stream.h:1138
bool ReadRaw(void *buffer, int size)
static uint8 * WriteUInt32ToArray(field_number, uint32 value, output) INL
Definition: wire_format_lite_inl.h:668
static void WriteFixed32NoTag(uint32 value, output) INL
Definition: wire_format_lite_inl.h:530
static int SInt32Size(int32 value)
Definition: wire_format_lite_inl.h:811
static uint8 * WriteSFixed32ToArray(field_number, int32 value, output) INL
Definition: wire_format_lite_inl.h:704
static uint8 * WriteSInt64ToArray(field_number, int64 value, output) INL
Definition: wire_format_lite_inl.h:686
static bool ReadMessage(input, MessageLite *value)
Definition: wire_format_lite_inl.h:441
#define READ_REPEATED_FIXED_SIZE_PRIMITIVE(CPPTYPE, DECLARED_TYPE)
Definition: wire_format_lite_inl.h:295
static uint8 * WriteSInt64NoTagToArray(int64 value, output) INL
Definition: wire_format_lite_inl.h:614
Definition: BnetFileGenerator.h:47
static uint8 * WriteLittleEndian32ToArray(uint32 value, uint8 *target)
Definition: coded_stream.h:1036
const FieldDescriptor value
Definition: descriptor.h:1522
static uint8 * WriteLittleEndian64ToArray(uint64 value, uint8 *target)
Definition: coded_stream.h:1049
void WriteVarint32SignExtended(int32 value)
Definition: coded_stream.h:1019
static uint8 * WriteVarint32SignExtendedToArray(int32 value, uint8 *target)
Definition: coded_stream.h:1027
static uint8 * WriteTagToArray(uint32 value, uint8 *target) GOOGLE_ATTRIBUTE_ALWAYS_INLINE
Definition: coded_stream.h:1073
bool ExpectTag(uint32 expected) GOOGLE_ATTRIBUTE_ALWAYS_INLINE
Definition: coded_stream.h:936
Definition: PreparedStatement.h:57
static bool ReadRepeatedPrimitive(int tag_size, uint32 tag, input, RepeatedField< CType > *value) INL
void GetDirectBufferPointerInline(const void **data, int *size) GOOGLE_ATTRIBUTE_ALWAYS_INLINE
Definition: coded_stream.h:974
static uint8 * WriteGroupNoVirtualToArray(field_number, const MessageType &value, output) INL
static uint8 * WriteFloatToArray(field_number, float value, output) INL
Definition: wire_format_lite_inl.h:716
static void WriteMessageNoVirtual(field_number, const MessageType &value, output)
static void WriteGroupNoVirtual(field_number, const MessageType &value, output)
static uint8 * WriteFixed64ToArray(field_number, uint64 value, output) INL
Definition: wire_format_lite_inl.h:698
WireType
Definition: wire_format_lite.h:86
static int VarintSize32(uint32 value)
Definition: coded_stream.h:1087
static uint8 * WriteUInt64NoTagToArray(uint64 value, output) INL
Definition: wire_format_lite_inl.h:605
#define field_number
Definition: wire_format_lite.h:244