From 6ef984af4b0c63c1c33127a12dcfc8e6359f0c9e Mon Sep 17 00:00:00 2001 From: Feng Xiao Date: Mon, 10 Nov 2014 17:34:54 -0800 Subject: Down-integrate from internal code base. --- src/google/protobuf/wire_format_lite.cc | 29 +++++++++++++++++------------ 1 file changed, 17 insertions(+), 12 deletions(-) (limited to 'src/google/protobuf/wire_format_lite.cc') diff --git a/src/google/protobuf/wire_format_lite.cc b/src/google/protobuf/wire_format_lite.cc index 8de82784..c80a7050 100644 --- a/src/google/protobuf/wire_format_lite.cc +++ b/src/google/protobuf/wire_format_lite.cc @@ -291,7 +291,7 @@ bool WireFormatLite::ReadPackedEnumNoInline(io::CodedInputStream* input, int, WireFormatLite::TYPE_ENUM>(input, &value)) { return false; } - if (is_valid(value)) { + if (is_valid == NULL || is_valid(value)) { values->Add(value); } } @@ -451,19 +451,24 @@ void WireFormatLite::WriteMessageMaybeToArray(int field_number, } } -bool WireFormatLite::ReadString(io::CodedInputStream* input, - string* value) { - // String is for UTF-8 text only +static inline bool ReadBytesToString(io::CodedInputStream* input, + string* value) GOOGLE_ATTRIBUTE_ALWAYS_INLINE; +static inline bool ReadBytesToString(io::CodedInputStream* input, + string* value) { uint32 length; - if (!input->ReadVarint32(&length)) return false; - if (!input->InternalReadStringInline(value, length)) return false; - return true; + return input->ReadVarint32(&length) && + input->InternalReadStringInline(value, length); } -bool WireFormatLite::ReadBytes(io::CodedInputStream* input, - string* value) { - uint32 length; - if (!input->ReadVarint32(&length)) return false; - return input->InternalReadStringInline(value, length); + +bool WireFormatLite::ReadBytes(io::CodedInputStream* input, string* value) { + return ReadBytesToString(input, value); +} + +bool WireFormatLite::ReadBytes(io::CodedInputStream* input, string** p) { + if (*p == &::google::protobuf::internal::GetEmptyStringAlreadyInited()) { + *p = new ::std::string(); + } + return ReadBytesToString(input, *p); } } // namespace internal -- cgit v1.2.3