Index: third_party/protobuf/src/google/protobuf/wire_format.cc |
diff --git a/third_party/protobuf/src/google/protobuf/wire_format.cc b/third_party/protobuf/src/google/protobuf/wire_format.cc |
index 7021f8e5651b6ae1ebdd2cf2437e3a1d519ec7a5..21350f51a160116b8a993e929ddad3b7aa825448 100644 |
--- a/third_party/protobuf/src/google/protobuf/wire_format.cc |
+++ b/third_party/protobuf/src/google/protobuf/wire_format.cc |
@@ -1,6 +1,6 @@ |
// Protocol Buffers - Google's data interchange format |
// Copyright 2008 Google Inc. All rights reserved. |
-// https://developers.google.com/protocol-buffers/ |
+// http://code.google.com/p/protobuf/ |
// |
// Redistribution and use in source and binary forms, with or without |
// modification, are permitted provided that the following conditions are |
@@ -39,7 +39,6 @@ |
#include <google/protobuf/wire_format.h> |
#include <google/protobuf/stubs/common.h> |
-#include <google/protobuf/stubs/stringprintf.h> |
#include <google/protobuf/descriptor.h> |
#include <google/protobuf/wire_format_lite_inl.h> |
#include <google/protobuf/descriptor.pb.h> |
@@ -106,37 +105,6 @@ bool WireFormat::ParseAndMergePartial(io::CodedInputStream* input, |
} |
} |
-bool WireFormat::SkipMessageSetField(io::CodedInputStream* input, |
- uint32 field_number, |
- UnknownFieldSet* unknown_fields) { |
- uint32 length; |
- if (!input->ReadVarint32(&length)) return false; |
- return input->ReadString( |
- unknown_fields->AddLengthDelimited(field_number), length); |
-} |
- |
-bool WireFormat::ParseAndMergeMessageSetField(uint32 field_number, |
- const FieldDescriptor* field, |
- Message* message, |
- io::CodedInputStream* input) { |
- const Reflection* message_reflection = message->GetReflection(); |
- if (field == NULL) { |
- // We store unknown MessageSet extensions as groups. |
- return SkipMessageSetField( |
- input, field_number, message_reflection->MutableUnknownFields(message)); |
- } else if (field->is_repeated() || |
- field->type() != FieldDescriptor::TYPE_MESSAGE) { |
- // This shouldn't happen as we only allow optional message extensions to |
- // MessageSet. |
- GOOGLE_LOG(ERROR) << "Extensions of MessageSets must be optional messages."; |
- return false; |
- } else { |
- Message* sub_message = message_reflection->MutableMessage( |
- message, field, input->GetExtensionFactory()); |
- return WireFormatLite::ReadMessage(input, sub_message); |
- } |
-} |
- |
bool WireFormat::ParseAndMergeField( |
uint32 tag, |
const FieldDescriptor* field, // May be NULL for unknown |
@@ -205,23 +173,10 @@ bool WireFormat::ParseAndMergeField( |
int value; |
if (!WireFormatLite::ReadPrimitive<int, WireFormatLite::TYPE_ENUM>( |
input, &value)) return false; |
- if (message->GetDescriptor()->file()->syntax() == |
- FileDescriptor::SYNTAX_PROTO3) { |
- message_reflection->AddEnumValue(message, field, value); |
- } else { |
- const EnumValueDescriptor* enum_value = |
- field->enum_type()->FindValueByNumber(value); |
- if (enum_value != NULL) { |
- message_reflection->AddEnum(message, field, enum_value); |
- } else { |
- // The enum value is not one of the known values. Add it to the |
- // UnknownFieldSet. |
- int64 sign_extended_value = static_cast<int64>(value); |
- message_reflection->MutableUnknownFields(message) |
- ->AddVarint( |
- WireFormatLite::GetTagFieldNumber(tag), |
- sign_extended_value); |
- } |
+ const EnumValueDescriptor* enum_value = |
+ field->enum_type()->FindValueByNumber(value); |
+ if (enum_value != NULL) { |
+ message_reflection->AddEnum(message, field, enum_value); |
} |
} |
@@ -278,31 +233,21 @@ bool WireFormat::ParseAndMergeField( |
int value; |
if (!WireFormatLite::ReadPrimitive<int, WireFormatLite::TYPE_ENUM>( |
input, &value)) return false; |
- if (message->GetDescriptor()->file()->syntax() == |
- FileDescriptor::SYNTAX_PROTO3) { |
+ const EnumValueDescriptor* enum_value = |
+ field->enum_type()->FindValueByNumber(value); |
+ if (enum_value != NULL) { |
if (field->is_repeated()) { |
- message_reflection->AddEnumValue(message, field, value); |
+ message_reflection->AddEnum(message, field, enum_value); |
} else { |
- message_reflection->SetEnumValue(message, field, value); |
+ message_reflection->SetEnum(message, field, enum_value); |
} |
} else { |
- const EnumValueDescriptor* enum_value = |
- field->enum_type()->FindValueByNumber(value); |
- if (enum_value != NULL) { |
- if (field->is_repeated()) { |
- message_reflection->AddEnum(message, field, enum_value); |
- } else { |
- message_reflection->SetEnum(message, field, enum_value); |
- } |
- } else { |
- // The enum value is not one of the known values. Add it to the |
- // UnknownFieldSet. |
- int64 sign_extended_value = static_cast<int64>(value); |
- message_reflection->MutableUnknownFields(message) |
- ->AddVarint( |
- WireFormatLite::GetTagFieldNumber(tag), |
- sign_extended_value); |
- } |
+ // The enum value is not one of the known values. Add it to the |
+ // UnknownFieldSet. |
+ int64 sign_extended_value = static_cast<int64>(value); |
+ message_reflection->MutableUnknownFields(message) |
+ ->AddVarint(WireFormatLite::GetTagFieldNumber(tag), |
+ sign_extended_value); |
} |
break; |
} |
@@ -311,8 +256,7 @@ bool WireFormat::ParseAndMergeField( |
case FieldDescriptor::TYPE_STRING: { |
string value; |
if (!WireFormatLite::ReadString(input, &value)) return false; |
- VerifyUTF8StringNamedField(value.data(), value.length(), PARSE, |
- field->name().c_str()); |
+ VerifyUTF8String(value.data(), value.length(), PARSE); |
if (field->is_repeated()) { |
message_reflection->AddString(message, field, value); |
} else { |
@@ -376,7 +320,10 @@ bool WireFormat::ParseAndMergeMessageSetItem( |
// required int32 type_id = 2; |
// required data message = 3; |
- uint32 last_type_id = 0; |
+ // Once we see a type_id, we'll construct a fake tag for this extension |
+ // which is the tag it would have had under the proto2 extensions wire |
+ // format. |
+ uint32 fake_tag = 0; |
// Once we see a type_id, we'll look up the FieldDescriptor for the |
// extension. |
@@ -394,7 +341,8 @@ bool WireFormat::ParseAndMergeMessageSetItem( |
case WireFormatLite::kMessageSetTypeIdTag: { |
uint32 type_id; |
if (!input->ReadVarint32(&type_id)) return false; |
- last_type_id = type_id; |
+ fake_tag = WireFormatLite::MakeTag( |
+ type_id, WireFormatLite::WIRETYPE_LENGTH_DELIMITED); |
field = message_reflection->FindKnownExtensionByNumber(type_id); |
if (!message_data.empty()) { |
@@ -403,8 +351,8 @@ bool WireFormat::ParseAndMergeMessageSetItem( |
io::ArrayInputStream raw_input(message_data.data(), |
message_data.size()); |
io::CodedInputStream sub_input(&raw_input); |
- if (!ParseAndMergeMessageSetField(last_type_id, field, message, |
- &sub_input)) { |
+ if (!ParseAndMergeField(fake_tag, field, message, |
+ &sub_input)) { |
return false; |
} |
message_data.clear(); |
@@ -414,7 +362,7 @@ bool WireFormat::ParseAndMergeMessageSetItem( |
} |
case WireFormatLite::kMessageSetMessageTag: { |
- if (last_type_id == 0) { |
+ if (fake_tag == 0) { |
// We haven't seen a type_id yet. Append this data to message_data. |
string temp; |
uint32 length; |
@@ -426,8 +374,7 @@ bool WireFormat::ParseAndMergeMessageSetItem( |
coded_output.WriteString(temp); |
} else { |
// Already saw type_id, so we can parse this directly. |
- if (!ParseAndMergeMessageSetField(last_type_id, field, message, |
- input)) { |
+ if (!ParseAndMergeField(fake_tag, field, message, input)) { |
return false; |
} |
} |
@@ -440,7 +387,7 @@ bool WireFormat::ParseAndMergeMessageSetItem( |
} |
default: { |
- if (!WireFormatLite::SkipField(input, tag)) return false; |
+ if (!WireFormatLite::SkipField(input, tag, NULL)) return false; |
} |
} |
} |
@@ -497,7 +444,7 @@ void WireFormat::SerializeFieldWithCachedSizes( |
count = 1; |
} |
- const bool is_packed = field->is_packed(); |
+ const bool is_packed = field->options().packed(); |
if (is_packed && count > 0) { |
WireFormatLite::WriteTag(field->number(), |
WireFormatLite::WIRETYPE_LENGTH_DELIMITED, output); |
@@ -575,8 +522,7 @@ void WireFormat::SerializeFieldWithCachedSizes( |
message_reflection->GetRepeatedStringReference( |
message, field, j, &scratch) : |
message_reflection->GetStringReference(message, field, &scratch); |
- VerifyUTF8StringNamedField(value.data(), value.length(), SERIALIZE, |
- field->name().c_str()); |
+ VerifyUTF8String(value.data(), value.length(), SERIALIZE); |
WireFormatLite::WriteString(field->number(), value, output); |
break; |
} |
@@ -664,7 +610,7 @@ int WireFormat::FieldByteSize( |
const int data_size = FieldDataOnlyByteSize(field, message); |
int our_size = data_size; |
- if (field->is_packed()) { |
+ if (field->options().packed()) { |
if (data_size > 0) { |
// Packed fields get serialized like a string, not their native type. |
// Technically this doesn't really matter; the size only changes if it's |
@@ -786,8 +732,7 @@ int WireFormat::MessageSetItemByteSize( |
void WireFormat::VerifyUTF8StringFallback(const char* data, |
int size, |
- Operation op, |
- const char* field_name) { |
+ Operation op) { |
if (!IsStructurallyValidUTF8(data, size)) { |
const char* operation_str = NULL; |
switch (op) { |
@@ -799,15 +744,10 @@ void WireFormat::VerifyUTF8StringFallback(const char* data, |
break; |
// no default case: have the compiler warn if a case is not covered. |
} |
- string quoted_field_name = ""; |
- if (field_name != NULL) { |
- quoted_field_name = StringPrintf(" '%s'", field_name); |
- } |
- // no space below to avoid double space when the field name is missing. |
- GOOGLE_LOG(ERROR) << "String field" << quoted_field_name << " contains invalid " |
- << "UTF-8 data when " << operation_str << " a protocol " |
- << "buffer. Use the 'bytes' type if you intend to send raw " |
- << "bytes. "; |
+ GOOGLE_LOG(ERROR) << "String field contains invalid UTF-8 data when " |
+ << operation_str |
+ << " a protocol buffer. Use the 'bytes' type if you intend to " |
+ "send raw bytes."; |
} |
} |