OLD | NEW |
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 256 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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 int elements_available = min(values->Capacity() - values->size(), | 277 int elements_available = |
278 size / per_value_size); | 278 std::min(values->Capacity() - values->size(), size / per_value_size); |
279 int num_read = 0; | 279 int num_read = 0; |
280 while (num_read < elements_available && | 280 while (num_read < elements_available && |
281 (buffer = io::CodedInputStream::ExpectTagFromArray( | 281 (buffer = io::CodedInputStream::ExpectTagFromArray( |
282 buffer, tag)) != NULL) { | 282 buffer, tag)) != NULL) { |
283 buffer = ReadPrimitiveFromArray<CType, DeclaredType>(buffer, &value); | 283 buffer = ReadPrimitiveFromArray<CType, DeclaredType>(buffer, &value); |
284 values->AddAlreadyReserved(value); | 284 values->AddAlreadyReserved(value); |
285 ++num_read; | 285 ++num_read; |
286 } | 286 } |
287 const int read_bytes = num_read * per_value_size; | 287 const int read_bytes = num_read * per_value_size; |
288 if (read_bytes > 0) { | 288 if (read_bytes > 0) { |
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
360 // TotalBytesLimit Limit | 360 // TotalBytesLimit Limit |
361 // -1 -1 Use slow path. | 361 // -1 -1 Use slow path. |
362 // -1 >= 0 Use fast path if length <= Limit. | 362 // -1 >= 0 Use fast path if length <= Limit. |
363 // >= 0 -1 Use slow path. | 363 // >= 0 -1 Use slow path. |
364 // >= 0 >= 0 Use fast path if length <= min(both limits). | 364 // >= 0 >= 0 Use fast path if length <= min(both limits). |
365 int64 bytes_limit = input->BytesUntilTotalBytesLimit(); | 365 int64 bytes_limit = input->BytesUntilTotalBytesLimit(); |
366 if (bytes_limit == -1) { | 366 if (bytes_limit == -1) { |
367 bytes_limit = input->BytesUntilLimit(); | 367 bytes_limit = input->BytesUntilLimit(); |
368 } else { | 368 } else { |
369 bytes_limit = | 369 bytes_limit = |
370 min(bytes_limit, static_cast<int64>(input->BytesUntilLimit())); | 370 std::min(bytes_limit, static_cast<int64>(input->BytesUntilLimit())); |
371 } | 371 } |
372 if (bytes_limit >= new_bytes) { | 372 if (bytes_limit >= new_bytes) { |
373 // Fast-path that pre-allocates *values to the final size. | 373 // Fast-path that pre-allocates *values to the final size. |
374 #if defined(PROTOBUF_LITTLE_ENDIAN) | 374 #if defined(PROTOBUF_LITTLE_ENDIAN) |
375 values->Resize(old_entries + new_entries, 0); | 375 values->Resize(old_entries + new_entries, 0); |
376 // values->mutable_data() may change after Resize(), so do this after: | 376 // values->mutable_data() may change after Resize(), so do this after: |
377 void* dest = reinterpret_cast<void*>(values->mutable_data() + old_entries); | 377 void* dest = reinterpret_cast<void*>(values->mutable_data() + old_entries); |
378 if (!input->ReadRaw(dest, new_bytes)) { | 378 if (!input->ReadRaw(dest, new_bytes)) { |
379 values->Truncate(old_entries); | 379 values->Truncate(old_entries); |
380 return false; | 380 return false; |
(...skipping 24 matching lines...) Expand all Loading... |
405 #define READ_REPEATED_PACKED_FIXED_SIZE_PRIMITIVE(CPPTYPE, DECLARED_TYPE) \ | 405 #define READ_REPEATED_PACKED_FIXED_SIZE_PRIMITIVE(CPPTYPE, DECLARED_TYPE) \ |
406 template <> \ | 406 template <> \ |
407 inline bool WireFormatLite::ReadPackedPrimitive< \ | 407 inline bool WireFormatLite::ReadPackedPrimitive< \ |
408 CPPTYPE, WireFormatLite::DECLARED_TYPE>( \ | 408 CPPTYPE, WireFormatLite::DECLARED_TYPE>( \ |
409 io::CodedInputStream* input, \ | 409 io::CodedInputStream* input, \ |
410 RepeatedField<CPPTYPE>* values) { \ | 410 RepeatedField<CPPTYPE>* values) { \ |
411 return ReadPackedFixedSizePrimitive< \ | 411 return ReadPackedFixedSizePrimitive< \ |
412 CPPTYPE, WireFormatLite::DECLARED_TYPE>(input, values); \ | 412 CPPTYPE, WireFormatLite::DECLARED_TYPE>(input, values); \ |
413 } | 413 } |
414 | 414 |
415 READ_REPEATED_PACKED_FIXED_SIZE_PRIMITIVE(uint32, TYPE_FIXED32); | 415 READ_REPEATED_PACKED_FIXED_SIZE_PRIMITIVE(uint32, TYPE_FIXED32) |
416 READ_REPEATED_PACKED_FIXED_SIZE_PRIMITIVE(uint64, TYPE_FIXED64); | 416 READ_REPEATED_PACKED_FIXED_SIZE_PRIMITIVE(uint64, TYPE_FIXED64) |
417 READ_REPEATED_PACKED_FIXED_SIZE_PRIMITIVE(int32, TYPE_SFIXED32); | 417 READ_REPEATED_PACKED_FIXED_SIZE_PRIMITIVE(int32, TYPE_SFIXED32) |
418 READ_REPEATED_PACKED_FIXED_SIZE_PRIMITIVE(int64, TYPE_SFIXED64); | 418 READ_REPEATED_PACKED_FIXED_SIZE_PRIMITIVE(int64, TYPE_SFIXED64) |
419 READ_REPEATED_PACKED_FIXED_SIZE_PRIMITIVE(float, TYPE_FLOAT); | 419 READ_REPEATED_PACKED_FIXED_SIZE_PRIMITIVE(float, TYPE_FLOAT) |
420 READ_REPEATED_PACKED_FIXED_SIZE_PRIMITIVE(double, TYPE_DOUBLE); | 420 READ_REPEATED_PACKED_FIXED_SIZE_PRIMITIVE(double, TYPE_DOUBLE) |
421 | 421 |
422 #undef READ_REPEATED_PACKED_FIXED_SIZE_PRIMITIVE | 422 #undef READ_REPEATED_PACKED_FIXED_SIZE_PRIMITIVE |
423 | 423 |
424 template <typename CType, enum WireFormatLite::FieldType DeclaredType> | 424 template <typename CType, enum WireFormatLite::FieldType DeclaredType> |
425 bool WireFormatLite::ReadPackedPrimitiveNoInline(io::CodedInputStream* input, | 425 bool WireFormatLite::ReadPackedPrimitiveNoInline(io::CodedInputStream* input, |
426 RepeatedField<CType>* values) { | 426 RepeatedField<CType>* values) { |
427 return ReadPackedPrimitive<CType, DeclaredType>(input, values); | 427 return ReadPackedPrimitive<CType, DeclaredType>(input, values); |
428 } | 428 } |
429 | 429 |
430 | 430 |
(...skipping 438 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
869 | 869 |
870 inline int WireFormatLite::LengthDelimitedSize(int length) { | 870 inline int WireFormatLite::LengthDelimitedSize(int length) { |
871 return io::CodedOutputStream::VarintSize32(length) + length; | 871 return io::CodedOutputStream::VarintSize32(length) + length; |
872 } | 872 } |
873 | 873 |
874 } // namespace internal | 874 } // namespace internal |
875 } // namespace protobuf | 875 } // namespace protobuf |
876 | 876 |
877 } // namespace google | 877 } // namespace google |
878 #endif // GOOGLE_PROTOBUF_WIRE_FORMAT_LITE_INL_H__ | 878 #endif // GOOGLE_PROTOBUF_WIRE_FORMAT_LITE_INL_H__ |
OLD | NEW |