Commit fce8b6b9 authored by guptasu's avatar guptasu

Made helper code also consider package name 'proto2' when dealing with MessageOptions.

This is done so that the same library can be used irrespective of whether MessageOptions belong to package name 'proto2' or 'google.protobuf'
parent ce5160b8
...@@ -1024,8 +1024,11 @@ bool ProtoStreamObjectSource::IsMap( ...@@ -1024,8 +1024,11 @@ bool ProtoStreamObjectSource::IsMap(
// TODO(xiaofeng): Unify option names. // TODO(xiaofeng): Unify option names.
return field.kind() == google::protobuf::Field_Kind_TYPE_MESSAGE && return field.kind() == google::protobuf::Field_Kind_TYPE_MESSAGE &&
(GetBoolOptionOrDefault(field_type->options(), (GetBoolOptionOrDefault(field_type->options(),
"google.protobuf.MessageOptions.map_entry", false) || "google.protobuf.MessageOptions.map_entry",
GetBoolOptionOrDefault(field_type->options(), "map_entry", false)); false) ||
GetBoolOptionOrDefault(field_type->options(), "map_entry", false) ||
GetBoolOptionOrDefault(field_type->options(),
"proto2.MessageOptions.map_entry", false));
} }
std::pair<int64, int32> ProtoStreamObjectSource::ReadSecondsAndNanos( std::pair<int64, int32> ProtoStreamObjectSource::ReadSecondsAndNanos(
...@@ -1119,3 +1122,4 @@ const string FormatNanos(uint32 nanos) { ...@@ -1119,3 +1122,4 @@ const string FormatNanos(uint32 nanos) {
} // namespace util } // namespace util
} // namespace protobuf } // namespace protobuf
} // namespace google } // namespace google
...@@ -1240,8 +1240,11 @@ bool ProtoStreamObjectWriter::IsMap(const google::protobuf::Field& field) { ...@@ -1240,8 +1240,11 @@ bool ProtoStreamObjectWriter::IsMap(const google::protobuf::Field& field) {
// TODO(xiaofeng): Unify option names. // TODO(xiaofeng): Unify option names.
return GetBoolOptionOrDefault(field_type->options(), return GetBoolOptionOrDefault(field_type->options(),
"google.protobuf.MessageOptions.map_entry", false) || "google.protobuf.MessageOptions.map_entry",
GetBoolOptionOrDefault(field_type->options(), "map_entry", false); 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) { bool ProtoStreamObjectWriter::IsAny(const google::protobuf::Field& field) {
...@@ -1266,3 +1269,4 @@ bool ProtoStreamObjectWriter::IsStructListValue( ...@@ -1266,3 +1269,4 @@ bool ProtoStreamObjectWriter::IsStructListValue(
} // namespace util } // namespace util
} // namespace protobuf } // namespace protobuf
} // namespace google } // namespace google
...@@ -356,15 +356,23 @@ bool IsValidBoolString(const string& bool_string) { ...@@ -356,15 +356,23 @@ bool IsValidBoolString(const string& bool_string) {
bool IsMap(const google::protobuf::Field& field, bool IsMap(const google::protobuf::Field& field,
const google::protobuf::Type& type) { const google::protobuf::Type& type) {
return (field.cardinality() == return (
google::protobuf::Field_Cardinality_CARDINALITY_REPEATED && field.cardinality() ==
GetBoolOptionOrDefault(type.options(), google::protobuf::Field_Cardinality_CARDINALITY_REPEATED &&
"google.protobuf.MessageOptions.map_entry", false)); (GetBoolOptionOrDefault(
type.options(), "google.protobuf.MessageOptions.map_entry", false) ||
GetBoolOptionOrDefault(type.options(), "proto2.MessageOptions.map_entry",
false)));
} }
bool IsMessageSetWireFormat(const google::protobuf::Type& type) { bool IsMessageSetWireFormat(const google::protobuf::Type& type) {
return GetBoolOptionOrDefault( return (
type.options(), "google.protobuf.MessageOptions.message_set_wire_format", false); 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) { string DoubleAsString(double value) {
...@@ -404,3 +412,4 @@ bool SafeStrToFloat(StringPiece str, float* value) { ...@@ -404,3 +412,4 @@ bool SafeStrToFloat(StringPiece str, float* value) {
} // namespace util } // namespace util
} // namespace protobuf } // namespace protobuf
} // namespace google } // namespace google
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment