My favorites | Sign in
Project Home Downloads Wiki Issues Source
New issue   Search
for
  Advanced search   Search tips   Subscriptions

Issue 341 attachment: protobuff.packed_rfield.diff (1.6 KB)

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
diff --git a/src/google/protobuf/wire_format_lite_inl.h b/src/google/protobuf/wire_format_lite_inl.h
index 103b0bd..96b15b9 100644
--- a/src/google/protobuf/wire_format_lite_inl.h
+++ b/src/google/protobuf/wire_format_lite_inl.h
@@ -322,16 +322,24 @@ bool WireFormatLite::ReadRepeatedPrimitiveNoInline(
template <typename CType, enum WireFormatLite::FieldType DeclaredType>
inline bool WireFormatLite::ReadPackedPrimitive(io::CodedInputStream* input,
RepeatedField<CType>* values) {
- uint32 length;
- if (!input->ReadVarint32(&length)) return false;
- io::CodedInputStream::Limit limit = input->PushLimit(length);
- while (input->BytesUntilLimit() > 0) {
- CType value;
- if (!ReadPrimitive<CType, DeclaredType>(input, &value)) return false;
- values->Add(value);
- }
- input->PopLimit(limit);
- return true;
+ uint32 length;
+ if( !input->ReadVarint32( &length ) ) return false;
+ //stay on the safe side, though as far as I know the encoder never serializes an empty array.
+ if( 0 == length ) return true;
+
+ const io::CodedInputStream::Limit limit = input->PushLimit( length );
+
+ const void *buff( NULL );
+ int buff_length( 0 );
+
+ do{
+ if( !WireFormatLite::ReadPrimitive< CType, DeclaredType >( input, values->Add() ) ){
+ return false;
+ }
+ input->GetDirectBufferPointerInline( &buff, &buff_length );
+ } while( ( 0 != buff_length ) || ( 0 != input->BytesUntilLimit() ) );
+ input->PopLimit( limit );
+ return true;
}

template <typename CType, enum WireFormatLite::FieldType DeclaredType>
Powered by Google Project Hosting