Skip to content

Commit

Permalink
Merge pull request protocolbuffers#2353 from guptasu/master
Browse files Browse the repository at this point in the history
MessageOptions should handle both proto2 and google.protobuf package names.
  • Loading branch information
xfxyjwf authored Nov 11, 2016
2 parents df56736 + fce8b6b commit 8a4b2c5
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 10 deletions.
8 changes: 6 additions & 2 deletions src/google/protobuf/util/internal/protostream_objectsource.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1024,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(
Expand Down Expand Up @@ -1119,3 +1122,4 @@ const string FormatNanos(uint32 nanos) {
} // namespace util
} // namespace protobuf
} // namespace google

8 changes: 6 additions & 2 deletions src/google/protobuf/util/internal/protostream_objectwriter.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1240,8 +1240,11 @@ bool ProtoStreamObjectWriter::IsMap(const google::protobuf::Field& field) {

// TODO(xiaofeng): Unify option names.
return 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);
}

bool ProtoStreamObjectWriter::IsAny(const google::protobuf::Field& field) {
Expand All @@ -1266,3 +1269,4 @@ bool ProtoStreamObjectWriter::IsStructListValue(
} // namespace util
} // namespace protobuf
} // namespace google

21 changes: 15 additions & 6 deletions src/google/protobuf/util/internal/utility.cc
Original file line number Diff line number Diff line change
Expand Up @@ -356,15 +356,23 @@ bool IsValidBoolString(const string& bool_string) {

bool IsMap(const google::protobuf::Field& field,
const google::protobuf::Type& type) {
return (field.cardinality() ==
google::protobuf::Field_Cardinality_CARDINALITY_REPEATED &&
GetBoolOptionOrDefault(type.options(),
"google.protobuf.MessageOptions.map_entry", false));
return (
field.cardinality() ==
google::protobuf::Field_Cardinality_CARDINALITY_REPEATED &&
(GetBoolOptionOrDefault(
type.options(), "google.protobuf.MessageOptions.map_entry", false) ||
GetBoolOptionOrDefault(type.options(), "proto2.MessageOptions.map_entry",
false)));
}

bool IsMessageSetWireFormat(const google::protobuf::Type& type) {
return GetBoolOptionOrDefault(
type.options(), "google.protobuf.MessageOptions.message_set_wire_format", false);
return (
GetBoolOptionOrDefault(
type.options(),
"google.protobuf.MessageOptions.message_set_wire_format", false) ||
GetBoolOptionOrDefault(type.options(),
"proto2.MessageOptions.message_set_wire_format",
false));
}

string DoubleAsString(double value) {
Expand Down Expand Up @@ -404,3 +412,4 @@ bool SafeStrToFloat(StringPiece str, float* value) {
} // namespace util
} // namespace protobuf
} // namespace google

0 comments on commit 8a4b2c5

Please sign in to comment.