Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(397)

Side by Side Diff: third_party/protobuf/src/google/protobuf/wire_format_lite_inl.h

Issue 2599263002: third_party/protobuf: Update to HEAD (f52e188fe4) (Closed)
Patch Set: Address comments Created 3 years, 12 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Protocol Buffers - Google's data interchange format 1 // Protocol Buffers - Google's data interchange format
2 // Copyright 2008 Google Inc. All rights reserved. 2 // Copyright 2008 Google Inc. All rights reserved.
3 // https://developers.google.com/protocol-buffers/ 3 // https://developers.google.com/protocol-buffers/
4 // 4 //
5 // Redistribution and use in source and binary forms, with or without 5 // Redistribution and use in source and binary forms, with or without
6 // modification, are permitted provided that the following conditions are 6 // modification, are permitted provided that the following conditions are
7 // met: 7 // met:
8 // 8 //
9 // * Redistributions of source code must retain the above copyright 9 // * Redistributions of source code must retain the above copyright
10 // notice, this list of conditions and the following disclaimer. 10 // notice, this list of conditions and the following disclaimer.
(...skipping 233 matching lines...) Expand 10 before | Expand all | Expand 10 after
244 } 244 }
245 return true; 245 return true;
246 } 246 }
247 247
248 template <typename CType, enum WireFormatLite::FieldType DeclaredType> 248 template <typename CType, enum WireFormatLite::FieldType DeclaredType>
249 inline bool WireFormatLite::ReadRepeatedFixedSizePrimitive( 249 inline bool WireFormatLite::ReadRepeatedFixedSizePrimitive(
250 int tag_size, 250 int tag_size,
251 uint32 tag, 251 uint32 tag,
252 io::CodedInputStream* input, 252 io::CodedInputStream* input,
253 RepeatedField<CType>* values) { 253 RepeatedField<CType>* values) {
254 GOOGLE_DCHECK_EQ(UInt32Size(tag), tag_size); 254 GOOGLE_DCHECK_EQ(UInt32Size(tag), static_cast<size_t>(tag_size));
255 CType value; 255 CType value;
256 if (!ReadPrimitive<CType, DeclaredType>(input, &value)) 256 if (!ReadPrimitive<CType, DeclaredType>(input, &value))
257 return false; 257 return false;
258 values->Add(value); 258 values->Add(value);
259 259
260 // For fixed size values, repeated values can be read more quickly by 260 // For fixed size values, repeated values can be read more quickly by
261 // reading directly from a raw array. 261 // reading directly from a raw array.
262 // 262 //
263 // We can get a tight loop by only reading as many elements as can be 263 // We can get a tight loop by only reading as many elements as can be
264 // added to the RepeatedField without having to do any resizing. Additionally, 264 // added to the RepeatedField without having to do any resizing. Additionally,
265 // we only try to read as many elements as are available from the current 265 // we only try to read as many elements as are available from the current
266 // buffer space. Doing so avoids having to perform boundary checks when 266 // buffer space. Doing so avoids having to perform boundary checks when
267 // reading the value: the maximum number of elements that can be read is 267 // reading the value: the maximum number of elements that can be read is
268 // known outside of the loop. 268 // known outside of the loop.
269 const void* void_pointer; 269 const void* void_pointer;
270 int size; 270 int size;
271 input->GetDirectBufferPointerInline(&void_pointer, &size); 271 input->GetDirectBufferPointerInline(&void_pointer, &size);
272 if (size > 0) { 272 if (size > 0) {
273 const uint8* buffer = reinterpret_cast<const uint8*>(void_pointer); 273 const uint8* buffer = reinterpret_cast<const uint8*>(void_pointer);
274 // The number of bytes each type occupies on the wire. 274 // The number of bytes each type occupies on the wire.
275 const int per_value_size = tag_size + sizeof(value); 275 const int per_value_size = tag_size + sizeof(value);
276 276
277 // parentheses around (std::min) prevents macro expansion of min(...)
277 int elements_available = 278 int elements_available =
278 std::min(values->Capacity() - values->size(), size / per_value_size); 279 (std::min)(values->Capacity() - values->size(), size / per_value_size);
279 int num_read = 0; 280 int num_read = 0;
280 while (num_read < elements_available && 281 while (num_read < elements_available &&
281 (buffer = io::CodedInputStream::ExpectTagFromArray( 282 (buffer = io::CodedInputStream::ExpectTagFromArray(
282 buffer, tag)) != NULL) { 283 buffer, tag)) != NULL) {
283 buffer = ReadPrimitiveFromArray<CType, DeclaredType>(buffer, &value); 284 buffer = ReadPrimitiveFromArray<CType, DeclaredType>(buffer, &value);
284 values->AddAlreadyReserved(value); 285 values->AddAlreadyReserved(value);
285 ++num_read; 286 ++num_read;
286 } 287 }
287 const int read_bytes = num_read * per_value_size; 288 const int read_bytes = num_read * per_value_size;
288 if (read_bytes > 0) { 289 if (read_bytes > 0) {
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
322 uint32 tag, 323 uint32 tag,
323 io::CodedInputStream* input, 324 io::CodedInputStream* input,
324 RepeatedField<CType>* value) { 325 RepeatedField<CType>* value) {
325 return ReadRepeatedPrimitive<CType, DeclaredType>( 326 return ReadRepeatedPrimitive<CType, DeclaredType>(
326 tag_size, tag, input, value); 327 tag_size, tag, input, value);
327 } 328 }
328 329
329 template <typename CType, enum WireFormatLite::FieldType DeclaredType> 330 template <typename CType, enum WireFormatLite::FieldType DeclaredType>
330 inline bool WireFormatLite::ReadPackedPrimitive(io::CodedInputStream* input, 331 inline bool WireFormatLite::ReadPackedPrimitive(io::CodedInputStream* input,
331 RepeatedField<CType>* values) { 332 RepeatedField<CType>* values) {
332 uint32 length; 333 int length;
333 if (!input->ReadVarint32(&length)) return false; 334 if (!input->ReadVarintSizeAsInt(&length)) return false;
334 io::CodedInputStream::Limit limit = input->PushLimit(length); 335 io::CodedInputStream::Limit limit = input->PushLimit(length);
335 while (input->BytesUntilLimit() > 0) { 336 while (input->BytesUntilLimit() > 0) {
336 CType value; 337 CType value;
337 if (!ReadPrimitive<CType, DeclaredType>(input, &value)) return false; 338 if (!ReadPrimitive<CType, DeclaredType>(input, &value)) return false;
338 values->Add(value); 339 values->Add(value);
339 } 340 }
340 input->PopLimit(limit); 341 input->PopLimit(limit);
341 return true; 342 return true;
342 } 343 }
343 344
344 template <typename CType, enum WireFormatLite::FieldType DeclaredType> 345 template <typename CType, enum WireFormatLite::FieldType DeclaredType>
345 inline bool WireFormatLite::ReadPackedFixedSizePrimitive( 346 inline bool WireFormatLite::ReadPackedFixedSizePrimitive(
346 io::CodedInputStream* input, RepeatedField<CType>* values) { 347 io::CodedInputStream* input, RepeatedField<CType>* values) {
347 uint32 length; 348 int length;
348 if (!input->ReadVarint32(&length)) return false; 349 if (!input->ReadVarintSizeAsInt(&length)) return false;
349 const uint32 old_entries = values->size(); 350 const int old_entries = values->size();
350 const uint32 new_entries = length / sizeof(CType); 351 const int new_entries = length / sizeof(CType);
351 const uint32 new_bytes = new_entries * sizeof(CType); 352 const int new_bytes = new_entries * sizeof(CType);
352 if (new_bytes != length) return false; 353 if (new_bytes != length) return false;
353 // We would *like* to pre-allocate the buffer to write into (for 354 // We would *like* to pre-allocate the buffer to write into (for
354 // speed), but *must* avoid performing a very large allocation due 355 // speed), but *must* avoid performing a very large allocation due
355 // to a malicious user-supplied "length" above. So we have a fast 356 // to a malicious user-supplied "length" above. So we have a fast
356 // path that pre-allocates when the "length" is less than a bound. 357 // path that pre-allocates when the "length" is less than a bound.
357 // We determine the bound by calling BytesUntilTotalBytesLimit() and 358 // We determine the bound by calling BytesUntilTotalBytesLimit() and
358 // BytesUntilLimit(). These return -1 to mean "no limit set". 359 // BytesUntilLimit(). These return -1 to mean "no limit set".
359 // There are four cases: 360 // There are four cases:
360 // TotalBytesLimit Limit 361 // TotalBytesLimit Limit
361 // -1 -1 Use slow path. 362 // -1 -1 Use slow path.
362 // -1 >= 0 Use fast path if length <= Limit. 363 // -1 >= 0 Use fast path if length <= Limit.
363 // >= 0 -1 Use slow path. 364 // >= 0 -1 Use slow path.
364 // >= 0 >= 0 Use fast path if length <= min(both limits). 365 // >= 0 >= 0 Use fast path if length <= min(both limits).
365 int64 bytes_limit = input->BytesUntilTotalBytesLimit(); 366 int64 bytes_limit = input->BytesUntilTotalBytesLimit();
366 if (bytes_limit == -1) { 367 if (bytes_limit == -1) {
367 bytes_limit = input->BytesUntilLimit(); 368 bytes_limit = input->BytesUntilLimit();
368 } else { 369 } else {
370 // parentheses around (std::min) prevents macro expansion of min(...)
369 bytes_limit = 371 bytes_limit =
370 std::min(bytes_limit, static_cast<int64>(input->BytesUntilLimit())); 372 (std::min)(bytes_limit, static_cast<int64>(input->BytesUntilLimit()));
371 } 373 }
372 if (bytes_limit >= new_bytes) { 374 if (bytes_limit >= new_bytes) {
373 // Fast-path that pre-allocates *values to the final size. 375 // Fast-path that pre-allocates *values to the final size.
374 #if defined(PROTOBUF_LITTLE_ENDIAN) 376 #if defined(PROTOBUF_LITTLE_ENDIAN)
375 values->Resize(old_entries + new_entries, 0); 377 values->Resize(old_entries + new_entries, 0);
376 // values->mutable_data() may change after Resize(), so do this after: 378 // values->mutable_data() may change after Resize(), so do this after:
377 void* dest = reinterpret_cast<void*>(values->mutable_data() + old_entries); 379 void* dest = reinterpret_cast<void*>(values->mutable_data() + old_entries);
378 if (!input->ReadRaw(dest, new_bytes)) { 380 if (!input->ReadRaw(dest, new_bytes)) {
379 values->Truncate(old_entries); 381 values->Truncate(old_entries);
380 return false; 382 return false;
381 } 383 }
382 #else 384 #else
383 values->Reserve(old_entries + new_entries); 385 values->Reserve(old_entries + new_entries);
384 CType value; 386 CType value;
385 for (uint32 i = 0; i < new_entries; ++i) { 387 for (int i = 0; i < new_entries; ++i) {
386 if (!ReadPrimitive<CType, DeclaredType>(input, &value)) return false; 388 if (!ReadPrimitive<CType, DeclaredType>(input, &value)) return false;
387 values->AddAlreadyReserved(value); 389 values->AddAlreadyReserved(value);
388 } 390 }
389 #endif 391 #endif
390 } else { 392 } else {
391 // This is the slow-path case where "length" may be too large to 393 // This is the slow-path case where "length" may be too large to
392 // safely allocate. We read as much as we can into *values 394 // safely allocate. We read as much as we can into *values
393 // without pre-allocating "length" bytes. 395 // without pre-allocating "length" bytes.
394 CType value; 396 CType value;
395 for (uint32 i = 0; i < new_entries; ++i) { 397 for (int i = 0; i < new_entries; ++i) {
396 if (!ReadPrimitive<CType, DeclaredType>(input, &value)) return false; 398 if (!ReadPrimitive<CType, DeclaredType>(input, &value)) return false;
397 values->Add(value); 399 values->Add(value);
398 } 400 }
399 } 401 }
400 return true; 402 return true;
401 } 403 }
402 404
403 // Specializations of ReadPackedPrimitive for the fixed size types, which use 405 // Specializations of ReadPackedPrimitive for the fixed size types, which use
404 // an optimized code path. 406 // an optimized code path.
405 #define READ_REPEATED_PACKED_FIXED_SIZE_PRIMITIVE(CPPTYPE, DECLARED_TYPE) \ 407 #define READ_REPEATED_PACKED_FIXED_SIZE_PRIMITIVE(CPPTYPE, DECLARED_TYPE) \
(...skipping 30 matching lines...) Expand all
436 if (!value->MergePartialFromCodedStream(input)) return false; 438 if (!value->MergePartialFromCodedStream(input)) return false;
437 input->DecrementRecursionDepth(); 439 input->DecrementRecursionDepth();
438 // Make sure the last thing read was an end tag for this group. 440 // Make sure the last thing read was an end tag for this group.
439 if (!input->LastTagWas(MakeTag(field_number, WIRETYPE_END_GROUP))) { 441 if (!input->LastTagWas(MakeTag(field_number, WIRETYPE_END_GROUP))) {
440 return false; 442 return false;
441 } 443 }
442 return true; 444 return true;
443 } 445 }
444 inline bool WireFormatLite::ReadMessage(io::CodedInputStream* input, 446 inline bool WireFormatLite::ReadMessage(io::CodedInputStream* input,
445 MessageLite* value) { 447 MessageLite* value) {
446 uint32 length; 448 int length;
447 if (!input->ReadVarint32(&length)) return false; 449 if (!input->ReadVarintSizeAsInt(&length)) return false;
448 std::pair<io::CodedInputStream::Limit, int> p = 450 std::pair<io::CodedInputStream::Limit, int> p =
449 input->IncrementRecursionDepthAndPushLimit(length); 451 input->IncrementRecursionDepthAndPushLimit(length);
450 if (p.second < 0 || !value->MergePartialFromCodedStream(input)) return false; 452 if (p.second < 0 || !value->MergePartialFromCodedStream(input)) return false;
451 // Make sure that parsing stopped when the limit was hit, not at an endgroup 453 // Make sure that parsing stopped when the limit was hit, not at an endgroup
452 // tag. 454 // tag.
453 return input->DecrementRecursionDepthAndPopLimit(p.first); 455 return input->DecrementRecursionDepthAndPopLimit(p.first);
454 } 456 }
455 457
456 // We name the template parameter something long and extremely unlikely to occur 458 // We name the template parameter something long and extremely unlikely to occur
457 // elsewhere because a *qualified* member access expression designed to avoid 459 // elsewhere because a *qualified* member access expression designed to avoid
(...skipping 24 matching lines...) Expand all
482 inline bool WireFormatLite::ReadGroupNoVirtualNoRecursionDepth( 484 inline bool WireFormatLite::ReadGroupNoVirtualNoRecursionDepth(
483 int field_number, io::CodedInputStream* input, 485 int field_number, io::CodedInputStream* input,
484 MessageType_WorkAroundCppLookupDefect* value) { 486 MessageType_WorkAroundCppLookupDefect* value) {
485 return value->MessageType_WorkAroundCppLookupDefect:: 487 return value->MessageType_WorkAroundCppLookupDefect::
486 MergePartialFromCodedStream(input) && 488 MergePartialFromCodedStream(input) &&
487 input->LastTagWas(MakeTag(field_number, WIRETYPE_END_GROUP)); 489 input->LastTagWas(MakeTag(field_number, WIRETYPE_END_GROUP));
488 } 490 }
489 template<typename MessageType_WorkAroundCppLookupDefect> 491 template<typename MessageType_WorkAroundCppLookupDefect>
490 inline bool WireFormatLite::ReadMessageNoVirtual( 492 inline bool WireFormatLite::ReadMessageNoVirtual(
491 io::CodedInputStream* input, MessageType_WorkAroundCppLookupDefect* value) { 493 io::CodedInputStream* input, MessageType_WorkAroundCppLookupDefect* value) {
492 uint32 length; 494 int length;
493 if (!input->ReadVarint32(&length)) return false; 495 if (!input->ReadVarintSizeAsInt(&length)) return false;
494 std::pair<io::CodedInputStream::Limit, int> p = 496 std::pair<io::CodedInputStream::Limit, int> p =
495 input->IncrementRecursionDepthAndPushLimit(length); 497 input->IncrementRecursionDepthAndPushLimit(length);
496 if (p.second < 0 || !value-> 498 if (p.second < 0 || !value->
497 MessageType_WorkAroundCppLookupDefect::MergePartialFromCodedStream(input)) 499 MessageType_WorkAroundCppLookupDefect::MergePartialFromCodedStream(input))
498 return false; 500 return false;
499 // Make sure that parsing stopped when the limit was hit, not at an endgroup 501 // Make sure that parsing stopped when the limit was hit, not at an endgroup
500 // tag. 502 // tag.
501 return input->DecrementRecursionDepthAndPopLimit(p.first); 503 return input->DecrementRecursionDepthAndPopLimit(p.first);
502 } 504 }
503 template<typename MessageType_WorkAroundCppLookupDefect> 505 template<typename MessageType_WorkAroundCppLookupDefect>
(...skipping 261 matching lines...) Expand 10 before | Expand all | Expand 10 after
765 return io::CodedOutputStream::WriteStringWithSizeToArray(value, target); 767 return io::CodedOutputStream::WriteStringWithSizeToArray(value, target);
766 } 768 }
767 inline uint8* WireFormatLite::WriteBytesToArray(int field_number, 769 inline uint8* WireFormatLite::WriteBytesToArray(int field_number,
768 const string& value, 770 const string& value,
769 uint8* target) { 771 uint8* target) {
770 target = WriteTagToArray(field_number, WIRETYPE_LENGTH_DELIMITED, target); 772 target = WriteTagToArray(field_number, WIRETYPE_LENGTH_DELIMITED, target);
771 return io::CodedOutputStream::WriteStringWithSizeToArray(value, target); 773 return io::CodedOutputStream::WriteStringWithSizeToArray(value, target);
772 } 774 }
773 775
774 776
775 inline uint8* WireFormatLite::WriteGroupToArray(int field_number, 777 inline uint8* WireFormatLite::InternalWriteGroupToArray(
776 const MessageLite& value, 778 int field_number, const MessageLite& value, bool deterministic,
777 uint8* target) { 779 uint8* target) {
778 target = WriteTagToArray(field_number, WIRETYPE_START_GROUP, target); 780 target = WriteTagToArray(field_number, WIRETYPE_START_GROUP, target);
779 target = value.SerializeWithCachedSizesToArray(target); 781 target = value.InternalSerializeWithCachedSizesToArray(deterministic, target);
780 return WriteTagToArray(field_number, WIRETYPE_END_GROUP, target); 782 return WriteTagToArray(field_number, WIRETYPE_END_GROUP, target);
781 } 783 }
782 inline uint8* WireFormatLite::WriteMessageToArray(int field_number, 784 inline uint8* WireFormatLite::InternalWriteMessageToArray(
783 const MessageLite& value, 785 int field_number, const MessageLite& value, bool deterministic,
784 uint8* target) { 786 uint8* target) {
785 target = WriteTagToArray(field_number, WIRETYPE_LENGTH_DELIMITED, target); 787 target = WriteTagToArray(field_number, WIRETYPE_LENGTH_DELIMITED, target);
786 target = io::CodedOutputStream::WriteVarint32ToArray( 788 target = io::CodedOutputStream::WriteVarint32ToArray(
787 value.GetCachedSize(), target); 789 value.GetCachedSize(), target);
788 return value.SerializeWithCachedSizesToArray(target); 790 return value.InternalSerializeWithCachedSizesToArray(deterministic, target);
789 } 791 }
790 792
791 // See comment on ReadGroupNoVirtual to understand the need for this template 793 // See comment on ReadGroupNoVirtual to understand the need for this template
792 // parameter name. 794 // parameter name.
793 template<typename MessageType_WorkAroundCppLookupDefect> 795 template<typename MessageType_WorkAroundCppLookupDefect>
794 inline uint8* WireFormatLite::WriteGroupNoVirtualToArray( 796 inline uint8* WireFormatLite::InternalWriteGroupNoVirtualToArray(
795 int field_number, const MessageType_WorkAroundCppLookupDefect& value, 797 int field_number, const MessageType_WorkAroundCppLookupDefect& value,
796 uint8* target) { 798 bool deterministic, uint8* target) {
797 target = WriteTagToArray(field_number, WIRETYPE_START_GROUP, target); 799 target = WriteTagToArray(field_number, WIRETYPE_START_GROUP, target);
798 target = value.MessageType_WorkAroundCppLookupDefect 800 target = value.InternalSerializeWithCachedSizesToArray(deterministic, target);
799 ::SerializeWithCachedSizesToArray(target);
800 return WriteTagToArray(field_number, WIRETYPE_END_GROUP, target); 801 return WriteTagToArray(field_number, WIRETYPE_END_GROUP, target);
801 } 802 }
802 template<typename MessageType_WorkAroundCppLookupDefect> 803 template<typename MessageType_WorkAroundCppLookupDefect>
803 inline uint8* WireFormatLite::WriteMessageNoVirtualToArray( 804 inline uint8* WireFormatLite::InternalWriteMessageNoVirtualToArray(
804 int field_number, const MessageType_WorkAroundCppLookupDefect& value, 805 int field_number, const MessageType_WorkAroundCppLookupDefect& value,
805 uint8* target) { 806 bool deterministic, uint8* target) {
806 target = WriteTagToArray(field_number, WIRETYPE_LENGTH_DELIMITED, target); 807 target = WriteTagToArray(field_number, WIRETYPE_LENGTH_DELIMITED, target);
807 target = io::CodedOutputStream::WriteVarint32ToArray( 808 target = io::CodedOutputStream::WriteVarint32ToArray(
808 value.MessageType_WorkAroundCppLookupDefect::GetCachedSize(), target); 809 value.MessageType_WorkAroundCppLookupDefect::GetCachedSize(), target);
809 return value.MessageType_WorkAroundCppLookupDefect 810 return value.InternalSerializeWithCachedSizesToArray(deterministic, target);
810 ::SerializeWithCachedSizesToArray(target);
811 } 811 }
812 812
813 // =================================================================== 813 // ===================================================================
814 814
815 inline int WireFormatLite::Int32Size(int32 value) { 815 inline size_t WireFormatLite::Int32Size(int32 value) {
816 return io::CodedOutputStream::VarintSize32SignExtended(value); 816 return io::CodedOutputStream::VarintSize32SignExtended(value);
817 } 817 }
818 inline int WireFormatLite::Int64Size(int64 value) { 818 inline size_t WireFormatLite::Int64Size(int64 value) {
819 return io::CodedOutputStream::VarintSize64(static_cast<uint64>(value)); 819 return io::CodedOutputStream::VarintSize64(static_cast<uint64>(value));
820 } 820 }
821 inline int WireFormatLite::UInt32Size(uint32 value) { 821 inline size_t WireFormatLite::UInt32Size(uint32 value) {
822 return io::CodedOutputStream::VarintSize32(value); 822 return io::CodedOutputStream::VarintSize32(value);
823 } 823 }
824 inline int WireFormatLite::UInt64Size(uint64 value) { 824 inline size_t WireFormatLite::UInt64Size(uint64 value) {
825 return io::CodedOutputStream::VarintSize64(value); 825 return io::CodedOutputStream::VarintSize64(value);
826 } 826 }
827 inline int WireFormatLite::SInt32Size(int32 value) { 827 inline size_t WireFormatLite::SInt32Size(int32 value) {
828 return io::CodedOutputStream::VarintSize32(ZigZagEncode32(value)); 828 return io::CodedOutputStream::VarintSize32(ZigZagEncode32(value));
829 } 829 }
830 inline int WireFormatLite::SInt64Size(int64 value) { 830 inline size_t WireFormatLite::SInt64Size(int64 value) {
831 return io::CodedOutputStream::VarintSize64(ZigZagEncode64(value)); 831 return io::CodedOutputStream::VarintSize64(ZigZagEncode64(value));
832 } 832 }
833 inline int WireFormatLite::EnumSize(int value) { 833 inline size_t WireFormatLite::EnumSize(int value) {
834 return io::CodedOutputStream::VarintSize32SignExtended(value); 834 return io::CodedOutputStream::VarintSize32SignExtended(value);
835 } 835 }
836 836
837 inline int WireFormatLite::StringSize(const string& value) { 837 inline size_t WireFormatLite::StringSize(const string& value) {
838 return static_cast<int>( 838 return LengthDelimitedSize(value.size());
839 io::CodedOutputStream::VarintSize32(static_cast<uint32>(value.size())) +
840 value.size());
841 } 839 }
842 inline int WireFormatLite::BytesSize(const string& value) { 840 inline size_t WireFormatLite::BytesSize(const string& value) {
843 return static_cast<int>( 841 return LengthDelimitedSize(value.size());
844 io::CodedOutputStream::VarintSize32(static_cast<uint32>(value.size())) +
845 value.size());
846 } 842 }
847 843
848 844
849 inline int WireFormatLite::GroupSize(const MessageLite& value) { 845 inline size_t WireFormatLite::GroupSize(const MessageLite& value) {
850 return value.ByteSize(); 846 return value.ByteSizeLong();
851 } 847 }
852 inline int WireFormatLite::MessageSize(const MessageLite& value) { 848 inline size_t WireFormatLite::MessageSize(const MessageLite& value) {
853 return LengthDelimitedSize(value.ByteSize()); 849 return LengthDelimitedSize(value.ByteSizeLong());
854 } 850 }
855 851
856 // See comment on ReadGroupNoVirtual to understand the need for this template 852 // See comment on ReadGroupNoVirtual to understand the need for this template
857 // parameter name. 853 // parameter name.
858 template<typename MessageType_WorkAroundCppLookupDefect> 854 template<typename MessageType_WorkAroundCppLookupDefect>
859 inline int WireFormatLite::GroupSizeNoVirtual( 855 inline size_t WireFormatLite::GroupSizeNoVirtual(
860 const MessageType_WorkAroundCppLookupDefect& value) { 856 const MessageType_WorkAroundCppLookupDefect& value) {
861 return value.MessageType_WorkAroundCppLookupDefect::ByteSize(); 857 return value.MessageType_WorkAroundCppLookupDefect::ByteSizeLong();
862 } 858 }
863 template<typename MessageType_WorkAroundCppLookupDefect> 859 template<typename MessageType_WorkAroundCppLookupDefect>
864 inline int WireFormatLite::MessageSizeNoVirtual( 860 inline size_t WireFormatLite::MessageSizeNoVirtual(
865 const MessageType_WorkAroundCppLookupDefect& value) { 861 const MessageType_WorkAroundCppLookupDefect& value) {
866 return LengthDelimitedSize( 862 return LengthDelimitedSize(
867 value.MessageType_WorkAroundCppLookupDefect::ByteSize()); 863 value.MessageType_WorkAroundCppLookupDefect::ByteSizeLong());
868 } 864 }
869 865
870 inline int WireFormatLite::LengthDelimitedSize(int length) { 866 inline size_t WireFormatLite::LengthDelimitedSize(size_t length) {
871 return io::CodedOutputStream::VarintSize32(length) + length; 867 // The static_cast here prevents an error in certain compiler configurations
868 // but is not technically correct--if length is too large to fit in a uint32
869 // then it will be silently truncated. We will need to fix this if we ever
870 // decide to start supporting serialized messages greater than 2 GiB in size.
871 return length + io::CodedOutputStream::VarintSize32(
872 static_cast<uint32>(length));
872 } 873 }
873 874
874 } // namespace internal 875 } // namespace internal
875 } // namespace protobuf 876 } // namespace protobuf
876 877
877 } // namespace google 878 } // namespace google
878 #endif // GOOGLE_PROTOBUF_WIRE_FORMAT_LITE_INL_H__ 879 #endif // GOOGLE_PROTOBUF_WIRE_FORMAT_LITE_INL_H__
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698