| Index: third_party/protobuf/src/google/protobuf/util/internal/protostream_objectsource.cc
|
| diff --git a/third_party/protobuf/src/google/protobuf/util/internal/protostream_objectsource.cc b/third_party/protobuf/src/google/protobuf/util/internal/protostream_objectsource.cc
|
| index 1f3781a4b48fc68ed4e9566a90798a33c06c8ea9..df0dbe1b14e64833b5f8ae857ec4d96d7a609a53 100644
|
| --- a/third_party/protobuf/src/google/protobuf/util/internal/protostream_objectsource.cc
|
| +++ b/third_party/protobuf/src/google/protobuf/util/internal/protostream_objectsource.cc
|
| @@ -121,7 +121,8 @@ ProtoStreamObjectSource::ProtoStreamObjectSource(
|
| type_(type),
|
| use_lower_camel_for_enums_(false),
|
| recursion_depth_(0),
|
| - max_recursion_depth_(kDefaultMaxRecursionDepth) {
|
| + max_recursion_depth_(kDefaultMaxRecursionDepth),
|
| + render_unknown_fields_(false) {
|
| GOOGLE_LOG_IF(DFATAL, stream == NULL) << "Input stream is NULL.";
|
| }
|
|
|
| @@ -134,7 +135,8 @@ ProtoStreamObjectSource::ProtoStreamObjectSource(
|
| type_(type),
|
| use_lower_camel_for_enums_(false),
|
| recursion_depth_(0),
|
| - max_recursion_depth_(kDefaultMaxRecursionDepth) {
|
| + max_recursion_depth_(kDefaultMaxRecursionDepth),
|
| + render_unknown_fields_(false) {
|
| GOOGLE_LOG_IF(DFATAL, stream == NULL) << "Input stream is NULL.";
|
| }
|
|
|
| @@ -184,6 +186,7 @@ Status ProtoStreamObjectSource::WriteMessage(const google::protobuf::Type& type,
|
| string field_name;
|
| // last_tag set to dummy value that is different from tag.
|
| uint32 tag = stream_->ReadTag(), last_tag = tag + 1;
|
| + google::protobuf::UnknownFieldSet unknown_fields;
|
|
|
| if (include_start_and_end) {
|
| ow->StartObject(name);
|
| @@ -199,7 +202,8 @@ Status ProtoStreamObjectSource::WriteMessage(const google::protobuf::Type& type,
|
| if (field == NULL) {
|
| // If we didn't find a field, skip this unknown tag.
|
| // TODO(wpoon): Check return boolean value.
|
| - WireFormat::SkipField(stream_, tag, NULL);
|
| + WireFormat::SkipField(stream_, tag,
|
| + render_unknown_fields_ ? &unknown_fields : NULL);
|
| tag = stream_->ReadTag();
|
| continue;
|
| }
|
| @@ -221,6 +225,8 @@ Status ProtoStreamObjectSource::WriteMessage(const google::protobuf::Type& type,
|
| tag = stream_->ReadTag();
|
| }
|
| }
|
| +
|
| +
|
| if (include_start_and_end) {
|
| ow->EndObject();
|
| }
|
| @@ -282,6 +288,8 @@ StatusOr<uint32> ProtoStreamObjectSource::RenderMap(
|
| return Status(util::error::INTERNAL, "Invalid map entry.");
|
| }
|
| ASSIGN_OR_RETURN(map_key, MapKeyDefaultValueAsString(*key_field));
|
| + // Key is empty, force it to render as empty (for string values).
|
| + ow->empty_name_ok_for_next_key();
|
| }
|
| RETURN_IF_ERROR(RenderField(field, map_key, ow));
|
| } else {
|
| @@ -851,7 +859,8 @@ Status ProtoStreamObjectSource::RenderNonMessageField(
|
| // up.
|
| const google::protobuf::Enum* en =
|
| typeinfo_->GetEnumByTypeUrl(field->type_url());
|
| - // Lookup the name of the enum, and render that. Skips unknown enums.
|
| + // Lookup the name of the enum, and render that. Unknown enum values
|
| + // are printed as integers.
|
| if (en != NULL) {
|
| const google::protobuf::EnumValue* enum_value =
|
| FindEnumValueByNumber(*en, buffer32);
|
| @@ -860,9 +869,11 @@ Status ProtoStreamObjectSource::RenderNonMessageField(
|
| ow->RenderString(field_name, ToCamelCase(enum_value->name()));
|
| else
|
| ow->RenderString(field_name, enum_value->name());
|
| + } else {
|
| + ow->RenderInt32(field_name, buffer32);
|
| }
|
| } else {
|
| - GOOGLE_LOG(INFO) << "Unknown enum skipped: " << field->type_url();
|
| + ow->RenderInt32(field_name, buffer32);
|
| }
|
| break;
|
| }
|
| @@ -1013,8 +1024,11 @@ bool ProtoStreamObjectSource::IsMap(
|
| // TODO(xiaofeng): Unify option names.
|
| return field.kind() == google::protobuf::Field_Kind_TYPE_MESSAGE &&
|
| (GetBoolOptionOrDefault(field_type->options(),
|
| - "google.protobuf.MessageOptions.map_entry", false) ||
|
| - GetBoolOptionOrDefault(field_type->options(), "map_entry", false));
|
| + "google.protobuf.MessageOptions.map_entry",
|
| + false) ||
|
| + GetBoolOptionOrDefault(field_type->options(), "map_entry", false) ||
|
| + GetBoolOptionOrDefault(field_type->options(),
|
| + "proto2.MessageOptions.map_entry", false));
|
| }
|
|
|
| std::pair<int64, int32> ProtoStreamObjectSource::ReadSecondsAndNanos(
|
| @@ -1093,6 +1107,8 @@ const google::protobuf::EnumValue* FindEnumValueByNumber(
|
| // TODO(skarvaje): Look into optimizing this by not doing computation on
|
| // double.
|
| const string FormatNanos(uint32 nanos) {
|
| + if (nanos == 0) return "";
|
| +
|
| const char* format =
|
| (nanos % 1000 != 0) ? "%.9f" : (nanos % 1000000 != 0) ? "%.6f" : "%.3f";
|
| string formatted =
|
| @@ -1106,3 +1122,4 @@ const string FormatNanos(uint32 nanos) {
|
| } // namespace util
|
| } // namespace protobuf
|
| } // namespace google
|
| +
|
|
|