diff options
author | Adam Cozzette <acozzette@google.com> | 2016-11-17 17:04:30 -0800 |
---|---|---|
committer | Adam Cozzette <acozzette@google.com> | 2016-11-17 17:04:30 -0800 |
commit | 5d63097fc2b7f405f53d6ca4ad3c1ebd98d80ddd (patch) | |
tree | 50d8116271f024e16334785464c794da85f3ce12 /src/google | |
parent | 5a76e633ea9b5adb215e93fdc11e1c0c08b3fc74 (diff) | |
parent | cd315dcbadc02569e145bde16e3f66c2fbb08e31 (diff) | |
download | protobuf-5d63097fc2b7f405f53d6ca4ad3c1ebd98d80ddd.tar.gz protobuf-5d63097fc2b7f405f53d6ca4ad3c1ebd98d80ddd.tar.bz2 protobuf-5d63097fc2b7f405f53d6ca4ad3c1ebd98d80ddd.zip |
Merge branch 'master' into down-integrate-with-msvc-fix
Diffstat (limited to 'src/google')
16 files changed, 166 insertions, 59 deletions
diff --git a/src/google/protobuf/arena.h b/src/google/protobuf/arena.h index f05277ed..87066507 100644 --- a/src/google/protobuf/arena.h +++ b/src/google/protobuf/arena.h @@ -83,6 +83,7 @@ inline void arena_free(void* object, size_t size) { #if defined(__GXX_DELETE_WITH_SIZE__) || defined(__cpp_sized_deallocation) ::operator delete(object, size); #else + (void)size; ::operator delete(object); #endif } diff --git a/src/google/protobuf/compiler/command_line_interface.cc b/src/google/protobuf/compiler/command_line_interface.cc index c1243272..78ceb68c 100644 --- a/src/google/protobuf/compiler/command_line_interface.cc +++ b/src/google/protobuf/compiler/command_line_interface.cc @@ -263,6 +263,12 @@ void AddDefaultProtoPaths(vector<pair<string, string> >* paths) { return; } } + +string PluginName(const string& plugin_prefix, const string& directive) { + // Assuming the directive starts with "--" and ends with "_out" or "_opt", + // strip the "--" and "_out/_opt" and add the plugin prefix. + return plugin_prefix + "gen-" + directive.substr(2, directive.size() - 6); +} } // namespace // A MultiFileErrorCollector that prints errors to stderr. @@ -1008,6 +1014,18 @@ CommandLineInterface::ParseArguments(int argc, const char* const argv[]) { return status; } + // Make sure each plugin option has a matching plugin output. + for (map<string, string>::const_iterator i = plugin_parameters_.begin(); + i != plugin_parameters_.end(); ++i) { + if (plugins_.find(i->first) == plugins_.end()) { + std::cerr << "Unknown flag: " + // strip prefix + "gen-" and add back "_opt" + << "--" + i->first.substr(plugin_prefix_.size() + 4) + "_opt" + << std::endl; + return PARSE_ARGUMENT_FAIL; + } + } + // If no --proto_path was given, use the current working directory. if (proto_path_.empty()) { // Don't use make_pair as the old/default standard library on Solaris @@ -1338,15 +1356,22 @@ CommandLineInterface::InterpretArgument(const string& name, (plugin_prefix_.empty() || !HasSuffixString(name, "_out"))) { // Check if it's a generator option flag. generator_info = FindOrNull(generators_by_option_name_, name); - if (generator_info == NULL) { - std::cerr << "Unknown flag: " << name << std::endl; - return PARSE_ARGUMENT_FAIL; - } else { + if (generator_info != NULL) { string* parameters = &generator_parameters_[generator_info->flag_name]; if (!parameters->empty()) { parameters->append(","); } parameters->append(value); + } else if (HasPrefixString(name, "--") && HasSuffixString(name, "_opt")) { + string* parameters = + &plugin_parameters_[PluginName(plugin_prefix_, name)]; + if (!parameters->empty()) { + parameters->append(","); + } + parameters->append(value); + } else { + std::cerr << "Unknown flag: " << name << std::endl; + return PARSE_ARGUMENT_FAIL; } } else { // It's an output flag. Add it to the output directives. @@ -1465,12 +1490,16 @@ bool CommandLineInterface::GenerateOutput( HasSuffixString(output_directive.name, "_out")) << "Bad name for plugin generator: " << output_directive.name; - // Strip the "--" and "_out" and add the plugin prefix. - string plugin_name = plugin_prefix_ + "gen-" + - output_directive.name.substr(2, output_directive.name.size() - 6); - + string plugin_name = PluginName(plugin_prefix_ , output_directive.name); + string parameters = output_directive.parameter; + if (!plugin_parameters_[plugin_name].empty()) { + if (!parameters.empty()) { + parameters.append(","); + } + parameters.append(plugin_parameters_[plugin_name]); + } if (!GeneratePluginOutput(parsed_files, plugin_name, - output_directive.parameter, + parameters, generator_context, &error)) { std::cerr << output_directive.name << ": " << error << std::endl; return false; diff --git a/src/google/protobuf/compiler/command_line_interface.h b/src/google/protobuf/compiler/command_line_interface.h index a1a6ab39..28471ee7 100644 --- a/src/google/protobuf/compiler/command_line_interface.h +++ b/src/google/protobuf/compiler/command_line_interface.h @@ -144,14 +144,14 @@ class LIBPROTOC_EXPORT CommandLineInterface { // plugin [--out=OUTDIR] [--parameter=PARAMETER] PROTO_FILES < DESCRIPTORS // --out indicates the output directory (as passed to the --foo_out // parameter); if omitted, the current directory should be used. --parameter - // gives the generator parameter, if any was provided. The PROTO_FILES list - // the .proto files which were given on the compiler command-line; these are - // the files for which the plugin is expected to generate output code. - // Finally, DESCRIPTORS is an encoded FileDescriptorSet (as defined in - // descriptor.proto). This is piped to the plugin's stdin. The set will - // include descriptors for all the files listed in PROTO_FILES as well as - // all files that they import. The plugin MUST NOT attempt to read the - // PROTO_FILES directly -- it must use the FileDescriptorSet. + // gives the generator parameter, if any was provided (see below). The + // PROTO_FILES list the .proto files which were given on the compiler + // command-line; these are the files for which the plugin is expected to + // generate output code. Finally, DESCRIPTORS is an encoded FileDescriptorSet + // (as defined in descriptor.proto). This is piped to the plugin's stdin. + // The set will include descriptors for all the files listed in PROTO_FILES as + // well as all files that they import. The plugin MUST NOT attempt to read + // the PROTO_FILES directly -- it must use the FileDescriptorSet. // // The plugin should generate whatever files are necessary, as code generators // normally do. It should write the names of all files it generates to @@ -159,6 +159,13 @@ class LIBPROTOC_EXPORT CommandLineInterface { // names or relative to the current directory. If any errors occur, error // messages should be written to stderr. If an error is fatal, the plugin // should exit with a non-zero exit code. + // + // Plugins can have generator parameters similar to normal built-in + // generators. Extra generator parameters can be passed in via a matching + // "_opt" parameter. For example: + // protoc --plug_out=enable_bar:outdir --plug_opt=enable_baz + // This will pass "enable_bar,enable_baz" as the parameter to the plugin. + // void AllowPlugins(const string& exe_name_prefix); // Run the Protocol Compiler with the given command-line parameters. @@ -314,6 +321,8 @@ class LIBPROTOC_EXPORT CommandLineInterface { // protoc --foo_out=outputdir --foo_opt=enable_bar ... // Then there will be an entry ("--foo_out", "enable_bar") in this map. std::map<string, string> generator_parameters_; + // Similar to generator_parameters_, but stores the parameters for plugins. + std::map<string, string> plugin_parameters_; // See AllowPlugins(). If this is empty, plugins aren't allowed. string plugin_prefix_; diff --git a/src/google/protobuf/compiler/command_line_interface_unittest.cc b/src/google/protobuf/compiler/command_line_interface_unittest.cc index 6600cc2f..d5b5b185 100644 --- a/src/google/protobuf/compiler/command_line_interface_unittest.cc +++ b/src/google/protobuf/compiler/command_line_interface_unittest.cc @@ -653,6 +653,44 @@ TEST_F(CommandLineInterfaceTest, ExtraGeneratorParameters) { "test_generator", "baz,foo1,foo2,foo3", "foo.proto", "Foo", "b"); } +TEST_F(CommandLineInterfaceTest, ExtraPluginParameters) { + // Test that generator parameters specified with the option flag are + // correctly passed to the code generator. + + CreateTempFile("foo.proto", + "syntax = \"proto2\";\n" + "message Foo {}\n"); + // Create the "a" and "b" sub-directories. + CreateTempDir("a"); + CreateTempDir("b"); + + Run("protocol_compiler " + "--plug_opt=foo1 " + "--plug_out=bar:$tmpdir/a " + "--plug_opt=foo2 " + "--plug_out=baz:$tmpdir/b " + "--plug_opt=foo3 " + "--proto_path=$tmpdir foo.proto"); + + ExpectNoErrors(); + ExpectGenerated( + "test_plugin", "bar,foo1,foo2,foo3", "foo.proto", "Foo", "a"); + ExpectGenerated( + "test_plugin", "baz,foo1,foo2,foo3", "foo.proto", "Foo", "b"); +} + +TEST_F(CommandLineInterfaceTest, UnrecognizedExtraParameters) { + CreateTempFile("foo.proto", + "syntax = \"proto2\";\n" + "message Foo {}\n"); + + Run("protocol_compiler --plug_out=TestParameter:$tmpdir " + "--unknown_plug_opt=Foo " + "--proto_path=$tmpdir foo.proto"); + + ExpectErrorSubstring("Unknown flag: --unknown_plug_opt"); +} + TEST_F(CommandLineInterfaceTest, Insert) { // Test running a generator that inserts code into another's output. diff --git a/src/google/protobuf/compiler/mock_code_generator.cc b/src/google/protobuf/compiler/mock_code_generator.cc index 156784b5..979814ec 100644 --- a/src/google/protobuf/compiler/mock_code_generator.cc +++ b/src/google/protobuf/compiler/mock_code_generator.cc @@ -61,7 +61,7 @@ namespace compiler { // comma-separated string. string CommaSeparatedList(const std::vector<const FileDescriptor*> all_files) { std::vector<string> names; - for (int i = 0; i < all_files.size(); i++) { + for (size_t i = 0; i < all_files.size(); i++) { names.push_back(all_files[i]->name()); } return Join(names, ","); @@ -98,7 +98,7 @@ void MockCodeGenerator::ExpectGenerated( while (!lines.empty() && lines.back().empty()) { lines.pop_back(); } - for (int i = 0; i < lines.size(); i++) { + for (size_t i = 0; i < lines.size(); i++) { lines[i] += "\n"; } @@ -115,7 +115,7 @@ void MockCodeGenerator::ExpectGenerated( EXPECT_EQ(kFirstInsertionPoint, lines[1 + insertion_list.size()]); EXPECT_EQ(kSecondInsertionPoint, lines[2 + insertion_list.size() * 2]); - for (int i = 0; i < insertion_list.size(); i++) { + for (size_t i = 0; i < insertion_list.size(); i++) { EXPECT_EQ(GetOutputFileContent(insertion_list[i], "first_insert", file, file, first_message_name), lines[1 + i]); @@ -171,7 +171,7 @@ bool MockCodeGenerator::Generate( SplitStringUsing(StripPrefixString(parameter, "insert="), ",", &insert_into); - for (int i = 0; i < insert_into.size(); i++) { + for (size_t i = 0; i < insert_into.size(); i++) { { google::protobuf::scoped_ptr<io::ZeroCopyOutputStream> output(context->OpenForInsert( GetOutputFileName(insert_into[i], file), kFirstInsertionPointName)); diff --git a/src/google/protobuf/compiler/php/php_generator.cc b/src/google/protobuf/compiler/php/php_generator.cc index 75ddb405..83e629b9 100644 --- a/src/google/protobuf/compiler/php/php_generator.cc +++ b/src/google/protobuf/compiler/php/php_generator.cc @@ -70,6 +70,16 @@ void GenerateEnum(const google::protobuf::EnumDescriptor* en, void Indent(google::protobuf::io::Printer* printer); void Outdent(google::protobuf::io::Printer* printer); +std::string MessagePrefix(const google::protobuf::Descriptor* message) { + // Empty cannot be php class name. + if (message->name() == "Empty" && + message->file()->package() == "google.protobuf") { + return "GPB"; + } else { + return ""; + } +} + std::string MessageName(const google::protobuf::Descriptor* message, bool is_descriptor) { string message_name = message->name(); @@ -78,6 +88,8 @@ std::string MessageName(const google::protobuf::Descriptor* message, message_name = descriptor->name() + '_' + message_name; descriptor = descriptor->containing_type(); } + message_name = MessagePrefix(message) + message_name; + return PhpName(message->file()->package(), is_descriptor) + '\\' + message_name; } @@ -483,8 +495,10 @@ void GenerateMessage(const string& name_prefix, return; } - string message_name = name_prefix.empty()? - message->name() : name_prefix + "_" + message->name(); + string message_name = + name_prefix.empty() + ? message->name() + : name_prefix + "_" + MessagePrefix(message) + message->name(); printer->Print( "class @name@ extends \\Google\\Protobuf\\Internal\\Message\n" diff --git a/src/google/protobuf/repeated_field.h b/src/google/protobuf/repeated_field.h index eaaf1795..bbdef449 100644 --- a/src/google/protobuf/repeated_field.h +++ b/src/google/protobuf/repeated_field.h @@ -686,8 +686,7 @@ inline const Message& GenericTypeHandler<Message>::default_instance() { return *null; } - -class StringTypeHandler { +class LIBPROTOBUF_EXPORT StringTypeHandler { public: typedef string Type; diff --git a/src/google/protobuf/stubs/atomicops.h b/src/google/protobuf/stubs/atomicops.h index 9b3d1e6b..10a71ed4 100644 --- a/src/google/protobuf/stubs/atomicops.h +++ b/src/google/protobuf/stubs/atomicops.h @@ -196,14 +196,22 @@ Atomic64 Release_Load(volatile const Atomic64* ptr); // Apple. #elif defined(GOOGLE_PROTOBUF_OS_APPLE) +#if __has_feature(cxx_atomic) || _GNUC_VER >= 407 +#include <google/protobuf/stubs/atomicops_internals_generic_c11_atomic.h> +#else // __has_feature(cxx_atomic) || _GNUC_VER >= 407 #include <google/protobuf/stubs/atomicops_internals_macosx.h> +#endif // __has_feature(cxx_atomic) || _GNUC_VER >= 407 // GCC. #elif defined(__GNUC__) #if defined(GOOGLE_PROTOBUF_ARCH_IA32) || defined(GOOGLE_PROTOBUF_ARCH_X64) #include <google/protobuf/stubs/atomicops_internals_x86_gcc.h> #elif defined(GOOGLE_PROTOBUF_ARCH_ARM) && defined(__linux__) +#if (((__GNUC__ == 4) && (__GNUC_MINOR__ >= 7)) || (__GNUC__ > 4)) +#include <google/protobuf/stubs/atomicops_internals_generic_gcc.h> +#else #include <google/protobuf/stubs/atomicops_internals_arm_gcc.h> +#endif #elif defined(GOOGLE_PROTOBUF_ARCH_AARCH64) #include <google/protobuf/stubs/atomicops_internals_arm64_gcc.h> #elif defined(GOOGLE_PROTOBUF_ARCH_ARM_QNX) @@ -213,7 +221,7 @@ Atomic64 Release_Load(volatile const Atomic64* ptr); #elif defined(GOOGLE_PROTOBUF_ARCH_POWER) #include <google/protobuf/stubs/atomicops_internals_power.h> #elif defined(__native_client__) -#include <google/protobuf/stubs/atomicops_internals_pnacl.h> +#include <google/protobuf/stubs/atomicops_internals_generic_c11_atomic.h> #elif defined(GOOGLE_PROTOBUF_ARCH_PPC) #include <google/protobuf/stubs/atomicops_internals_ppc_gcc.h> #elif (((__GNUC__ == 4) && (__GNUC_MINOR__ >= 7)) || (__GNUC__ > 4)) diff --git a/src/google/protobuf/stubs/atomicops_internals_pnacl.h b/src/google/protobuf/stubs/atomicops_internals_generic_c11_atomic.h index 3b314fd0..7bc584eb 100644 --- a/src/google/protobuf/stubs/atomicops_internals_pnacl.h +++ b/src/google/protobuf/stubs/atomicops_internals_generic_c11_atomic.h @@ -30,8 +30,8 @@ // This file is an internal atomic implementation, use atomicops.h instead. -#ifndef GOOGLE_PROTOBUF_ATOMICOPS_INTERNALS_PNACL_H_ -#define GOOGLE_PROTOBUF_ATOMICOPS_INTERNALS_PNACL_H_ +#ifndef GOOGLE_PROTOBUF_ATOMICOPS_INTERNALS_GENERIC_C11_ATOMIC_H_ +#define GOOGLE_PROTOBUF_ATOMICOPS_INTERNALS_GENERIC_C11_ATOMIC_H_ #include <atomic> @@ -228,4 +228,4 @@ inline Atomic64 Release_Load(volatile const Atomic64* ptr) { } // namespace protobuf } // namespace google -#endif // GOOGLE_PROTOBUF_ATOMICOPS_INTERNALS_PNACL_H_ +#endif // GOOGLE_PROTOBUF_ATOMICOPS_INTERNALS_GENERIC_C11_ATOMIC_H_ diff --git a/src/google/protobuf/stubs/atomicops_internals_generic_gcc.h b/src/google/protobuf/stubs/atomicops_internals_generic_gcc.h index 7314ee4f..7f17b30d 100644 --- a/src/google/protobuf/stubs/atomicops_internals_generic_gcc.h +++ b/src/google/protobuf/stubs/atomicops_internals_generic_gcc.h @@ -38,7 +38,7 @@ namespace internal { inline Atomic32 NoBarrier_CompareAndSwap(volatile Atomic32* ptr, Atomic32 old_value, Atomic32 new_value) { - __atomic_compare_exchange_n(ptr, &old_value, new_value, true, + __atomic_compare_exchange_n(ptr, &old_value, new_value, false, __ATOMIC_RELAXED, __ATOMIC_RELAXED); return old_value; } @@ -61,7 +61,7 @@ inline Atomic32 Barrier_AtomicIncrement(volatile Atomic32* ptr, inline Atomic32 Acquire_CompareAndSwap(volatile Atomic32* ptr, Atomic32 old_value, Atomic32 new_value) { - __atomic_compare_exchange_n(ptr, &old_value, new_value, true, + __atomic_compare_exchange_n(ptr, &old_value, new_value, false, __ATOMIC_ACQUIRE, __ATOMIC_ACQUIRE); return old_value; } @@ -69,7 +69,7 @@ inline Atomic32 Acquire_CompareAndSwap(volatile Atomic32* ptr, inline Atomic32 Release_CompareAndSwap(volatile Atomic32* ptr, Atomic32 old_value, Atomic32 new_value) { - __atomic_compare_exchange_n(ptr, &old_value, new_value, true, + __atomic_compare_exchange_n(ptr, &old_value, new_value, false, __ATOMIC_RELEASE, __ATOMIC_ACQUIRE); return old_value; } @@ -115,7 +115,7 @@ inline Atomic64 Acquire_Load(volatile const Atomic64* ptr) { inline Atomic64 Acquire_CompareAndSwap(volatile Atomic64* ptr, Atomic64 old_value, Atomic64 new_value) { - __atomic_compare_exchange_n(ptr, &old_value, new_value, true, + __atomic_compare_exchange_n(ptr, &old_value, new_value, false, __ATOMIC_ACQUIRE, __ATOMIC_ACQUIRE); return old_value; } @@ -123,7 +123,7 @@ inline Atomic64 Acquire_CompareAndSwap(volatile Atomic64* ptr, inline Atomic64 NoBarrier_CompareAndSwap(volatile Atomic64* ptr, Atomic64 old_value, Atomic64 new_value) { - __atomic_compare_exchange_n(ptr, &old_value, new_value, true, + __atomic_compare_exchange_n(ptr, &old_value, new_value, false, __ATOMIC_RELAXED, __ATOMIC_RELAXED); return old_value; } diff --git a/src/google/protobuf/stubs/platform_macros.h b/src/google/protobuf/stubs/platform_macros.h index 4ba4b348..8b7f224f 100644 --- a/src/google/protobuf/stubs/platform_macros.h +++ b/src/google/protobuf/stubs/platform_macros.h @@ -114,11 +114,11 @@ GOOGLE_PROTOBUF_PLATFORM_ERROR #undef GOOGLE_PROTOBUF_PLATFORM_ERROR -#if defined(GOOGLE_PROTOBUF_OS_ANDROID) || defined(GOOGLE_PROTOBUF_OS_IPHONE) +#if defined(GOOGLE_PROTOBUF_OS_ANDROID) || defined(GOOGLE_PROTOBUF_OS_IPHONE) || defined(__OpenBSD__) // Android ndk does not support the __thread keyword very well yet. Here // we use pthread_key_create()/pthread_getspecific()/... methods for // TLS support on android. -// iOS also does not support the __thread keyword. +// iOS and OpenBSD also do not support the __thread keyword. #define GOOGLE_PROTOBUF_NO_THREADLOCAL #endif diff --git a/src/google/protobuf/stubs/type_traits.h b/src/google/protobuf/stubs/type_traits.h index 8d48c6aa..3ab5ea7d 100644 --- a/src/google/protobuf/stubs/type_traits.h +++ b/src/google/protobuf/stubs/type_traits.h @@ -139,18 +139,10 @@ template<> struct is_integral<int> : true_type { }; template<> struct is_integral<unsigned int> : true_type { }; template<> struct is_integral<long> : true_type { }; template<> struct is_integral<unsigned long> : true_type { }; -#ifdef HAVE_LONG_LONG +#if defined(HAVE_LONG_LONG) || defined(_MSC_VER) template<> struct is_integral<long long> : true_type { }; template<> struct is_integral<unsigned long long> : true_type { }; #endif -#if defined(_MSC_VER) -// With VC, __int8, __int16, and __int32 are synonymous with standard types -// with the same size, but __int64 has not equivalent (i.e., it's neither -// long, nor long long and should be treated differnetly). -// https://msdn.microsoft.com/en-us/library/29dh1w7z.aspx -template<> struct is_integral<__int64> : true_type { }; -template<> struct is_integral<unsigned __int64> : true_type {}; -#endif template <class T> struct is_integral<const T> : is_integral<T> { }; template <class T> struct is_integral<volatile T> : is_integral<T> { }; template <class T> struct is_integral<const volatile T> : is_integral<T> { }; diff --git a/src/google/protobuf/util/internal/constants.h b/src/google/protobuf/util/internal/constants.h index e556888c..a018a09e 100644 --- a/src/google/protobuf/util/internal/constants.h +++ b/src/google/protobuf/util/internal/constants.h @@ -50,16 +50,16 @@ const char kRfc3339TimeFormat[] = "%E4Y-%m-%dT%H:%M:%S"; const char kRfc3339TimeFormatNoPadding[] = "%Y-%m-%dT%H:%M:%S"; // Minimun seconds allowed in a google.protobuf.Timestamp value. -const int64 kTimestampMinSeconds = -62135596800; +const int64 kTimestampMinSeconds = -62135596800LL; // Maximum seconds allowed in a google.protobuf.Timestamp value. -const int64 kTimestampMaxSeconds = 253402300799; +const int64 kTimestampMaxSeconds = 253402300799LL; // Minimum seconds allowed in a google.protobuf.Duration value. -const int64 kDurationMinSeconds = -315576000000; +const int64 kDurationMinSeconds = -315576000000LL; // Maximum seconds allowed in a google.protobuf.Duration value. -const int64 kDurationMaxSeconds = 315576000000; +const int64 kDurationMaxSeconds = 315576000000LL; // Nano seconds in a second. const int32 kNanosPerSecond = 1000000000; diff --git a/src/google/protobuf/util/internal/protostream_objectsource.cc b/src/google/protobuf/util/internal/protostream_objectsource.cc index 554757d0..a970dc12 100644 --- a/src/google/protobuf/util/internal/protostream_objectsource.cc +++ b/src/google/protobuf/util/internal/protostream_objectsource.cc @@ -1028,8 +1028,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( @@ -1125,3 +1128,4 @@ const string FormatNanos(uint32 nanos, bool with_trailing_zeros) { } // namespace util } // namespace protobuf } // namespace google + diff --git a/src/google/protobuf/util/internal/protostream_objectwriter.cc b/src/google/protobuf/util/internal/protostream_objectwriter.cc index 6c15e862..c37e671c 100644 --- a/src/google/protobuf/util/internal/protostream_objectwriter.cc +++ b/src/google/protobuf/util/internal/protostream_objectwriter.cc @@ -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) { @@ -1266,3 +1269,4 @@ bool ProtoStreamObjectWriter::IsStructListValue( } // namespace util } // namespace protobuf } // namespace google + diff --git a/src/google/protobuf/util/internal/utility.cc b/src/google/protobuf/util/internal/utility.cc index d74c3f3a..05759e85 100644 --- a/src/google/protobuf/util/internal/utility.cc +++ b/src/google/protobuf/util/internal/utility.cc @@ -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) { @@ -404,3 +412,4 @@ bool SafeStrToFloat(StringPiece str, float* value) { } // namespace util } // namespace protobuf } // namespace google + |