aboutsummaryrefslogtreecommitdiffhomepage
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/Makefile.am21
-rw-r--r--src/google/protobuf/any.pb.cc6
-rw-r--r--src/google/protobuf/api.pb.cc6
-rw-r--r--src/google/protobuf/compiler/cpp/cpp_file.cc6
-rw-r--r--src/google/protobuf/compiler/cpp/cpp_message.cc2
-rw-r--r--src/google/protobuf/compiler/csharp/csharp_helpers.cc2
-rw-r--r--src/google/protobuf/compiler/java/java_enum_field.cc8
-rw-r--r--src/google/protobuf/compiler/java/java_lazy_message_field.cc5
-rw-r--r--src/google/protobuf/compiler/java/java_message_field.cc23
-rw-r--r--src/google/protobuf/compiler/java/java_primitive_field.cc22
-rw-r--r--src/google/protobuf/compiler/java/java_string_field.cc8
-rw-r--r--src/google/protobuf/compiler/js/embed.cc110
-rwxr-xr-xsrc/google/protobuf/compiler/js/js_generator.cc3
-rw-r--r--src/google/protobuf/compiler/js/well_known_types_embed.cc225
-rw-r--r--src/google/protobuf/compiler/plugin.pb.cc6
-rw-r--r--src/google/protobuf/descriptor.cc14
-rw-r--r--src/google/protobuf/descriptor.pb.cc60
-rw-r--r--src/google/protobuf/duration.pb.cc6
-rw-r--r--src/google/protobuf/empty.pb.cc6
-rw-r--r--src/google/protobuf/field_mask.pb.cc6
-rw-r--r--src/google/protobuf/generated_message_util.h4
-rw-r--r--src/google/protobuf/message_lite.cc6
-rw-r--r--src/google/protobuf/source_context.pb.cc6
-rw-r--r--src/google/protobuf/struct.pb.cc6
-rw-r--r--src/google/protobuf/stubs/int128.cc52
-rw-r--r--src/google/protobuf/stubs/mutex.h20
-rw-r--r--src/google/protobuf/stubs/platform_macros.h6
-rw-r--r--src/google/protobuf/timestamp.pb.cc6
-rw-r--r--src/google/protobuf/type.pb.cc6
-rw-r--r--src/google/protobuf/util/internal/proto_writer.h2
-rw-r--r--src/google/protobuf/util/internal/protostream_objectsource.cc7
-rw-r--r--src/google/protobuf/util/internal/protostream_objectsource_test.cc78
-rw-r--r--src/google/protobuf/util/internal/protostream_objectwriter.cc2
-rw-r--r--src/google/protobuf/util/internal/protostream_objectwriter_test.cc16
-rw-r--r--src/google/protobuf/util/internal/testdata/books.proto3
-rw-r--r--src/google/protobuf/util/internal/testdata/maps.proto3
-rw-r--r--src/google/protobuf/util/json_util.cc3
-rw-r--r--src/google/protobuf/util/json_util_test.cc2
-rw-r--r--src/google/protobuf/wrappers.pb.cc6
39 files changed, 507 insertions, 272 deletions
diff --git a/src/Makefile.am b/src/Makefile.am
index fb247300..09ab76f7 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -56,9 +56,7 @@ clean-local:
CLEANFILES = $(protoc_outputs) unittest_proto_middleman \
testzip.jar testzip.list testzip.proto testzip.zip \
- no_warning_test.cc \
- google/protobuf/compiler/js/well_known_types_embed.cc \
- js_embed$(EXEEXT)
+ no_warning_test.cc
MAINTAINERCLEANFILES = \
Makefile.in
@@ -471,22 +469,6 @@ bin_PROGRAMS = protoc
protoc_LDADD = $(PTHREAD_LIBS) libprotobuf.la libprotoc.la
protoc_SOURCES = google/protobuf/compiler/main.cc
-# The special JS code for the well-known types is linked into the compiler via
-# well_known_types_embed.cc, which is generated from .js source files. We have
-# to build the js_embed binary using $(CXX_FOR_BUILD) so that it is executable
-# on the build machine in a cross-compilation setup.
-js_embed$(EXEEXT): $(srcdir)/google/protobuf/compiler/js/embed.cc
- $(CXX_FOR_BUILD) -o $@ $<
-js_well_known_types_sources = \
- google/protobuf/compiler/js/well_known_types/any.js \
- google/protobuf/compiler/js/well_known_types/struct.js \
- google/protobuf/compiler/js/well_known_types/timestamp.js
-# We have to cd to $(srcdir) so that out-of-tree builds work properly.
-google/protobuf/compiler/js/well_known_types_embed.cc: js_embed$(EXEEXT) $(js_well_known_types_sources)
- mkdir -p `dirname $@` && \
- oldpwd=`pwd` && cd $(srcdir) && \
- $$oldpwd/js_embed$(EXEEXT) $(js_well_known_types_sources) > $$oldpwd/$@
-
# Tests ==============================================================
protoc_inputs = \
@@ -565,7 +547,6 @@ EXTRA_DIST = \
google/protobuf/package_info.h \
google/protobuf/io/package_info.h \
google/protobuf/util/package_info.h \
- google/protobuf/compiler/js/embed.cc \
google/protobuf/compiler/ruby/ruby_generated_code.proto \
google/protobuf/compiler/ruby/ruby_generated_code_pb.rb \
google/protobuf/compiler/package_info.h \
diff --git a/src/google/protobuf/any.pb.cc b/src/google/protobuf/any.pb.cc
index 9d632efe..d0fc2905 100644
--- a/src/google/protobuf/any.pb.cc
+++ b/src/google/protobuf/any.pb.cc
@@ -66,14 +66,14 @@ static ::google::protobuf::Message const * const file_default_instances[] = {
reinterpret_cast<const ::google::protobuf::Message*>(&::google::protobuf::_Any_default_instance_),
};
-void protobuf_AssignDescriptors() {
+static void protobuf_AssignDescriptors() {
AddDescriptors();
AssignDescriptors(
"google/protobuf/any.proto", schemas, file_default_instances, TableStruct::offsets,
file_level_metadata, NULL, NULL);
}
-void protobuf_AssignDescriptorsOnce() {
+static void protobuf_AssignDescriptorsOnce() {
static ::google::protobuf::internal::once_flag once;
::google::protobuf::internal::call_once(once, protobuf_AssignDescriptors);
}
@@ -84,7 +84,7 @@ void protobuf_RegisterTypes(const ::std::string&) {
::google::protobuf::internal::RegisterAllTypes(file_level_metadata, 1);
}
-void AddDescriptorsImpl() {
+static void AddDescriptorsImpl() {
InitDefaults();
static const char descriptor[] GOOGLE_PROTOBUF_ATTRIBUTE_SECTION_VARIABLE(protodesc_cold) = {
"\n\031google/protobuf/any.proto\022\017google.prot"
diff --git a/src/google/protobuf/api.pb.cc b/src/google/protobuf/api.pb.cc
index e0a249d0..6ad9f48d 100644
--- a/src/google/protobuf/api.pb.cc
+++ b/src/google/protobuf/api.pb.cc
@@ -149,14 +149,14 @@ static ::google::protobuf::Message const * const file_default_instances[] = {
reinterpret_cast<const ::google::protobuf::Message*>(&::google::protobuf::_Mixin_default_instance_),
};
-void protobuf_AssignDescriptors() {
+static void protobuf_AssignDescriptors() {
AddDescriptors();
AssignDescriptors(
"google/protobuf/api.proto", schemas, file_default_instances, TableStruct::offsets,
file_level_metadata, NULL, NULL);
}
-void protobuf_AssignDescriptorsOnce() {
+static void protobuf_AssignDescriptorsOnce() {
static ::google::protobuf::internal::once_flag once;
::google::protobuf::internal::call_once(once, protobuf_AssignDescriptors);
}
@@ -167,7 +167,7 @@ void protobuf_RegisterTypes(const ::std::string&) {
::google::protobuf::internal::RegisterAllTypes(file_level_metadata, 3);
}
-void AddDescriptorsImpl() {
+static void AddDescriptorsImpl() {
InitDefaults();
static const char descriptor[] GOOGLE_PROTOBUF_ATTRIBUTE_SECTION_VARIABLE(protodesc_cold) = {
"\n\031google/protobuf/api.proto\022\017google.prot"
diff --git a/src/google/protobuf/compiler/cpp/cpp_file.cc b/src/google/protobuf/compiler/cpp/cpp_file.cc
index 42525687..02f360bb 100644
--- a/src/google/protobuf/compiler/cpp/cpp_file.cc
+++ b/src/google/protobuf/compiler/cpp/cpp_file.cc
@@ -791,7 +791,7 @@ void FileGenerator::GenerateReflectionInitializationCode(io::Printer* printer) {
// AssignDescriptors(). All later times, waits for the first call to
// complete and then returns.
printer->Print(
- "void protobuf_AssignDescriptors() {\n"
+ "static void protobuf_AssignDescriptors() {\n"
// Make sure the file has found its way into the pool. If a descriptor
// is requested *during* static init then AddDescriptors() may not have
// been called yet, so we call it manually. Note that it's fine if
@@ -812,7 +812,7 @@ void FileGenerator::GenerateReflectionInitializationCode(io::Printer* printer) {
printer->Print(
"}\n"
"\n"
- "void protobuf_AssignDescriptorsOnce() {\n"
+ "static void protobuf_AssignDescriptorsOnce() {\n"
" static ::google::protobuf::internal::once_flag once;\n"
" ::google::protobuf::internal::call_once(once, protobuf_AssignDescriptors);\n"
"}\n"
@@ -850,7 +850,7 @@ void FileGenerator::GenerateReflectionInitializationCode(io::Printer* printer) {
// Now generate the AddDescriptors() function.
printer->Print(
- "void AddDescriptorsImpl() {\n"
+ "static void AddDescriptorsImpl() {\n"
" InitDefaults();\n");
printer->Indent();
diff --git a/src/google/protobuf/compiler/cpp/cpp_message.cc b/src/google/protobuf/compiler/cpp/cpp_message.cc
index 8c2336af..778fc406 100644
--- a/src/google/protobuf/compiler/cpp/cpp_message.cc
+++ b/src/google/protobuf/compiler/cpp/cpp_message.cc
@@ -2280,7 +2280,7 @@ GenerateArenaDestructorCode(io::Printer* printer) {
"classname", classname_);
} else {
printer->Print(
- "void $classname$::RegisterArenaDtor(::google::protobuf::Arena* arena) {\n"
+ "void $classname$::RegisterArenaDtor(::google::protobuf::Arena*) {\n"
"}\n",
"classname", classname_);
}
diff --git a/src/google/protobuf/compiler/csharp/csharp_helpers.cc b/src/google/protobuf/compiler/csharp/csharp_helpers.cc
index 5bca1ffa..04b61074 100644
--- a/src/google/protobuf/compiler/csharp/csharp_helpers.cc
+++ b/src/google/protobuf/compiler/csharp/csharp_helpers.cc
@@ -169,7 +169,7 @@ std::string UnderscoresToCamelCase(const std::string& input,
}
}
// Add a trailing "_" if the name should be altered.
- if (input[input.size() - 1] == '#') {
+ if (input.size() > 0 && input[input.size() - 1] == '#') {
result += '_';
}
return result;
diff --git a/src/google/protobuf/compiler/java/java_enum_field.cc b/src/google/protobuf/compiler/java/java_enum_field.cc
index 0686ea0f..ef64d88b 100644
--- a/src/google/protobuf/compiler/java/java_enum_field.cc
+++ b/src/google/protobuf/compiler/java/java_enum_field.cc
@@ -305,11 +305,15 @@ GenerateBuildingCode(io::Printer* printer) const {
if (SupportFieldPresence(descriptor_->file())) {
printer->Print(variables_,
"if ($get_has_field_bit_from_local$) {\n"
+ " result.$name$_ = $name$_;\n"
" $set_has_field_bit_to_local$;\n"
+ "} else {\n"
+ " result.$name$_ = $default_number$;\n"
"}\n");
+ } else {
+ printer->Print(variables_,
+ "result.$name$_ = $name$_;\n");
}
- printer->Print(variables_,
- "result.$name$_ = $name$_;\n");
}
void ImmutableEnumFieldGenerator::
diff --git a/src/google/protobuf/compiler/java/java_lazy_message_field.cc b/src/google/protobuf/compiler/java/java_lazy_message_field.cc
index abf8e55c..6544bea0 100644
--- a/src/google/protobuf/compiler/java/java_lazy_message_field.cc
+++ b/src/google/protobuf/compiler/java/java_lazy_message_field.cc
@@ -233,12 +233,9 @@ void ImmutableLazyMessageFieldGenerator::
GenerateBuildingCode(io::Printer* printer) const {
printer->Print(variables_,
"if ($get_has_field_bit_from_local$) {\n"
+ " result.$name$_.set($name$_);\n"
" $set_has_field_bit_to_local$;\n"
"}\n");
-
- printer->Print(variables_,
- "result.$name$_.set(\n"
- " $name$_);\n");
}
void ImmutableLazyMessageFieldGenerator::
diff --git a/src/google/protobuf/compiler/java/java_message_field.cc b/src/google/protobuf/compiler/java/java_message_field.cc
index baa7f872..bda4fcc0 100644
--- a/src/google/protobuf/compiler/java/java_message_field.cc
+++ b/src/google/protobuf/compiler/java/java_message_field.cc
@@ -255,7 +255,7 @@ GenerateBuilderMembers(io::Printer* printer) const {
bool support_field_presence = SupportFieldPresence(descriptor_->file());
printer->Print(variables_,
- "private $type$ $name$_ = null;\n");
+ "private $type$ $name$_;\n");
printer->Print(variables_,
// If this builder is non-null, it is used and the other fields are
@@ -444,15 +444,20 @@ void ImmutableMessageFieldGenerator::
GenerateBuildingCode(io::Printer* printer) const {
if (SupportFieldPresence(descriptor_->file())) {
printer->Print(variables_,
- "if ($get_has_field_bit_from_local$) {\n"
- " $set_has_field_bit_to_local$;\n"
- "}\n");
+ "if ($get_has_field_bit_from_local$) {\n");
+ printer->Indent();
+ PrintNestedBuilderCondition(printer,
+ "result.$name$_ = $name$_;\n",
+ "result.$name$_ = $name$Builder_.build();\n");
+ printer->Outdent();
+ printer->Print(variables_,
+ " $set_has_field_bit_to_local$;\n"
+ "}\n");
+ } else {
+ PrintNestedBuilderCondition(printer,
+ "result.$name$_ = $name$_;\n",
+ "result.$name$_ = $name$Builder_.build();\n");
}
-
- PrintNestedBuilderCondition(printer,
- "result.$name$_ = $name$_;\n",
-
- "result.$name$_ = $name$Builder_.build();\n");
}
void ImmutableMessageFieldGenerator::
diff --git a/src/google/protobuf/compiler/java/java_primitive_field.cc b/src/google/protobuf/compiler/java/java_primitive_field.cc
index 71ee0992..e6ce69c7 100644
--- a/src/google/protobuf/compiler/java/java_primitive_field.cc
+++ b/src/google/protobuf/compiler/java/java_primitive_field.cc
@@ -264,7 +264,9 @@ GenerateFieldBuilderInitializationCode(io::Printer* printer) const {
void ImmutablePrimitiveFieldGenerator::
GenerateInitializationCode(io::Printer* printer) const {
- printer->Print(variables_, "$name$_ = $default$;\n");
+ if (!IsDefaultValueJavaDefault(descriptor_)) {
+ printer->Print(variables_, "$name$_ = $default$;\n");
+ }
}
void ImmutablePrimitiveFieldGenerator::
@@ -294,11 +296,21 @@ GenerateBuildingCode(io::Printer* printer) const {
if (SupportFieldPresence(descriptor_->file())) {
printer->Print(variables_,
"if ($get_has_field_bit_from_local$) {\n"
- " $set_has_field_bit_to_local$;\n"
- "}\n");
+ " result.$name$_ = $name$_;\n"
+ " $set_has_field_bit_to_local$;\n");
+ if (IsDefaultValueJavaDefault(descriptor_)) {
+ printer->Print(variables_,
+ "}\n");
+ } else {
+ printer->Print(variables_,
+ "} else {\n"
+ " result.$name$_ = $default$;\n"
+ "}\n");
+ }
+ } else {
+ printer->Print(variables_,
+ "result.$name$_ = $name$_;\n");
}
- printer->Print(variables_,
- "result.$name$_ = $name$_;\n");
}
void ImmutablePrimitiveFieldGenerator::
diff --git a/src/google/protobuf/compiler/java/java_string_field.cc b/src/google/protobuf/compiler/java/java_string_field.cc
index 2b6e9381..b08febc0 100644
--- a/src/google/protobuf/compiler/java/java_string_field.cc
+++ b/src/google/protobuf/compiler/java/java_string_field.cc
@@ -405,11 +405,15 @@ GenerateBuildingCode(io::Printer* printer) const {
if (SupportFieldPresence(descriptor_->file())) {
printer->Print(variables_,
"if ($get_has_field_bit_from_local$) {\n"
+ " result.$name$_ = $name$_;\n"
" $set_has_field_bit_to_local$;\n"
+ "} else {\n"
+ " result.$name$_ = $default$;\n"
"}\n");
+ } else {
+ printer->Print(variables_,
+ "result.$name$_ = $name$_;\n");
}
- printer->Print(variables_,
- "result.$name$_ = $name$_;\n");
}
void ImmutableStringFieldGenerator::
diff --git a/src/google/protobuf/compiler/js/embed.cc b/src/google/protobuf/compiler/js/embed.cc
deleted file mode 100644
index f0f946e5..00000000
--- a/src/google/protobuf/compiler/js/embed.cc
+++ /dev/null
@@ -1,110 +0,0 @@
-// Protocol Buffers - Google's data interchange format
-// Copyright 2008 Google Inc. All rights reserved.
-// https://developers.google.com/protocol-buffers/
-//
-// Redistribution and use in source and binary forms, with or without
-// modification, are permitted provided that the following conditions are
-// met:
-//
-// * Redistributions of source code must retain the above copyright
-// notice, this list of conditions and the following disclaimer.
-// * Redistributions in binary form must reproduce the above
-// copyright notice, this list of conditions and the following disclaimer
-// in the documentation and/or other materials provided with the
-// distribution.
-// * Neither the name of Google Inc. nor the names of its
-// contributors may be used to endorse or promote products derived from
-// this software without specific prior written permission.
-//
-// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
-// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
-// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
-// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
-// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
-// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
-// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
-// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
-// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
-// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
-// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-
-#include <cassert>
-#include <cstdlib>
-#include <fstream>
-#include <iostream>
-#include <string>
-
-static bool AsciiIsPrint(unsigned char c) {
- return c >= 32 && c < 127;
-}
-
-static char ToDecimalDigit(int num) {
- assert(num < 10);
- return '0' + num;
-}
-
-static std::string CEscape(const std::string& str) {
- std::string dest;
-
- for (size_t i = 0; i < str.size(); ++i) {
- unsigned char ch = str[i];
- switch (ch) {
- case '\n': dest += "\\n"; break;
- case '\r': dest += "\\r"; break;
- case '\t': dest += "\\t"; break;
- case '\"': dest += "\\\""; break;
- case '\\': dest += "\\\\"; break;
- default:
- if (AsciiIsPrint(ch)) {
- dest += ch;
- } else {
- dest += "\\";
- dest += ToDecimalDigit(ch / 64);
- dest += ToDecimalDigit((ch % 64) / 8);
- dest += ToDecimalDigit(ch % 8);
- }
- break;
- }
- }
-
- return dest;
-}
-
-static void AddFile(const char* name, std::basic_ostream<char>* out) {
- std::ifstream in(name);
-
- if (!in.is_open()) {
- std::cerr << "Couldn't open input file: " << name << "\n";
- std::exit(EXIT_FAILURE);
- }
-
- // Make canonical name only include the final element.
- for (const char *p = name; *p; p++) {
- if (*p == '/') {
- name = p + 1;
- }
- }
-
- *out << "{\"" << CEscape(name) << "\",\n";
-
- for (std::string line; std::getline(in, line); ) {
- *out << " \"" << CEscape(line) << "\\n\"\n";
- }
-
- *out << "},\n";
-}
-
-int main(int argc, char *argv[]) {
- std::cout << "#include "
- "\"google/protobuf/compiler/js/well_known_types_embed.h\"\n";
- std::cout << "struct FileToc well_known_types_js[] = {\n";
-
- for (int i = 1; i < argc; i++) {
- AddFile(argv[i], &std::cout);
- }
-
- std::cout << " {NULL, NULL} // Terminate the list.\n";
- std::cout << "};\n";
-
- return EXIT_SUCCESS;
-}
diff --git a/src/google/protobuf/compiler/js/js_generator.cc b/src/google/protobuf/compiler/js/js_generator.cc
index b5771f26..dfa60068 100755
--- a/src/google/protobuf/compiler/js/js_generator.cc
+++ b/src/google/protobuf/compiler/js/js_generator.cc
@@ -3481,7 +3481,8 @@ void Generator::GenerateFile(const GeneratorOptions& options,
GenerateExtension(options, printer, *it);
}
- if (options.import_style == GeneratorOptions::kImportCommonJs) {
+ // if provided is empty, do not export anything
+ if (options.import_style == GeneratorOptions::kImportCommonJs && !provided.empty()) {
printer->Print("goog.object.extend(exports, $package$);\n",
"package", GetFilePath(options, file));
}
diff --git a/src/google/protobuf/compiler/js/well_known_types_embed.cc b/src/google/protobuf/compiler/js/well_known_types_embed.cc
new file mode 100644
index 00000000..e5ee5510
--- /dev/null
+++ b/src/google/protobuf/compiler/js/well_known_types_embed.cc
@@ -0,0 +1,225 @@
+#include <google/protobuf/compiler/js/well_known_types_embed.h>
+
+struct FileToc well_known_types_js[] = {
+ {"any.js",
+ "/* This code will be inserted into generated code for\n"
+ " * google/protobuf/any.proto. */\n"
+ "\n"
+ "/**\n"
+ " * Returns the type name contained in this instance, if any.\n"
+ " * @return {string|undefined}\n"
+ " */\n"
+ "proto.google.protobuf.Any.prototype.getTypeName = function() {\n"
+ " return this.getTypeUrl().split('/').pop();\n"
+ "};\n"
+ "\n"
+ "\n"
+ "/**\n"
+ " * Packs the given message instance into this Any.\n"
+ " * @param {!Uint8Array} serialized The serialized data to pack.\n"
+ " * @param {string} name The type name of this message object.\n"
+ " * @param {string=} opt_typeUrlPrefix the type URL prefix.\n"
+ " */\n"
+ "proto.google.protobuf.Any.prototype.pack = function(serialized, name,\n"
+ " opt_typeUrlPrefix) "
+ "{\n"
+ " if (!opt_typeUrlPrefix) {\n"
+ " opt_typeUrlPrefix = 'type.googleapis.com/';\n"
+ " }\n"
+ "\n"
+ " if (opt_typeUrlPrefix.substr(-1) != '/') {\n"
+ " this.setTypeUrl(opt_typeUrlPrefix + '/' + name);\n"
+ " } else {\n"
+ " this.setTypeUrl(opt_typeUrlPrefix + name);\n"
+ " }\n"
+ "\n"
+ " this.setValue(serialized);\n"
+ "};\n"
+ "\n"
+ "\n"
+ "/**\n"
+ " * @template T\n"
+ " * Unpacks this Any into the given message object.\n"
+ " * @param {function(Uint8Array):T} deserialize Function that will "
+ "deserialize\n"
+ " * the binary data properly.\n"
+ " * @param {string} name The expected type name of this message object.\n"
+ " * @return {?T} If the name matched the expected name, returns the "
+ "deserialized\n"
+ " * object, otherwise returns null.\n"
+ " */\n"
+ "proto.google.protobuf.Any.prototype.unpack = function(deserialize, name) "
+ "{\n"
+ " if (this.getTypeName() == name) {\n"
+ " return deserialize(this.getValue_asU8());\n"
+ " } else {\n"
+ " return null;\n"
+ " }\n"
+ "};\n"},
+ {"timestamp.js",
+ "/* This code will be inserted into generated code for\n"
+ " * google/protobuf/timestamp.proto. */\n"
+ "\n"
+ "/**\n"
+ " * Returns a JavaScript 'Date' object corresponding to this Timestamp.\n"
+ " * @return {!Date}\n"
+ " */\n"
+ "proto.google.protobuf.Timestamp.prototype.toDate = function() {\n"
+ " var seconds = this.getSeconds();\n"
+ " var nanos = this.getNanos();\n"
+ "\n"
+ " return new Date((seconds * 1000) + (nanos / 1000000));\n"
+ "};\n"
+ "\n"
+ "\n"
+ "/**\n"
+ " * Sets the value of this Timestamp object to be the given Date.\n"
+ " * @param {!Date} value The value to set.\n"
+ " */\n"
+ "proto.google.protobuf.Timestamp.prototype.fromDate = function(value) {\n"
+ " this.setSeconds(Math.floor(value.getTime() / 1000));\n"
+ " this.setNanos(value.getMilliseconds() * 1000000);\n"
+ "};\n"},
+ {"struct.js",
+ "/* This code will be inserted into generated code for\n"
+ " * google/protobuf/struct.proto. */\n"
+ "\n"
+ "/**\n"
+ " * Typedef representing plain JavaScript values that can go into a\n"
+ " * Struct.\n"
+ " * @typedef {null|number|string|boolean|Array|Object}\n"
+ " */\n"
+ "proto.google.protobuf.JavaScriptValue;\n"
+ "\n"
+ "\n"
+ "/**\n"
+ " * Converts this Value object to a plain JavaScript value.\n"
+ " * @return {?proto.google.protobuf.JavaScriptValue} a plain JavaScript\n"
+ " * value representing this Struct.\n"
+ " */\n"
+ "proto.google.protobuf.Value.prototype.toJavaScript = function() {\n"
+ " var kindCase = proto.google.protobuf.Value.KindCase;\n"
+ " switch (this.getKindCase()) {\n"
+ " case kindCase.NULL_VALUE:\n"
+ " return null;\n"
+ " case kindCase.NUMBER_VALUE:\n"
+ " return this.getNumberValue();\n"
+ " case kindCase.STRING_VALUE:\n"
+ " return this.getStringValue();\n"
+ " case kindCase.BOOL_VALUE:\n"
+ " return this.getBoolValue();\n"
+ " case kindCase.STRUCT_VALUE:\n"
+ " return this.getStructValue().toJavaScript();\n"
+ " case kindCase.LIST_VALUE:\n"
+ " return this.getListValue().toJavaScript();\n"
+ " default:\n"
+ " throw new Error('Unexpected struct type');\n"
+ " }\n"
+ "};\n"
+ "\n"
+ "\n"
+ "/**\n"
+ " * Converts this JavaScript value to a new Value proto.\n"
+ " * @param {!proto.google.protobuf.JavaScriptValue} value The value to\n"
+ " * convert.\n"
+ " * @return {!proto.google.protobuf.Value} The newly constructed value.\n"
+ " */\n"
+ "proto.google.protobuf.Value.fromJavaScript = function(value) {\n"
+ " var ret = new proto.google.protobuf.Value();\n"
+ " switch (goog.typeOf(value)) {\n"
+ " case 'string':\n"
+ " ret.setStringValue(/** @type {string} */ (value));\n"
+ " break;\n"
+ " case 'number':\n"
+ " ret.setNumberValue(/** @type {number} */ (value));\n"
+ " break;\n"
+ " case 'boolean':\n"
+ " ret.setBoolValue(/** @type {boolean} */ (value));\n"
+ " break;\n"
+ " case 'null':\n"
+ " ret.setNullValue(proto.google.protobuf.NullValue.NULL_VALUE);\n"
+ " break;\n"
+ " case 'array':\n"
+ " ret.setListValue(proto.google.protobuf.ListValue.fromJavaScript(\n"
+ " /** @type{!Array} */ (value)));\n"
+ " break;\n"
+ " case 'object':\n"
+ " ret.setStructValue(proto.google.protobuf.Struct.fromJavaScript(\n"
+ " /** @type{!Object} */ (value)));\n"
+ " break;\n"
+ " default:\n"
+ " throw new Error('Unexpected struct type.');\n"
+ " }\n"
+ "\n"
+ " return ret;\n"
+ "};\n"
+ "\n"
+ "\n"
+ "/**\n"
+ " * Converts this ListValue object to a plain JavaScript array.\n"
+ " * @return {!Array} a plain JavaScript array representing this List.\n"
+ " */\n"
+ "proto.google.protobuf.ListValue.prototype.toJavaScript = function() {\n"
+ " var ret = [];\n"
+ " var values = this.getValuesList();\n"
+ "\n"
+ " for (var i = 0; i < values.length; i++) {\n"
+ " ret[i] = values[i].toJavaScript();\n"
+ " }\n"
+ "\n"
+ " return ret;\n"
+ "};\n"
+ "\n"
+ "\n"
+ "/**\n"
+ " * Constructs a ListValue protobuf from this plain JavaScript array.\n"
+ " * @param {!Array} array a plain JavaScript array\n"
+ " * @return {proto.google.protobuf.ListValue} a new ListValue object\n"
+ " */\n"
+ "proto.google.protobuf.ListValue.fromJavaScript = function(array) {\n"
+ " var ret = new proto.google.protobuf.ListValue();\n"
+ "\n"
+ " for (var i = 0; i < array.length; i++) {\n"
+ " "
+ "ret.addValues(proto.google.protobuf.Value.fromJavaScript(array[i]));\n"
+ " }\n"
+ "\n"
+ " return ret;\n"
+ "};\n"
+ "\n"
+ "\n"
+ "/**\n"
+ " * Converts this Struct object to a plain JavaScript object.\n"
+ " * @return {!Object<string, !proto.google.protobuf.JavaScriptValue>} a "
+ "plain\n"
+ " * JavaScript object representing this Struct.\n"
+ " */\n"
+ "proto.google.protobuf.Struct.prototype.toJavaScript = function() {\n"
+ " var ret = {};\n"
+ "\n"
+ " this.getFieldsMap().forEach(function(value, key) {\n"
+ " ret[key] = value.toJavaScript();\n"
+ " });\n"
+ "\n"
+ " return ret;\n"
+ "};\n"
+ "\n"
+ "\n"
+ "/**\n"
+ " * Constructs a Struct protobuf from this plain JavaScript object.\n"
+ " * @param {!Object} obj a plain JavaScript object\n"
+ " * @return {proto.google.protobuf.Struct} a new Struct object\n"
+ " */\n"
+ "proto.google.protobuf.Struct.fromJavaScript = function(obj) {\n"
+ " var ret = new proto.google.protobuf.Struct();\n"
+ " var map = ret.getFieldsMap();\n"
+ "\n"
+ " for (var property in obj) {\n"
+ " var val = obj[property];\n"
+ " map.set(property, proto.google.protobuf.Value.fromJavaScript(val));\n"
+ " }\n"
+ "\n"
+ " return ret;\n"
+ "};\n"},
+ {NULL, NULL} // Terminate the list.
+};
diff --git a/src/google/protobuf/compiler/plugin.pb.cc b/src/google/protobuf/compiler/plugin.pb.cc
index ef52def3..20aa82c7 100644
--- a/src/google/protobuf/compiler/plugin.pb.cc
+++ b/src/google/protobuf/compiler/plugin.pb.cc
@@ -183,14 +183,14 @@ static ::google::protobuf::Message const * const file_default_instances[] = {
reinterpret_cast<const ::google::protobuf::Message*>(&::google::protobuf::compiler::_CodeGeneratorResponse_default_instance_),
};
-void protobuf_AssignDescriptors() {
+static void protobuf_AssignDescriptors() {
AddDescriptors();
AssignDescriptors(
"google/protobuf/compiler/plugin.proto", schemas, file_default_instances, TableStruct::offsets,
file_level_metadata, NULL, NULL);
}
-void protobuf_AssignDescriptorsOnce() {
+static void protobuf_AssignDescriptorsOnce() {
static ::google::protobuf::internal::once_flag once;
::google::protobuf::internal::call_once(once, protobuf_AssignDescriptors);
}
@@ -201,7 +201,7 @@ void protobuf_RegisterTypes(const ::std::string&) {
::google::protobuf::internal::RegisterAllTypes(file_level_metadata, 4);
}
-void AddDescriptorsImpl() {
+static void AddDescriptorsImpl() {
InitDefaults();
static const char descriptor[] GOOGLE_PROTOBUF_ATTRIBUTE_SECTION_VARIABLE(protodesc_cold) = {
"\n%google/protobuf/compiler/plugin.proto\022"
diff --git a/src/google/protobuf/descriptor.cc b/src/google/protobuf/descriptor.cc
index 83eae519..60b2a30e 100644
--- a/src/google/protobuf/descriptor.cc
+++ b/src/google/protobuf/descriptor.cc
@@ -406,9 +406,10 @@ typedef std::pair<const EnumDescriptor*, int> EnumIntPair;
template<typename PairType>
struct PointerIntegerPairHash {
size_t operator()(const PairType& p) const {
- // FIXME(kenton): What is the best way to compute this hash? I have
- // no idea! This seems a bit better than an XOR.
- return reinterpret_cast<intptr_t>(p.first) * ((1 << 16) - 1) + p.second;
+ static const size_t prime1 = 16777499;
+ static const size_t prime2 = 16777619;
+ return reinterpret_cast<size_t>(p.first) * prime1 ^
+ static_cast<size_t>(p.second) * prime2;
}
#ifdef _MSC_VER
@@ -424,11 +425,10 @@ struct PointerIntegerPairHash {
struct PointerStringPairHash {
size_t operator()(const PointerStringPair& p) const {
- // FIXME(kenton): What is the best way to compute this hash? I have
- // no idea! This seems a bit better than an XOR.
+ static const size_t prime = 16777619;
hash<const char*> cstring_hash;
- return reinterpret_cast<intptr_t>(p.first) * ((1 << 16) - 1) +
- cstring_hash(p.second);
+ return reinterpret_cast<size_t>(p.first) * prime ^
+ static_cast<size_t>(cstring_hash(p.second));
}
#ifdef _MSC_VER
diff --git a/src/google/protobuf/descriptor.pb.cc b/src/google/protobuf/descriptor.pb.cc
index 59b04aba..2ccf189c 100644
--- a/src/google/protobuf/descriptor.pb.cc
+++ b/src/google/protobuf/descriptor.pb.cc
@@ -1077,14 +1077,14 @@ static ::google::protobuf::Message const * const file_default_instances[] = {
reinterpret_cast<const ::google::protobuf::Message*>(&::google::protobuf::_GeneratedCodeInfo_default_instance_),
};
-void protobuf_AssignDescriptors() {
+static void protobuf_AssignDescriptors() {
AddDescriptors();
AssignDescriptors(
"google/protobuf/descriptor.proto", schemas, file_default_instances, TableStruct::offsets,
file_level_metadata, file_level_enum_descriptors, NULL);
}
-void protobuf_AssignDescriptorsOnce() {
+static void protobuf_AssignDescriptorsOnce() {
static ::google::protobuf::internal::once_flag once;
::google::protobuf::internal::call_once(once, protobuf_AssignDescriptors);
}
@@ -1095,7 +1095,7 @@ void protobuf_RegisterTypes(const ::std::string&) {
::google::protobuf::internal::RegisterAllTypes(file_level_metadata, 27);
}
-void AddDescriptorsImpl() {
+static void AddDescriptorsImpl() {
InitDefaults();
static const char descriptor[] GOOGLE_PROTOBUF_ATTRIBUTE_SECTION_VARIABLE(protodesc_cold) = {
"\n google/protobuf/descriptor.proto\022\017goog"
@@ -1487,7 +1487,7 @@ void FileDescriptorSet::ArenaDtor(void* object) {
FileDescriptorSet* _this = reinterpret_cast< FileDescriptorSet* >(object);
(void)_this;
}
-void FileDescriptorSet::RegisterArenaDtor(::google::protobuf::Arena* arena) {
+void FileDescriptorSet::RegisterArenaDtor(::google::protobuf::Arena*) {
}
void FileDescriptorSet::SetCachedSize(int size) const {
_cached_size_.Set(size);
@@ -1840,7 +1840,7 @@ void FileDescriptorProto::ArenaDtor(void* object) {
FileDescriptorProto* _this = reinterpret_cast< FileDescriptorProto* >(object);
(void)_this;
}
-void FileDescriptorProto::RegisterArenaDtor(::google::protobuf::Arena* arena) {
+void FileDescriptorProto::RegisterArenaDtor(::google::protobuf::Arena*) {
}
void FileDescriptorProto::SetCachedSize(int size) const {
_cached_size_.Set(size);
@@ -2642,7 +2642,7 @@ void DescriptorProto_ExtensionRange::ArenaDtor(void* object) {
DescriptorProto_ExtensionRange* _this = reinterpret_cast< DescriptorProto_ExtensionRange* >(object);
(void)_this;
}
-void DescriptorProto_ExtensionRange::RegisterArenaDtor(::google::protobuf::Arena* arena) {
+void DescriptorProto_ExtensionRange::RegisterArenaDtor(::google::protobuf::Arena*) {
}
void DescriptorProto_ExtensionRange::SetCachedSize(int size) const {
_cached_size_.Set(size);
@@ -2994,7 +2994,7 @@ void DescriptorProto_ReservedRange::ArenaDtor(void* object) {
DescriptorProto_ReservedRange* _this = reinterpret_cast< DescriptorProto_ReservedRange* >(object);
(void)_this;
}
-void DescriptorProto_ReservedRange::RegisterArenaDtor(::google::protobuf::Arena* arena) {
+void DescriptorProto_ReservedRange::RegisterArenaDtor(::google::protobuf::Arena*) {
}
void DescriptorProto_ReservedRange::SetCachedSize(int size) const {
_cached_size_.Set(size);
@@ -3350,7 +3350,7 @@ void DescriptorProto::ArenaDtor(void* object) {
DescriptorProto* _this = reinterpret_cast< DescriptorProto* >(object);
(void)_this;
}
-void DescriptorProto::RegisterArenaDtor(::google::protobuf::Arena* arena) {
+void DescriptorProto::RegisterArenaDtor(::google::protobuf::Arena*) {
}
void DescriptorProto::SetCachedSize(int size) const {
_cached_size_.Set(size);
@@ -4032,7 +4032,7 @@ void ExtensionRangeOptions::ArenaDtor(void* object) {
ExtensionRangeOptions* _this = reinterpret_cast< ExtensionRangeOptions* >(object);
(void)_this;
}
-void ExtensionRangeOptions::RegisterArenaDtor(::google::protobuf::Arena* arena) {
+void ExtensionRangeOptions::RegisterArenaDtor(::google::protobuf::Arena*) {
}
void ExtensionRangeOptions::SetCachedSize(int size) const {
_cached_size_.Set(size);
@@ -4390,7 +4390,7 @@ void FieldDescriptorProto::ArenaDtor(void* object) {
FieldDescriptorProto* _this = reinterpret_cast< FieldDescriptorProto* >(object);
(void)_this;
}
-void FieldDescriptorProto::RegisterArenaDtor(::google::protobuf::Arena* arena) {
+void FieldDescriptorProto::RegisterArenaDtor(::google::protobuf::Arena*) {
}
void FieldDescriptorProto::SetCachedSize(int size) const {
_cached_size_.Set(size);
@@ -5120,7 +5120,7 @@ void OneofDescriptorProto::ArenaDtor(void* object) {
OneofDescriptorProto* _this = reinterpret_cast< OneofDescriptorProto* >(object);
(void)_this;
}
-void OneofDescriptorProto::RegisterArenaDtor(::google::protobuf::Arena* arena) {
+void OneofDescriptorProto::RegisterArenaDtor(::google::protobuf::Arena*) {
}
void OneofDescriptorProto::SetCachedSize(int size) const {
_cached_size_.Set(size);
@@ -5450,7 +5450,7 @@ void EnumDescriptorProto_EnumReservedRange::ArenaDtor(void* object) {
EnumDescriptorProto_EnumReservedRange* _this = reinterpret_cast< EnumDescriptorProto_EnumReservedRange* >(object);
(void)_this;
}
-void EnumDescriptorProto_EnumReservedRange::RegisterArenaDtor(::google::protobuf::Arena* arena) {
+void EnumDescriptorProto_EnumReservedRange::RegisterArenaDtor(::google::protobuf::Arena*) {
}
void EnumDescriptorProto_EnumReservedRange::SetCachedSize(int size) const {
_cached_size_.Set(size);
@@ -5791,7 +5791,7 @@ void EnumDescriptorProto::ArenaDtor(void* object) {
EnumDescriptorProto* _this = reinterpret_cast< EnumDescriptorProto* >(object);
(void)_this;
}
-void EnumDescriptorProto::RegisterArenaDtor(::google::protobuf::Arena* arena) {
+void EnumDescriptorProto::RegisterArenaDtor(::google::protobuf::Arena*) {
}
void EnumDescriptorProto::SetCachedSize(int size) const {
_cached_size_.Set(size);
@@ -6283,7 +6283,7 @@ void EnumValueDescriptorProto::ArenaDtor(void* object) {
EnumValueDescriptorProto* _this = reinterpret_cast< EnumValueDescriptorProto* >(object);
(void)_this;
}
-void EnumValueDescriptorProto::RegisterArenaDtor(::google::protobuf::Arena* arena) {
+void EnumValueDescriptorProto::RegisterArenaDtor(::google::protobuf::Arena*) {
}
void EnumValueDescriptorProto::SetCachedSize(int size) const {
_cached_size_.Set(size);
@@ -6676,7 +6676,7 @@ void ServiceDescriptorProto::ArenaDtor(void* object) {
ServiceDescriptorProto* _this = reinterpret_cast< ServiceDescriptorProto* >(object);
(void)_this;
}
-void ServiceDescriptorProto::RegisterArenaDtor(::google::protobuf::Arena* arena) {
+void ServiceDescriptorProto::RegisterArenaDtor(::google::protobuf::Arena*) {
}
void ServiceDescriptorProto::SetCachedSize(int size) const {
_cached_size_.Set(size);
@@ -7096,7 +7096,7 @@ void MethodDescriptorProto::ArenaDtor(void* object) {
MethodDescriptorProto* _this = reinterpret_cast< MethodDescriptorProto* >(object);
(void)_this;
}
-void MethodDescriptorProto::RegisterArenaDtor(::google::protobuf::Arena* arena) {
+void MethodDescriptorProto::RegisterArenaDtor(::google::protobuf::Arena*) {
}
void MethodDescriptorProto::SetCachedSize(int size) const {
_cached_size_.Set(size);
@@ -7694,7 +7694,7 @@ void FileOptions::ArenaDtor(void* object) {
FileOptions* _this = reinterpret_cast< FileOptions* >(object);
(void)_this;
}
-void FileOptions::RegisterArenaDtor(::google::protobuf::Arena* arena) {
+void FileOptions::RegisterArenaDtor(::google::protobuf::Arena*) {
}
void FileOptions::SetCachedSize(int size) const {
_cached_size_.Set(size);
@@ -8885,7 +8885,7 @@ void MessageOptions::ArenaDtor(void* object) {
MessageOptions* _this = reinterpret_cast< MessageOptions* >(object);
(void)_this;
}
-void MessageOptions::RegisterArenaDtor(::google::protobuf::Arena* arena) {
+void MessageOptions::RegisterArenaDtor(::google::protobuf::Arena*) {
}
void MessageOptions::SetCachedSize(int size) const {
_cached_size_.Set(size);
@@ -9329,7 +9329,7 @@ void FieldOptions::ArenaDtor(void* object) {
FieldOptions* _this = reinterpret_cast< FieldOptions* >(object);
(void)_this;
}
-void FieldOptions::RegisterArenaDtor(::google::protobuf::Arena* arena) {
+void FieldOptions::RegisterArenaDtor(::google::protobuf::Arena*) {
}
void FieldOptions::SetCachedSize(int size) const {
_cached_size_.Set(size);
@@ -9848,7 +9848,7 @@ void OneofOptions::ArenaDtor(void* object) {
OneofOptions* _this = reinterpret_cast< OneofOptions* >(object);
(void)_this;
}
-void OneofOptions::RegisterArenaDtor(::google::protobuf::Arena* arena) {
+void OneofOptions::RegisterArenaDtor(::google::protobuf::Arena*) {
}
void OneofOptions::SetCachedSize(int size) const {
_cached_size_.Set(size);
@@ -10145,7 +10145,7 @@ void EnumOptions::ArenaDtor(void* object) {
EnumOptions* _this = reinterpret_cast< EnumOptions* >(object);
(void)_this;
}
-void EnumOptions::RegisterArenaDtor(::google::protobuf::Arena* arena) {
+void EnumOptions::RegisterArenaDtor(::google::protobuf::Arena*) {
}
void EnumOptions::SetCachedSize(int size) const {
_cached_size_.Set(size);
@@ -10514,7 +10514,7 @@ void EnumValueOptions::ArenaDtor(void* object) {
EnumValueOptions* _this = reinterpret_cast< EnumValueOptions* >(object);
(void)_this;
}
-void EnumValueOptions::RegisterArenaDtor(::google::protobuf::Arena* arena) {
+void EnumValueOptions::RegisterArenaDtor(::google::protobuf::Arena*) {
}
void EnumValueOptions::SetCachedSize(int size) const {
_cached_size_.Set(size);
@@ -10842,7 +10842,7 @@ void ServiceOptions::ArenaDtor(void* object) {
ServiceOptions* _this = reinterpret_cast< ServiceOptions* >(object);
(void)_this;
}
-void ServiceOptions::RegisterArenaDtor(::google::protobuf::Arena* arena) {
+void ServiceOptions::RegisterArenaDtor(::google::protobuf::Arena*) {
}
void ServiceOptions::SetCachedSize(int size) const {
_cached_size_.Set(size);
@@ -11175,7 +11175,7 @@ void MethodOptions::ArenaDtor(void* object) {
MethodOptions* _this = reinterpret_cast< MethodOptions* >(object);
(void)_this;
}
-void MethodOptions::RegisterArenaDtor(::google::protobuf::Arena* arena) {
+void MethodOptions::RegisterArenaDtor(::google::protobuf::Arena*) {
}
void MethodOptions::SetCachedSize(int size) const {
_cached_size_.Set(size);
@@ -11559,7 +11559,7 @@ void UninterpretedOption_NamePart::ArenaDtor(void* object) {
UninterpretedOption_NamePart* _this = reinterpret_cast< UninterpretedOption_NamePart* >(object);
(void)_this;
}
-void UninterpretedOption_NamePart::RegisterArenaDtor(::google::protobuf::Arena* arena) {
+void UninterpretedOption_NamePart::RegisterArenaDtor(::google::protobuf::Arena*) {
}
void UninterpretedOption_NamePart::SetCachedSize(int size) const {
_cached_size_.Set(size);
@@ -11924,7 +11924,7 @@ void UninterpretedOption::ArenaDtor(void* object) {
UninterpretedOption* _this = reinterpret_cast< UninterpretedOption* >(object);
(void)_this;
}
-void UninterpretedOption::RegisterArenaDtor(::google::protobuf::Arena* arena) {
+void UninterpretedOption::RegisterArenaDtor(::google::protobuf::Arena*) {
}
void UninterpretedOption::SetCachedSize(int size) const {
_cached_size_.Set(size);
@@ -12473,7 +12473,7 @@ void SourceCodeInfo_Location::ArenaDtor(void* object) {
SourceCodeInfo_Location* _this = reinterpret_cast< SourceCodeInfo_Location* >(object);
(void)_this;
}
-void SourceCodeInfo_Location::RegisterArenaDtor(::google::protobuf::Arena* arena) {
+void SourceCodeInfo_Location::RegisterArenaDtor(::google::protobuf::Arena*) {
}
void SourceCodeInfo_Location::SetCachedSize(int size) const {
_cached_size_.Set(size);
@@ -12979,7 +12979,7 @@ void SourceCodeInfo::ArenaDtor(void* object) {
SourceCodeInfo* _this = reinterpret_cast< SourceCodeInfo* >(object);
(void)_this;
}
-void SourceCodeInfo::RegisterArenaDtor(::google::protobuf::Arena* arena) {
+void SourceCodeInfo::RegisterArenaDtor(::google::protobuf::Arena*) {
}
void SourceCodeInfo::SetCachedSize(int size) const {
_cached_size_.Set(size);
@@ -13258,7 +13258,7 @@ void GeneratedCodeInfo_Annotation::ArenaDtor(void* object) {
GeneratedCodeInfo_Annotation* _this = reinterpret_cast< GeneratedCodeInfo_Annotation* >(object);
(void)_this;
}
-void GeneratedCodeInfo_Annotation::RegisterArenaDtor(::google::protobuf::Arena* arena) {
+void GeneratedCodeInfo_Annotation::RegisterArenaDtor(::google::protobuf::Arena*) {
}
void GeneratedCodeInfo_Annotation::SetCachedSize(int size) const {
_cached_size_.Set(size);
@@ -13676,7 +13676,7 @@ void GeneratedCodeInfo::ArenaDtor(void* object) {
GeneratedCodeInfo* _this = reinterpret_cast< GeneratedCodeInfo* >(object);
(void)_this;
}
-void GeneratedCodeInfo::RegisterArenaDtor(::google::protobuf::Arena* arena) {
+void GeneratedCodeInfo::RegisterArenaDtor(::google::protobuf::Arena*) {
}
void GeneratedCodeInfo::SetCachedSize(int size) const {
_cached_size_.Set(size);
diff --git a/src/google/protobuf/duration.pb.cc b/src/google/protobuf/duration.pb.cc
index ddc063db..0c67f86e 100644
--- a/src/google/protobuf/duration.pb.cc
+++ b/src/google/protobuf/duration.pb.cc
@@ -66,14 +66,14 @@ static ::google::protobuf::Message const * const file_default_instances[] = {
reinterpret_cast<const ::google::protobuf::Message*>(&::google::protobuf::_Duration_default_instance_),
};
-void protobuf_AssignDescriptors() {
+static void protobuf_AssignDescriptors() {
AddDescriptors();
AssignDescriptors(
"google/protobuf/duration.proto", schemas, file_default_instances, TableStruct::offsets,
file_level_metadata, NULL, NULL);
}
-void protobuf_AssignDescriptorsOnce() {
+static void protobuf_AssignDescriptorsOnce() {
static ::google::protobuf::internal::once_flag once;
::google::protobuf::internal::call_once(once, protobuf_AssignDescriptors);
}
@@ -84,7 +84,7 @@ void protobuf_RegisterTypes(const ::std::string&) {
::google::protobuf::internal::RegisterAllTypes(file_level_metadata, 1);
}
-void AddDescriptorsImpl() {
+static void AddDescriptorsImpl() {
InitDefaults();
static const char descriptor[] GOOGLE_PROTOBUF_ATTRIBUTE_SECTION_VARIABLE(protodesc_cold) = {
"\n\036google/protobuf/duration.proto\022\017google"
diff --git a/src/google/protobuf/empty.pb.cc b/src/google/protobuf/empty.pb.cc
index 9b53c546..7bc46121 100644
--- a/src/google/protobuf/empty.pb.cc
+++ b/src/google/protobuf/empty.pb.cc
@@ -64,14 +64,14 @@ static ::google::protobuf::Message const * const file_default_instances[] = {
reinterpret_cast<const ::google::protobuf::Message*>(&::google::protobuf::_Empty_default_instance_),
};
-void protobuf_AssignDescriptors() {
+static void protobuf_AssignDescriptors() {
AddDescriptors();
AssignDescriptors(
"google/protobuf/empty.proto", schemas, file_default_instances, TableStruct::offsets,
file_level_metadata, NULL, NULL);
}
-void protobuf_AssignDescriptorsOnce() {
+static void protobuf_AssignDescriptorsOnce() {
static ::google::protobuf::internal::once_flag once;
::google::protobuf::internal::call_once(once, protobuf_AssignDescriptors);
}
@@ -82,7 +82,7 @@ void protobuf_RegisterTypes(const ::std::string&) {
::google::protobuf::internal::RegisterAllTypes(file_level_metadata, 1);
}
-void AddDescriptorsImpl() {
+static void AddDescriptorsImpl() {
InitDefaults();
static const char descriptor[] GOOGLE_PROTOBUF_ATTRIBUTE_SECTION_VARIABLE(protodesc_cold) = {
"\n\033google/protobuf/empty.proto\022\017google.pr"
diff --git a/src/google/protobuf/field_mask.pb.cc b/src/google/protobuf/field_mask.pb.cc
index 000fa8d3..2ce061d9 100644
--- a/src/google/protobuf/field_mask.pb.cc
+++ b/src/google/protobuf/field_mask.pb.cc
@@ -65,14 +65,14 @@ static ::google::protobuf::Message const * const file_default_instances[] = {
reinterpret_cast<const ::google::protobuf::Message*>(&::google::protobuf::_FieldMask_default_instance_),
};
-void protobuf_AssignDescriptors() {
+static void protobuf_AssignDescriptors() {
AddDescriptors();
AssignDescriptors(
"google/protobuf/field_mask.proto", schemas, file_default_instances, TableStruct::offsets,
file_level_metadata, NULL, NULL);
}
-void protobuf_AssignDescriptorsOnce() {
+static void protobuf_AssignDescriptorsOnce() {
static ::google::protobuf::internal::once_flag once;
::google::protobuf::internal::call_once(once, protobuf_AssignDescriptors);
}
@@ -83,7 +83,7 @@ void protobuf_RegisterTypes(const ::std::string&) {
::google::protobuf::internal::RegisterAllTypes(file_level_metadata, 1);
}
-void AddDescriptorsImpl() {
+static void AddDescriptorsImpl() {
InitDefaults();
static const char descriptor[] GOOGLE_PROTOBUF_ATTRIBUTE_SECTION_VARIABLE(protodesc_cold) = {
"\n google/protobuf/field_mask.proto\022\017goog"
diff --git a/src/google/protobuf/generated_message_util.h b/src/google/protobuf/generated_message_util.h
index 706df383..4da04cae 100644
--- a/src/google/protobuf/generated_message_util.h
+++ b/src/google/protobuf/generated_message_util.h
@@ -201,7 +201,7 @@ struct SerializationTable {
};
LIBPROTOBUF_EXPORT void SerializeInternal(const uint8* base, const FieldMetadata* table,
- int num_fields, ::google::protobuf::io::CodedOutputStream* output);
+ int32 num_fields, ::google::protobuf::io::CodedOutputStream* output);
inline void TableSerialize(const ::google::protobuf::MessageLite& msg,
const SerializationTable* table,
@@ -219,7 +219,7 @@ inline void TableSerialize(const ::google::protobuf::MessageLite& msg,
}
uint8* SerializeInternalToArray(const uint8* base, const FieldMetadata* table,
- int num_fields, bool is_deterministic,
+ int32 num_fields, bool is_deterministic,
uint8* buffer);
inline uint8* TableSerializeToArray(const ::google::protobuf::MessageLite& msg,
diff --git a/src/google/protobuf/message_lite.cc b/src/google/protobuf/message_lite.cc
index 123b142d..65af7cea 100644
--- a/src/google/protobuf/message_lite.cc
+++ b/src/google/protobuf/message_lite.cc
@@ -316,7 +316,11 @@ bool MessageLite::SerializeToArray(void* data, int size) const {
}
bool MessageLite::SerializePartialToArray(void* data, int size) const {
- int byte_size = ByteSizeLong();
+ size_t byte_size = ByteSizeLong();
+ if (byte_size > INT_MAX) {
+ GOOGLE_LOG(ERROR) << "Exceeded maximum protobuf size of 2GB: " << size;
+ return false;
+ }
if (size < byte_size) return false;
uint8* start = reinterpret_cast<uint8*>(data);
uint8* end = SerializeWithCachedSizesToArray(start);
diff --git a/src/google/protobuf/source_context.pb.cc b/src/google/protobuf/source_context.pb.cc
index 739172f8..af93e6b2 100644
--- a/src/google/protobuf/source_context.pb.cc
+++ b/src/google/protobuf/source_context.pb.cc
@@ -65,14 +65,14 @@ static ::google::protobuf::Message const * const file_default_instances[] = {
reinterpret_cast<const ::google::protobuf::Message*>(&::google::protobuf::_SourceContext_default_instance_),
};
-void protobuf_AssignDescriptors() {
+static void protobuf_AssignDescriptors() {
AddDescriptors();
AssignDescriptors(
"google/protobuf/source_context.proto", schemas, file_default_instances, TableStruct::offsets,
file_level_metadata, NULL, NULL);
}
-void protobuf_AssignDescriptorsOnce() {
+static void protobuf_AssignDescriptorsOnce() {
static ::google::protobuf::internal::once_flag once;
::google::protobuf::internal::call_once(once, protobuf_AssignDescriptors);
}
@@ -83,7 +83,7 @@ void protobuf_RegisterTypes(const ::std::string&) {
::google::protobuf::internal::RegisterAllTypes(file_level_metadata, 1);
}
-void AddDescriptorsImpl() {
+static void AddDescriptorsImpl() {
InitDefaults();
static const char descriptor[] GOOGLE_PROTOBUF_ATTRIBUTE_SECTION_VARIABLE(protodesc_cold) = {
"\n$google/protobuf/source_context.proto\022\017"
diff --git a/src/google/protobuf/struct.pb.cc b/src/google/protobuf/struct.pb.cc
index 8f2d4848..4bf5d45c 100644
--- a/src/google/protobuf/struct.pb.cc
+++ b/src/google/protobuf/struct.pb.cc
@@ -140,14 +140,14 @@ static ::google::protobuf::Message const * const file_default_instances[] = {
reinterpret_cast<const ::google::protobuf::Message*>(&::google::protobuf::_ListValue_default_instance_),
};
-void protobuf_AssignDescriptors() {
+static void protobuf_AssignDescriptors() {
AddDescriptors();
AssignDescriptors(
"google/protobuf/struct.proto", schemas, file_default_instances, TableStruct::offsets,
file_level_metadata, file_level_enum_descriptors, NULL);
}
-void protobuf_AssignDescriptorsOnce() {
+static void protobuf_AssignDescriptorsOnce() {
static ::google::protobuf::internal::once_flag once;
::google::protobuf::internal::call_once(once, protobuf_AssignDescriptors);
}
@@ -158,7 +158,7 @@ void protobuf_RegisterTypes(const ::std::string&) {
::google::protobuf::internal::RegisterAllTypes(file_level_metadata, 4);
}
-void AddDescriptorsImpl() {
+static void AddDescriptorsImpl() {
InitDefaults();
static const char descriptor[] GOOGLE_PROTOBUF_ATTRIBUTE_SECTION_VARIABLE(protodesc_cold) = {
"\n\034google/protobuf/struct.proto\022\017google.p"
diff --git a/src/google/protobuf/stubs/int128.cc b/src/google/protobuf/stubs/int128.cc
index a5090801..7b993e8f 100644
--- a/src/google/protobuf/stubs/int128.cc
+++ b/src/google/protobuf/stubs/int128.cc
@@ -76,52 +76,36 @@ static inline int Fls128(uint128 n) {
return Fls64(Uint128Low64(n));
}
-// Long division/modulo for uint128 implemented using the shift-subtract
-// division algorithm adapted from:
-// http://stackoverflow.com/questions/5386377/division-without-using
void uint128::DivModImpl(uint128 dividend, uint128 divisor,
uint128* quotient_ret, uint128* remainder_ret) {
if (divisor == 0) {
GOOGLE_LOG(FATAL) << "Division or mod by zero: dividend.hi=" << dividend.hi_
<< ", lo=" << dividend.lo_;
- }
-
- if (divisor > dividend) {
+ } else if (dividend < divisor) {
*quotient_ret = 0;
*remainder_ret = dividend;
return;
- }
-
- if (divisor == dividend) {
- *quotient_ret = 1;
- *remainder_ret = 0;
- return;
- }
-
- uint128 denominator = divisor;
- uint128 position = 1;
- uint128 quotient = 0;
-
- // Left aligns the MSB of the denominator and the dividend.
- int shift = Fls128(dividend) - Fls128(denominator);
- denominator <<= shift;
- position <<= shift;
-
- // Uses shift-subtract algorithm to divide dividend by denominator. The
- // remainder will be left in dividend.
- while (position > 0) {
- if (dividend >= denominator) {
- dividend -= denominator;
- quotient |= position;
+ } else {
+ int dividend_bit_length = Fls128(dividend);
+ int divisor_bit_length = Fls128(divisor);
+ int difference = dividend_bit_length - divisor_bit_length;
+ uint128 quotient = 0;
+ while (difference >= 0) {
+ quotient <<= 1;
+ uint128 shifted_divisor = divisor << difference;
+ if (shifted_divisor <= dividend) {
+ dividend -= shifted_divisor;
+ quotient += 1;
+ }
+ difference -= 1;
}
- position >>= 1;
- denominator >>= 1;
+ //record the final quotient and remainder
+ *quotient_ret = quotient;
+ *remainder_ret = dividend;
}
-
- *quotient_ret = quotient;
- *remainder_ret = dividend;
}
+
uint128& uint128::operator/=(const uint128& divisor) {
uint128 quotient = 0;
uint128 remainder = 0;
diff --git a/src/google/protobuf/stubs/mutex.h b/src/google/protobuf/stubs/mutex.h
index b9b7d2e1..47edb7a3 100644
--- a/src/google/protobuf/stubs/mutex.h
+++ b/src/google/protobuf/stubs/mutex.h
@@ -34,6 +34,18 @@
#include <google/protobuf/stubs/macros.h>
+// Define thread-safety annotations for use below, if we are building with
+// Clang.
+#if defined(__clang__) && !defined(SWIG)
+#define GOOGLE_PROTOBUF_ACQUIRE(...) \
+ __attribute__((acquire_capability(__VA_ARGS__)))
+#define GOOGLE_PROTOBUF_RELEASE(...) \
+ __attribute__((release_capability(__VA_ARGS__)))
+#else
+#define GOOGLE_PROTOBUF_ACQUIRE(...)
+#define GOOGLE_PROTOBUF_RELEASE(...)
+#endif
+
// ===================================================================
// emulates google3/base/mutex.h
namespace google {
@@ -48,8 +60,8 @@ namespace internal {
class LIBPROTOBUF_EXPORT WrappedMutex {
public:
WrappedMutex() = default;
- void Lock() { mu_.lock(); }
- void Unlock() { mu_.unlock(); }
+ void Lock() GOOGLE_PROTOBUF_ACQUIRE() { mu_.lock(); }
+ void Unlock() GOOGLE_PROTOBUF_RELEASE() { mu_.unlock(); }
// Crash if this Mutex is not held exclusively by this thread.
// May fail to crash when it should; will never crash when it should not.
void AssertHeld() const {}
@@ -123,8 +135,10 @@ using internal::ReaderMutexLock;
using internal::WriterMutexLock;
using internal::MutexLockMaybe;
-
} // namespace protobuf
} // namespace google
+#undef GOOGLE_PROTOBUF_ACQUIRE
+#undef GOOGLE_PROTOBUF_RELEASE
+
#endif // GOOGLE_PROTOBUF_STUBS_MUTEX_H_
diff --git a/src/google/protobuf/stubs/platform_macros.h b/src/google/protobuf/stubs/platform_macros.h
index c3a64dd2..ff4dea7b 100644
--- a/src/google/protobuf/stubs/platform_macros.h
+++ b/src/google/protobuf/stubs/platform_macros.h
@@ -99,6 +99,7 @@ GOOGLE_PROTOBUF_PLATFORM_ERROR
#if defined(__APPLE__)
#define GOOGLE_PROTOBUF_OS_APPLE
+#include <Availability.h>
#include <TargetConditionals.h>
#if TARGET_OS_IPHONE
#define GOOGLE_PROTOBUF_OS_IPHONE
@@ -125,4 +126,9 @@ GOOGLE_PROTOBUF_PLATFORM_ERROR
#define GOOGLE_PROTOBUF_NO_THREADLOCAL
#endif
+#if defined(__MAC_OS_X_VERSION_MIN_REQUIRED) && __MAC_OS_X_VERSION_MIN_REQUIRED < 1070
+// __thread keyword requires at least 10.7
+#define GOOGLE_PROTOBUF_NO_THREADLOCAL
+#endif
+
#endif // GOOGLE_PROTOBUF_PLATFORM_MACROS_H_
diff --git a/src/google/protobuf/timestamp.pb.cc b/src/google/protobuf/timestamp.pb.cc
index 8e6b5f23..3184bd97 100644
--- a/src/google/protobuf/timestamp.pb.cc
+++ b/src/google/protobuf/timestamp.pb.cc
@@ -66,14 +66,14 @@ static ::google::protobuf::Message const * const file_default_instances[] = {
reinterpret_cast<const ::google::protobuf::Message*>(&::google::protobuf::_Timestamp_default_instance_),
};
-void protobuf_AssignDescriptors() {
+static void protobuf_AssignDescriptors() {
AddDescriptors();
AssignDescriptors(
"google/protobuf/timestamp.proto", schemas, file_default_instances, TableStruct::offsets,
file_level_metadata, NULL, NULL);
}
-void protobuf_AssignDescriptorsOnce() {
+static void protobuf_AssignDescriptorsOnce() {
static ::google::protobuf::internal::once_flag once;
::google::protobuf::internal::call_once(once, protobuf_AssignDescriptors);
}
@@ -84,7 +84,7 @@ void protobuf_RegisterTypes(const ::std::string&) {
::google::protobuf::internal::RegisterAllTypes(file_level_metadata, 1);
}
-void AddDescriptorsImpl() {
+static void AddDescriptorsImpl() {
InitDefaults();
static const char descriptor[] GOOGLE_PROTOBUF_ATTRIBUTE_SECTION_VARIABLE(protodesc_cold) = {
"\n\037google/protobuf/timestamp.proto\022\017googl"
diff --git a/src/google/protobuf/type.pb.cc b/src/google/protobuf/type.pb.cc
index 130af52a..17d5ce2a 100644
--- a/src/google/protobuf/type.pb.cc
+++ b/src/google/protobuf/type.pb.cc
@@ -219,14 +219,14 @@ static ::google::protobuf::Message const * const file_default_instances[] = {
reinterpret_cast<const ::google::protobuf::Message*>(&::google::protobuf::_Option_default_instance_),
};
-void protobuf_AssignDescriptors() {
+static void protobuf_AssignDescriptors() {
AddDescriptors();
AssignDescriptors(
"google/protobuf/type.proto", schemas, file_default_instances, TableStruct::offsets,
file_level_metadata, file_level_enum_descriptors, NULL);
}
-void protobuf_AssignDescriptorsOnce() {
+static void protobuf_AssignDescriptorsOnce() {
static ::google::protobuf::internal::once_flag once;
::google::protobuf::internal::call_once(once, protobuf_AssignDescriptors);
}
@@ -237,7 +237,7 @@ void protobuf_RegisterTypes(const ::std::string&) {
::google::protobuf::internal::RegisterAllTypes(file_level_metadata, 5);
}
-void AddDescriptorsImpl() {
+static void AddDescriptorsImpl() {
InitDefaults();
static const char descriptor[] GOOGLE_PROTOBUF_ATTRIBUTE_SECTION_VARIABLE(protodesc_cold) = {
"\n\032google/protobuf/type.proto\022\017google.pro"
diff --git a/src/google/protobuf/util/internal/proto_writer.h b/src/google/protobuf/util/internal/proto_writer.h
index 28496963..f2b4f42f 100644
--- a/src/google/protobuf/util/internal/proto_writer.h
+++ b/src/google/protobuf/util/internal/proto_writer.h
@@ -110,7 +110,7 @@ class LIBPROTOBUF_EXPORT ProtoWriter : public StructuredObjectWriter {
return RenderDataPiece(name,
DataPiece(value, use_strict_base64_decoding()));
}
- virtual ProtoWriter* RenderBytes(StringPiece name, StringPiece value) {
+ ProtoWriter* RenderBytes(StringPiece name, StringPiece value) override {
return RenderDataPiece(
name, DataPiece(value, false, use_strict_base64_decoding()));
}
diff --git a/src/google/protobuf/util/internal/protostream_objectsource.cc b/src/google/protobuf/util/internal/protostream_objectsource.cc
index 56e6db12..b0d86c17 100644
--- a/src/google/protobuf/util/internal/protostream_objectsource.cc
+++ b/src/google/protobuf/util/internal/protostream_objectsource.cc
@@ -648,6 +648,13 @@ Status ProtoStreamObjectSource::RenderAny(const ProtoStreamObjectSource* os,
// using a nested ProtoStreamObjectSource using our nested type information.
ProtoStreamObjectSource nested_os(&in_stream, os->typeinfo_, *nested_type);
+ // TODO(htuch): This is somewhat fragile, since new options may be omitted.
+ // We should probably do this via the constructor or some object grouping
+ // options.
+ nested_os.set_use_lower_camel_for_enums(os->use_lower_camel_for_enums_);
+ nested_os.set_use_ints_for_enums(os->use_ints_for_enums_);
+ nested_os.set_preserve_proto_field_names(os->preserve_proto_field_names_);
+
// We manually call start and end object here so we can inject the @type.
ow->StartObject(field_name);
ow->RenderString("@type", type_url);
diff --git a/src/google/protobuf/util/internal/protostream_objectsource_test.cc b/src/google/protobuf/util/internal/protostream_objectsource_test.cc
index df790728..4d86b856 100644
--- a/src/google/protobuf/util/internal/protostream_objectsource_test.cc
+++ b/src/google/protobuf/util/internal/protostream_objectsource_test.cc
@@ -100,6 +100,7 @@ class ProtostreamObjectSourceTest
ow_(&mock_),
use_lower_camel_for_enums_(false),
use_ints_for_enums_(false),
+ use_preserve_proto_field_names_(false),
add_trailing_zeros_(false),
render_unknown_enum_values_(true) {
helper_.ResetTypeInfo(Book::descriptor(), Proto3Message::descriptor());
@@ -123,6 +124,7 @@ class ProtostreamObjectSourceTest
helper_.NewProtoSource(&in_stream, GetTypeUrl(descriptor)));
if (use_lower_camel_for_enums_) os->set_use_lower_camel_for_enums(true);
if (use_ints_for_enums_) os->set_use_ints_for_enums(true);
+ if (use_preserve_proto_field_names_) os->set_preserve_proto_field_names(true);
os->set_max_recursion_depth(64);
return os->WriteTo(&mock_);
}
@@ -272,6 +274,8 @@ class ProtostreamObjectSourceTest
void UseIntsForEnums() { use_ints_for_enums_ = true; }
+ void UsePreserveProtoFieldNames() { use_preserve_proto_field_names_ = true; }
+
void AddTrailingZeros() { add_trailing_zeros_ = true; }
void SetRenderUnknownEnumValues(bool value) {
@@ -284,6 +288,7 @@ class ProtostreamObjectSourceTest
ExpectingObjectWriter ow_;
bool use_lower_camel_for_enums_;
bool use_ints_for_enums_;
+ bool use_preserve_proto_field_names_;
bool add_trailing_zeros_;
bool render_unknown_enum_values_;
};
@@ -536,6 +541,16 @@ TEST_P(ProtostreamObjectSourceTest, UseIntsForEnumsTest) {
DoTest(book, Book::descriptor());
}
+TEST_P(ProtostreamObjectSourceTest, UsePreserveProtoFieldNames) {
+ Book book;
+ book.set_snake_field("foo");
+
+ UsePreserveProtoFieldNames();
+
+ ow_.StartObject("")->RenderString("snake_field", "foo")->EndObject();
+ DoTest(book, Book::descriptor());
+}
+
TEST_P(ProtostreamObjectSourceTest,
UnknownEnumAreDroppedWhenRenderUnknownEnumValuesIsUnset) {
Proto3Message message;
@@ -769,6 +784,69 @@ TEST_P(ProtostreamObjectSourceAnysTest, BasicAny) {
DoTest(out, AnyOut::descriptor());
}
+TEST_P(ProtostreamObjectSourceAnysTest, LowerCamelEnumOutputSnakeCase) {
+ AnyOut out;
+ ::google::protobuf::Any* any = out.mutable_any();
+
+ Book book;
+ book.set_type(Book::arts_and_photography);
+ any->PackFrom(book);
+
+ UseLowerCamelForEnums();
+
+ ow_.StartObject("")
+ ->StartObject("any")
+ ->RenderString("@type",
+ "type.googleapis.com/google.protobuf.testing.Book")
+ ->RenderString("type", "artsAndPhotography")
+ ->EndObject()
+ ->EndObject();
+
+ DoTest(out, AnyOut::descriptor());
+}
+
+TEST_P(ProtostreamObjectSourceAnysTest, UseIntsForEnumsTest) {
+ AnyOut out;
+ ::google::protobuf::Any* any = out.mutable_any();
+
+ Book book;
+ book.set_type(Book::ACTION_AND_ADVENTURE);
+ any->PackFrom(book);
+
+ UseIntsForEnums();
+
+ ow_.StartObject("")
+ ->StartObject("any")
+ ->RenderString("@type",
+ "type.googleapis.com/google.protobuf.testing.Book")
+ ->RenderInt32("type", 3)
+ ->EndObject()
+ ->EndObject();
+
+ DoTest(out, AnyOut::descriptor());
+}
+
+TEST_P(ProtostreamObjectSourceAnysTest, UsePreserveProtoFieldNames) {
+ AnyOut out;
+ ::google::protobuf::Any* any = out.mutable_any();
+
+ Book book;
+ book.set_snake_field("foo");
+ any->PackFrom(book);
+
+ UsePreserveProtoFieldNames();
+
+ ow_.StartObject("")
+ ->StartObject("any")
+ ->RenderString("@type",
+ "type.googleapis.com/google.protobuf.testing.Book")
+ ->RenderString("snake_field", "foo")
+ ->EndObject()
+ ->EndObject();
+
+ DoTest(out, AnyOut::descriptor());
+}
+
TEST_P(ProtostreamObjectSourceAnysTest, RecursiveAny) {
AnyOut out;
::google::protobuf::Any* any = out.mutable_any();
diff --git a/src/google/protobuf/util/internal/protostream_objectwriter.cc b/src/google/protobuf/util/internal/protostream_objectwriter.cc
index 2edfd075..a1a7030a 100644
--- a/src/google/protobuf/util/internal/protostream_objectwriter.cc
+++ b/src/google/protobuf/util/internal/protostream_objectwriter.cc
@@ -534,7 +534,7 @@ ProtoStreamObjectWriter* ProtoStreamObjectWriter::StartObject(
Push("", Item::MESSAGE, false, false);
ProtoWriter::RenderDataPiece("key",
DataPiece(name, use_strict_base64_decoding()));
- Push("value", Item::MESSAGE, true, false);
+ Push("value", IsAny(*Lookup("value")) ? Item::ANY : Item::MESSAGE, true, false);
// Make sure we are valid so far after starting map fields.
if (invalid_depth() > 0) return this;
diff --git a/src/google/protobuf/util/internal/protostream_objectwriter_test.cc b/src/google/protobuf/util/internal/protostream_objectwriter_test.cc
index 7f0df567..9c50e7dd 100644
--- a/src/google/protobuf/util/internal/protostream_objectwriter_test.cc
+++ b/src/google/protobuf/util/internal/protostream_objectwriter_test.cc
@@ -1679,6 +1679,22 @@ TEST_P(ProtoStreamObjectWriterMapTest, RepeatedMapKeyTest) {
->EndObject();
}
+TEST_P(ProtoStreamObjectWriterMapTest, AnyInMap) {
+ MapIn mm;
+ google::protobuf::DoubleValue d;
+ d.set_value(40.2);
+ (*mm.mutable_map_any())["foo"].PackFrom(d);
+ ow_->StartObject("")
+ ->StartObject("map_any")
+ ->StartObject("foo")
+ ->RenderString("@type", "type.googleapis.com/google.protobuf.DoubleValue")
+ ->RenderDouble("value", 40.2)
+ ->EndObject()
+ ->EndObject()
+ ->EndObject();
+ CheckOutput(mm);
+}
+
class ProtoStreamObjectWriterAnyTest : public BaseProtoStreamObjectWriterTest {
protected:
ProtoStreamObjectWriterAnyTest() {
diff --git a/src/google/protobuf/util/internal/testdata/books.proto b/src/google/protobuf/util/internal/testdata/books.proto
index 5630cc78..5e08a291 100644
--- a/src/google/protobuf/util/internal/testdata/books.proto
+++ b/src/google/protobuf/util/internal/testdata/books.proto
@@ -69,6 +69,9 @@ message Book {
}
optional Type type = 11;
+ // Useful for testing JSON snake/camel-case conversions.
+ optional string snake_field = 12;
+
extensions 200 to 499;
}
diff --git a/src/google/protobuf/util/internal/testdata/maps.proto b/src/google/protobuf/util/internal/testdata/maps.proto
index 0f381b32..765254ea 100644
--- a/src/google/protobuf/util/internal/testdata/maps.proto
+++ b/src/google/protobuf/util/internal/testdata/maps.proto
@@ -32,6 +32,8 @@ syntax = "proto3";
package google.protobuf.testing;
+import "google/protobuf/any.proto";
+
// Top-level test cases proto used by MarshallingTest. See description
// at the top of the class MarshallingTest for details on how to write
// test cases.
@@ -103,6 +105,7 @@ message MapIn {
string other = 1;
repeated string things = 2;
map<string, string> map_input = 3;
+ map<string, google.protobuf.Any> map_any = 4;
}
message MapOut {
diff --git a/src/google/protobuf/util/json_util.cc b/src/google/protobuf/util/json_util.cc
index f81a7a30..9ad073d8 100644
--- a/src/google/protobuf/util/json_util.cc
+++ b/src/google/protobuf/util/json_util.cc
@@ -127,7 +127,8 @@ class StatusErrorListener : public converter::ErrorListener {
virtual void InvalidName(const converter::LocationTrackerInterface& loc,
StringPiece unknown_name, StringPiece message) {
status_ = util::Status(util::error::INVALID_ARGUMENT,
- loc.ToString() + ": " + string(message));
+ loc.ToString() + ": invalid name " +
+ string(unknown_name) + ": " + string(message));
}
virtual void InvalidValue(const converter::LocationTrackerInterface& loc,
diff --git a/src/google/protobuf/util/json_util_test.cc b/src/google/protobuf/util/json_util_test.cc
index ed9092df..a2a84b57 100644
--- a/src/google/protobuf/util/json_util_test.cc
+++ b/src/google/protobuf/util/json_util_test.cc
@@ -284,7 +284,7 @@ TEST_F(JsonUtilTest, ParsePrimitiveMapIn) {
JsonPrintOptions print_options;
print_options.always_print_primitive_fields = true;
JsonParseOptions parse_options;
- EXPECT_EQ("{\"other\":\"\",\"things\":[],\"mapInput\":{}}",
+ EXPECT_EQ("{\"other\":\"\",\"things\":[],\"mapInput\":{},\"mapAny\":{}}",
ToJson(message, print_options));
MapIn other;
ASSERT_TRUE(FromJson(ToJson(message, print_options), &other, parse_options));
diff --git a/src/google/protobuf/wrappers.pb.cc b/src/google/protobuf/wrappers.pb.cc
index ffd905f5..386be61d 100644
--- a/src/google/protobuf/wrappers.pb.cc
+++ b/src/google/protobuf/wrappers.pb.cc
@@ -289,14 +289,14 @@ static ::google::protobuf::Message const * const file_default_instances[] = {
reinterpret_cast<const ::google::protobuf::Message*>(&::google::protobuf::_BytesValue_default_instance_),
};
-void protobuf_AssignDescriptors() {
+static void protobuf_AssignDescriptors() {
AddDescriptors();
AssignDescriptors(
"google/protobuf/wrappers.proto", schemas, file_default_instances, TableStruct::offsets,
file_level_metadata, NULL, NULL);
}
-void protobuf_AssignDescriptorsOnce() {
+static void protobuf_AssignDescriptorsOnce() {
static ::google::protobuf::internal::once_flag once;
::google::protobuf::internal::call_once(once, protobuf_AssignDescriptors);
}
@@ -307,7 +307,7 @@ void protobuf_RegisterTypes(const ::std::string&) {
::google::protobuf::internal::RegisterAllTypes(file_level_metadata, 9);
}
-void AddDescriptorsImpl() {
+static void AddDescriptorsImpl() {
InitDefaults();
static const char descriptor[] GOOGLE_PROTOBUF_ATTRIBUTE_SECTION_VARIABLE(protodesc_cold) = {
"\n\036google/protobuf/wrappers.proto\022\017google"