Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(10)

Unified Diff: third_party/protobuf/src/google/protobuf/util/internal/protostream_objectsource.cc

Issue 2590803003: Revert "third_party/protobuf: Update to HEAD (83d681ee2c)" (Closed)
Patch Set: Created 4 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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 a970dc120f703d3457634142fa39021be34493be..1f3781a4b48fc68ed4e9566a90798a33c06c8ea9 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
@@ -85,7 +85,7 @@ const google::protobuf::EnumValue* FindEnumValueByNumber(
const google::protobuf::Enum& tech_enum, int number);
// Utility function to format nanos.
-const string FormatNanos(uint32 nanos, bool with_trailing_zeros);
+const string FormatNanos(uint32 nanos);
StatusOr<string> MapKeyDefaultValueAsString(
const google::protobuf::Field& field) {
@@ -121,9 +121,7 @@ ProtoStreamObjectSource::ProtoStreamObjectSource(
type_(type),
use_lower_camel_for_enums_(false),
recursion_depth_(0),
- max_recursion_depth_(kDefaultMaxRecursionDepth),
- render_unknown_fields_(false),
- add_trailing_zeros_for_timestamp_and_duration_(false) {
+ max_recursion_depth_(kDefaultMaxRecursionDepth) {
GOOGLE_LOG_IF(DFATAL, stream == NULL) << "Input stream is NULL.";
}
@@ -136,9 +134,7 @@ ProtoStreamObjectSource::ProtoStreamObjectSource(
type_(type),
use_lower_camel_for_enums_(false),
recursion_depth_(0),
- max_recursion_depth_(kDefaultMaxRecursionDepth),
- render_unknown_fields_(false),
- add_trailing_zeros_for_timestamp_and_duration_(false) {
+ max_recursion_depth_(kDefaultMaxRecursionDepth) {
GOOGLE_LOG_IF(DFATAL, stream == NULL) << "Input stream is NULL.";
}
@@ -188,7 +184,6 @@ 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);
@@ -204,8 +199,7 @@ 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,
- render_unknown_fields_ ? &unknown_fields : NULL);
+ WireFormat::SkipField(stream_, tag, NULL);
tag = stream_->ReadTag();
continue;
}
@@ -227,8 +221,6 @@ Status ProtoStreamObjectSource::WriteMessage(const google::protobuf::Type& type,
tag = stream_->ReadTag();
}
}
-
-
if (include_start_and_end) {
ow->EndObject();
}
@@ -290,8 +282,6 @@ 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 {
@@ -320,7 +310,7 @@ Status ProtoStreamObjectSource::RenderPacked(
Status ProtoStreamObjectSource::RenderTimestamp(
const ProtoStreamObjectSource* os, const google::protobuf::Type& type,
StringPiece field_name, ObjectWriter* ow) {
- std::pair<int64, int32> p = os->ReadSecondsAndNanos(type);
+ pair<int64, int32> p = os->ReadSecondsAndNanos(type);
int64 seconds = p.first;
int32 nanos = p.second;
if (seconds > kTimestampMaxSeconds || seconds < kTimestampMinSeconds) {
@@ -344,7 +334,7 @@ Status ProtoStreamObjectSource::RenderTimestamp(
Status ProtoStreamObjectSource::RenderDuration(
const ProtoStreamObjectSource* os, const google::protobuf::Type& type,
StringPiece field_name, ObjectWriter* ow) {
- std::pair<int64, int32> p = os->ReadSecondsAndNanos(type);
+ pair<int64, int32> p = os->ReadSecondsAndNanos(type);
int64 seconds = p.first;
int32 nanos = p.second;
if (seconds > kDurationMaxSeconds || seconds < kDurationMinSeconds) {
@@ -374,10 +364,8 @@ Status ProtoStreamObjectSource::RenderDuration(
sign = "-";
nanos = -nanos;
}
- string formatted_duration = StringPrintf(
- "%s%lld%ss", sign.c_str(), seconds,
- FormatNanos(nanos, os->add_trailing_zeros_for_timestamp_and_duration_)
- .c_str());
+ string formatted_duration = StringPrintf("%s%lld%ss", sign.c_str(), seconds,
+ FormatNanos(nanos).c_str());
ow->RenderString(field_name, formatted_duration);
return Status::OK;
}
@@ -863,8 +851,7 @@ Status ProtoStreamObjectSource::RenderNonMessageField(
// up.
const google::protobuf::Enum* en =
typeinfo_->GetEnumByTypeUrl(field->type_url());
- // Lookup the name of the enum, and render that. Unknown enum values
- // are printed as integers.
+ // Lookup the name of the enum, and render that. Skips unknown enums.
if (en != NULL) {
const google::protobuf::EnumValue* enum_value =
FindEnumValueByNumber(*en, buffer32);
@@ -873,11 +860,9 @@ 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 {
- ow->RenderInt32(field_name, buffer32);
+ GOOGLE_LOG(INFO) << "Unknown enum skipped: " << field->type_url();
}
break;
}
@@ -1028,11 +1013,8 @@ 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) ||
- GetBoolOptionOrDefault(field_type->options(),
- "proto2.MessageOptions.map_entry", false));
+ "google.protobuf.MessageOptions.map_entry", false) ||
+ GetBoolOptionOrDefault(field_type->options(), "map_entry", false));
}
std::pair<int64, int32> ProtoStreamObjectSource::ReadSecondsAndNanos(
@@ -1110,11 +1092,7 @@ const google::protobuf::EnumValue* FindEnumValueByNumber(
// TODO(skarvaje): Look into optimizing this by not doing computation on
// double.
-const string FormatNanos(uint32 nanos, bool with_trailing_zeros) {
- if (nanos == 0) {
- return with_trailing_zeros ? ".000" : "";
- }
-
+const string FormatNanos(uint32 nanos) {
const char* format =
(nanos % 1000 != 0) ? "%.9f" : (nanos % 1000000 != 0) ? "%.6f" : "%.3f";
string formatted =
@@ -1128,4 +1106,3 @@ const string FormatNanos(uint32 nanos, bool with_trailing_zeros) {
} // namespace util
} // namespace protobuf
} // namespace google
-

Powered by Google App Engine
This is Rietveld 408576698