Down Integrate Internal Changes
diff --git a/BUILD b/BUILD index 07e8317..f887912 100644 --- a/BUILD +++ b/BUILD
@@ -190,7 +190,6 @@ "src/google/protobuf/service.cc", "src/google/protobuf/source_context.pb.cc", "src/google/protobuf/struct.pb.cc", - "src/google/protobuf/stubs/mathlimits.cc", "src/google/protobuf/stubs/substitute.cc", "src/google/protobuf/text_format.cc", "src/google/protobuf/timestamp.pb.cc",
diff --git a/cmake/libprotobuf.cmake b/cmake/libprotobuf.cmake index 710b34c..0c12596 100644 --- a/cmake/libprotobuf.cmake +++ b/cmake/libprotobuf.cmake
@@ -23,7 +23,6 @@ ${protobuf_source_dir}/src/google/protobuf/service.cc ${protobuf_source_dir}/src/google/protobuf/source_context.pb.cc ${protobuf_source_dir}/src/google/protobuf/struct.pb.cc - ${protobuf_source_dir}/src/google/protobuf/stubs/mathlimits.cc ${protobuf_source_dir}/src/google/protobuf/stubs/substitute.cc ${protobuf_source_dir}/src/google/protobuf/text_format.cc ${protobuf_source_dir}/src/google/protobuf/timestamp.pb.cc @@ -77,7 +76,6 @@ ${protobuf_source_dir}/src/google/protobuf/service.h ${protobuf_source_dir}/src/google/protobuf/source_context.pb.h ${protobuf_source_dir}/src/google/protobuf/struct.pb.h - ${protobuf_source_dir}/src/google/protobuf/stubs/mathlimits.h ${protobuf_source_dir}/src/google/protobuf/stubs/substitute.h ${protobuf_source_dir}/src/google/protobuf/text_format.h ${protobuf_source_dir}/src/google/protobuf/timestamp.pb.h
diff --git a/conformance/ConformanceJava.java b/conformance/ConformanceJava.java index c5b3f4e..fa4dfb7 100644 --- a/conformance/ConformanceJava.java +++ b/conformance/ConformanceJava.java
@@ -1,3 +1,33 @@ +// 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. + import com.google.protobuf.AbstractMessage; import com.google.protobuf.ByteString; import com.google.protobuf.CodedInputStream;
diff --git a/conformance/ConformanceJavaLite.java b/conformance/ConformanceJavaLite.java index 016f793..147738d 100644 --- a/conformance/ConformanceJavaLite.java +++ b/conformance/ConformanceJavaLite.java
@@ -1,3 +1,32 @@ +// 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. import com.google.protobuf.conformance.Conformance; import com.google.protobuf.InvalidProtocolBufferException;
diff --git a/conformance/binary_json_conformance_suite.cc b/conformance/binary_json_conformance_suite.cc index c1747bd..d297ae3 100644 --- a/conformance/binary_json_conformance_suite.cc +++ b/conformance/binary_json_conformance_suite.cc
@@ -29,18 +29,18 @@ // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #include "binary_json_conformance_suite.h" -#include "conformance_test.h" -#include "third_party/jsoncpp/json.h" -#include <google/protobuf/test_messages_proto3.pb.h> -#include <google/protobuf/test_messages_proto2.pb.h> - -#include <google/protobuf/stubs/common.h> -#include <google/protobuf/stubs/strutil.h> #include <google/protobuf/text_format.h> +#include <google/protobuf/wire_format_lite.h> #include <google/protobuf/util/json_util.h> #include <google/protobuf/util/type_resolver_util.h> -#include <google/protobuf/wire_format_lite.h> +#include "third_party/jsoncpp/json.h" +#include "conformance_test.h" +#include <google/protobuf/test_messages_proto2.pb.h> +#include <google/protobuf/test_messages_proto3.pb.h> +#include <google/protobuf/stubs/status.h> + +namespace proto2_messages = protobuf_test_messages::proto2; using conformance::ConformanceRequest; using conformance::ConformanceResponse; @@ -48,11 +48,11 @@ using google::protobuf::Descriptor; using google::protobuf::FieldDescriptor; using google::protobuf::Message; -using google::protobuf::internal::WireFormatLite; using google::protobuf::TextFormat; +using google::protobuf::internal::WireFormatLite; using google::protobuf::util::NewTypeResolverForDescriptorPool; +using proto2_messages::TestAllTypesProto2; using protobuf_test_messages::proto3::TestAllTypesProto3; -using protobuf_test_messages::proto2::TestAllTypesProto2; using std::string; namespace { @@ -249,10 +249,9 @@ if (packed == Packed::FALSE) { packed_string = "Unpacked "; } - GOOGLE_LOG(FATAL) << "Couldn't find field with type: " - << repeated_string.c_str() << packed_string.c_str() - << FieldDescriptor::TypeName(type) << " for " - << proto_string.c_str(); + GOOGLE_LOG(FATAL) << "Couldn't find field with type: " << repeated_string.c_str() + << packed_string.c_str() << FieldDescriptor::TypeName(type) + << " for " << proto_string.c_str(); return nullptr; } @@ -275,9 +274,9 @@ const string proto_string = is_proto3 ? "Proto3" : "Proto2"; GOOGLE_LOG(FATAL) << "Couldn't find map field with type: " - << FieldDescriptor::TypeName(key_type) << " and " - << FieldDescriptor::TypeName(key_type) << " for " - << proto_string.c_str(); + << FieldDescriptor::TypeName(key_type) << " and " + << FieldDescriptor::TypeName(key_type) << " for " + << proto_string.c_str(); return nullptr; } @@ -295,8 +294,8 @@ const string proto_string = is_proto3 ? "Proto3" : "Proto2"; GOOGLE_LOG(FATAL) << "Couldn't find oneof field with type: " - << FieldDescriptor::TypeName(type) << " for " - << proto_string.c_str(); + << FieldDescriptor::TypeName(type) << " for " + << proto_string.c_str(); return nullptr; } @@ -364,9 +363,8 @@ } if (!test_message->ParseFromString(binary_protobuf)) { - GOOGLE_LOG(FATAL) - << "INTERNAL ERROR: internal JSON->protobuf transcode " - << "yielded unparseable proto."; + GOOGLE_LOG(FATAL) << "INTERNAL ERROR: internal JSON->protobuf transcode " + << "yielded unparseable proto."; return false; } @@ -385,10 +383,11 @@ switch (response.result_case()) { case ConformanceResponse::kProtobufPayload: { if (requested_output != conformance::PROTOBUF) { - ReportFailure( - test_name, level, request, response, - StrCat("Test was asked for ", WireFormatToString(requested_output), - " output but provided PROTOBUF instead.").c_str()); + ReportFailure(test_name, level, request, response, + StrCat("Test was asked for ", + WireFormatToString(requested_output), + " output but provided PROTOBUF instead.") + .c_str()); return false; } @@ -403,10 +402,11 @@ case ConformanceResponse::kJsonPayload: { if (requested_output != conformance::JSON) { - ReportFailure( - test_name, level, request, response, - StrCat("Test was asked for ", WireFormatToString(requested_output), - " output but provided JSON instead.").c_str()); + ReportFailure(test_name, level, request, response, + StrCat("Test was asked for ", + WireFormatToString(requested_output), + " output but provided JSON instead.") + .c_str()); return false; } @@ -420,8 +420,8 @@ } default: - GOOGLE_LOG(FATAL) << test_name << ": unknown payload type: " - << response.result_case(); + GOOGLE_LOG(FATAL) << test_name + << ": unknown payload type: " << response.result_case(); } return true; @@ -440,10 +440,9 @@ const ConformanceRequest& request = setting.GetRequest(); ConformanceResponse response; - string effective_test_name = - StrCat(setting.ConformanceLevelToString(level), - (is_proto3 ? ".Proto3" : ".Proto2"), - ".ProtobufInput.", test_name); + string effective_test_name = StrCat( + setting.ConformanceLevelToString(level), + (is_proto3 ? ".Proto3" : ".Proto2"), ".ProtobufInput.", test_name); RunTest(effective_test_name, request, &response); if (response.result_case() == ConformanceResponse::kParseError) { @@ -574,8 +573,7 @@ ConformanceResponse response; string effective_test_name = StrCat(setting.ConformanceLevelToString(level), - ".Proto3.JsonInput.", - test_name, ".Validator"); + ".Proto3.JsonInput.", test_name, ".Validator"); RunTest(effective_test_name, request, &response); @@ -617,9 +615,8 @@ prototype, test_name, input_json); const ConformanceRequest& request = setting.GetRequest(); ConformanceResponse response; - string effective_test_name = - StrCat(setting.ConformanceLevelToString(level), - ".Proto3.JsonInput.", test_name); + string effective_test_name = StrCat( + setting.ConformanceLevelToString(level), ".Proto3.JsonInput.", test_name); RunTest(effective_test_name, request, &response); if (response.result_case() == ConformanceResponse::kParseError) { @@ -635,9 +632,8 @@ void BinaryAndJsonConformanceSuite::ExpectSerializeFailureForJson( const string& test_name, ConformanceLevel level, const string& text_format) { TestAllTypesProto3 payload_message; - GOOGLE_CHECK( - TextFormat::ParseFromString(text_format, &payload_message)) - << "Failed to parse: " << text_format; + GOOGLE_CHECK(TextFormat::ParseFromString(text_format, &payload_message)) + << "Failed to parse: " << text_format; TestAllTypesProto3 prototype; ConformanceRequestSetting setting( @@ -646,9 +642,8 @@ prototype, test_name, payload_message.SerializeAsString()); const ConformanceRequest& request = setting.GetRequest(); ConformanceResponse response; - string effective_test_name = - StrCat(setting.ConformanceLevelToString(level), - ".", test_name, ".JsonOutput"); + string effective_test_name = StrCat( + setting.ConformanceLevelToString(level), ".", test_name, ".JsonOutput"); RunTest(effective_test_name, request, &response); if (response.result_case() == ConformanceResponse::kSerializeError) { @@ -772,11 +767,12 @@ test_message->MergeFromString(expected_proto); string text = test_message->DebugString(); - RunValidProtobufTest(StrCat("ValidDataScalar", type_name, "[", i, "]"), - REQUIRED, proto, text, is_proto3); + RunValidProtobufTest( + StrCat("ValidDataScalar", type_name, "[", i, "]"), REQUIRED, + proto, text, is_proto3); RunValidBinaryProtobufTest( - StrCat("ValidDataScalarBinary", type_name, "[", i, "]"), RECOMMENDED, - proto, expected_proto, is_proto3); + StrCat("ValidDataScalarBinary", type_name, "[", i, "]"), + RECOMMENDED, proto, expected_proto, is_proto3); } // Test repeated data for singular fields. @@ -856,11 +852,11 @@ // Ensures both packed and unpacked data can be parsed. RunValidProtobufTest( - StrCat("ValidDataRepeated", type_name, ".UnpackedInput"), REQUIRED, - default_proto_unpacked, text, is_proto3); + StrCat("ValidDataRepeated", type_name, ".UnpackedInput"), + REQUIRED, default_proto_unpacked, text, is_proto3); RunValidProtobufTest( - StrCat("ValidDataRepeated", type_name, ".PackedInput"), REQUIRED, - default_proto_packed, text, is_proto3); + StrCat("ValidDataRepeated", type_name, ".PackedInput"), + REQUIRED, default_proto_packed, text, is_proto3); // proto2 should encode as unpacked by default and proto3 should encode as // packed by default. @@ -868,26 +864,29 @@ ? default_proto_packed_expected : default_proto_unpacked_expected; RunValidBinaryProtobufTest(StrCat("ValidDataRepeated", type_name, - ".UnpackedInput.DefaultOutput"), + ".UnpackedInput.DefaultOutput"), RECOMMENDED, default_proto_unpacked, expected_proto, is_proto3); - RunValidBinaryProtobufTest( - StrCat("ValidDataRepeated", type_name, ".PackedInput.DefaultOutput"), - RECOMMENDED, default_proto_packed, expected_proto, is_proto3); - RunValidBinaryProtobufTest( - StrCat("ValidDataRepeated", type_name, ".UnpackedInput.PackedOutput"), - RECOMMENDED, packed_proto_unpacked, packed_proto_expected, is_proto3); - RunValidBinaryProtobufTest( - StrCat("ValidDataRepeated", type_name, ".PackedInput.PackedOutput"), - RECOMMENDED, packed_proto_packed, packed_proto_expected, is_proto3); RunValidBinaryProtobufTest(StrCat("ValidDataRepeated", type_name, - ".UnpackedInput.UnpackedOutput"), + ".PackedInput.DefaultOutput"), + RECOMMENDED, default_proto_packed, + expected_proto, is_proto3); + RunValidBinaryProtobufTest(StrCat("ValidDataRepeated", type_name, + ".UnpackedInput.PackedOutput"), + RECOMMENDED, packed_proto_unpacked, + packed_proto_expected, is_proto3); + RunValidBinaryProtobufTest(StrCat("ValidDataRepeated", type_name, + ".PackedInput.PackedOutput"), + RECOMMENDED, packed_proto_packed, + packed_proto_expected, is_proto3); + RunValidBinaryProtobufTest(StrCat("ValidDataRepeated", type_name, + ".UnpackedInput.UnpackedOutput"), RECOMMENDED, unpacked_proto_unpacked, unpacked_proto_expected, is_proto3); - RunValidBinaryProtobufTest( - StrCat("ValidDataRepeated", type_name, ".PackedInput.UnpackedOutput"), - RECOMMENDED, unpacked_proto_packed, unpacked_proto_expected, - is_proto3); + RunValidBinaryProtobufTest(StrCat("ValidDataRepeated", type_name, + ".PackedInput.UnpackedOutput"), + RECOMMENDED, unpacked_proto_packed, + unpacked_proto_expected, is_proto3); } else { string proto; string expected_proto; @@ -900,8 +899,8 @@ test_message->MergeFromString(expected_proto); string text = test_message->DebugString(); - RunValidProtobufTest(StrCat("ValidDataRepeated", type_name), REQUIRED, - proto, text, is_proto3); + RunValidProtobufTest(StrCat("ValidDataRepeated", type_name), + REQUIRED, proto, text, is_proto3); } } } @@ -976,9 +975,9 @@ std::unique_ptr<Message> test_message = NewTestMessage(is_proto3); test_message->MergeFromString(proto); string text = test_message->DebugString(); - RunValidProtobufTest( - StrCat("ValidDataMap", key_type_name, value_type_name, ".Default"), - REQUIRED, proto, text, is_proto3); + RunValidProtobufTest(StrCat("ValidDataMap", key_type_name, + value_type_name, ".Default"), + REQUIRED, proto, text, is_proto3); } { @@ -990,7 +989,7 @@ test_message->MergeFromString(proto); string text = test_message->DebugString(); RunValidProtobufTest(StrCat("ValidDataMap", key_type_name, - value_type_name, ".MissingDefault"), + value_type_name, ".MissingDefault"), REQUIRED, proto, text, is_proto3); } @@ -1002,9 +1001,9 @@ std::unique_ptr<Message> test_message = NewTestMessage(is_proto3); test_message->MergeFromString(proto); string text = test_message->DebugString(); - RunValidProtobufTest( - StrCat("ValidDataMap", key_type_name, value_type_name, ".NonDefault"), - REQUIRED, proto, text, is_proto3); + RunValidProtobufTest(StrCat("ValidDataMap", key_type_name, + value_type_name, ".NonDefault"), + REQUIRED, proto, text, is_proto3); } { @@ -1015,9 +1014,9 @@ std::unique_ptr<Message> test_message = NewTestMessage(is_proto3); test_message->MergeFromString(proto); string text = test_message->DebugString(); - RunValidProtobufTest( - StrCat("ValidDataMap", key_type_name, value_type_name, ".Unordered"), - REQUIRED, proto, text, is_proto3); + RunValidProtobufTest(StrCat("ValidDataMap", key_type_name, + value_type_name, ".Unordered"), + REQUIRED, proto, text, is_proto3); } { @@ -1033,7 +1032,7 @@ test_message->MergeFromString(proto2); string text = test_message->DebugString(); RunValidProtobufTest(StrCat("ValidDataMap", key_type_name, - value_type_name, ".DuplicateKey"), + value_type_name, ".DuplicateKey"), REQUIRED, proto, text, is_proto3); } @@ -1045,9 +1044,10 @@ std::unique_ptr<Message> test_message = NewTestMessage(is_proto3); test_message->MergeFromString(proto); string text = test_message->DebugString(); - RunValidProtobufTest(StrCat("ValidDataMap", key_type_name, - value_type_name, ".DuplicateKeyInMapEntry"), - REQUIRED, proto, text, is_proto3); + RunValidProtobufTest( + StrCat("ValidDataMap", key_type_name, value_type_name, + ".DuplicateKeyInMapEntry"), + REQUIRED, proto, text, is_proto3); } { @@ -1058,9 +1058,10 @@ std::unique_ptr<Message> test_message = NewTestMessage(is_proto3); test_message->MergeFromString(proto); string text = test_message->DebugString(); - RunValidProtobufTest(StrCat("ValidDataMap", key_type_name, - value_type_name, ".DuplicateValueInMapEntry"), - REQUIRED, proto, text, is_proto3); + RunValidProtobufTest( + StrCat("ValidDataMap", key_type_name, value_type_name, + ".DuplicateValueInMapEntry"), + REQUIRED, proto, text, is_proto3); } } } @@ -1123,8 +1124,9 @@ test_message->MergeFromString(proto); string text = test_message->DebugString(); - RunValidProtobufTest(StrCat("ValidDataOneof", type_name, ".DefaultValue"), - REQUIRED, proto, text, is_proto3); + RunValidProtobufTest( + StrCat("ValidDataOneof", type_name, ".DefaultValue"), REQUIRED, + proto, text, is_proto3); RunValidBinaryProtobufTest( StrCat("ValidDataOneofBinary", type_name, ".DefaultValue"), RECOMMENDED, proto, proto, is_proto3); @@ -1138,8 +1140,8 @@ string text = test_message->DebugString(); RunValidProtobufTest( - StrCat("ValidDataOneof", type_name, ".NonDefaultValue"), REQUIRED, - proto, text, is_proto3); + StrCat("ValidDataOneof", type_name, ".NonDefaultValue"), + REQUIRED, proto, text, is_proto3); RunValidBinaryProtobufTest( StrCat("ValidDataOneofBinary", type_name, ".NonDefaultValue"), RECOMMENDED, proto, proto, is_proto3); @@ -1153,11 +1155,11 @@ test_message->MergeFromString(expected_proto); string text = test_message->DebugString(); - RunValidProtobufTest( - StrCat("ValidDataOneof", type_name, ".MultipleValuesForSameField"), - REQUIRED, proto, text, is_proto3); - RunValidBinaryProtobufTest(StrCat("ValidDataOneofBinary", type_name, + RunValidProtobufTest(StrCat("ValidDataOneof", type_name, ".MultipleValuesForSameField"), + REQUIRED, proto, text, is_proto3); + RunValidBinaryProtobufTest(StrCat("ValidDataOneofBinary", type_name, + ".MultipleValuesForSameField"), RECOMMENDED, proto, expected_proto, is_proto3); } @@ -1180,11 +1182,12 @@ string text = test_message->DebugString(); RunValidProtobufTest(StrCat("ValidDataOneof", type_name, - ".MultipleValuesForDifferentField"), - REQUIRED, proto, text, is_proto3); - RunValidBinaryProtobufTest(StrCat("ValidDataOneofBinary", type_name, ".MultipleValuesForDifferentField"), - RECOMMENDED, proto, expected_proto, is_proto3); + REQUIRED, proto, text, is_proto3); + RunValidBinaryProtobufTest( + StrCat("ValidDataOneofBinary", type_name, + ".MultipleValuesForDifferentField"), + RECOMMENDED, proto, expected_proto, is_proto3); } } } @@ -1292,7 +1295,7 @@ void BinaryAndJsonConformanceSuite::RunSuiteImpl() { // Hack to get the list of test failures based on whether - // GOOGLE3_PROTOBUF_ENABLE_EXPERIMENTAL_PARSER is enabled or not. + // GOOGLE_PROTOBUF_ENABLE_EXPERIMENTAL_PARSER is enabled or not. conformance::FailureSet failure_set; ConformanceRequest req; ConformanceResponse res; @@ -1363,6 +1366,8 @@ {varint(kInt32Min), varint(kInt32Min)}, {varint(1LL << 33), varint(0)}, {varint((1LL << 33) - 1), varint(-1)}, + {varint(kInt64Max), varint(-1)}, + {varint(kInt64Min + 1), varint(1)}, }); TestValidDataForType( FieldDescriptor::TYPE_UINT32, @@ -1373,7 +1378,10 @@ {longvarint(12345, 7), varint(12345)}, {varint(kUint32Max), varint(kUint32Max)}, // UINT32_MAX {varint(1LL << 33), varint(0)}, + {varint((1LL << 33) + 1), varint(1)}, {varint((1LL << 33) - 1), varint((1LL << 32) - 1)}, + {varint(kInt64Max), varint((1LL << 32) - 1)}, + {varint(kInt64Min + 1), varint(1)}, }); TestValidDataForType(FieldDescriptor::TYPE_FIXED64, { @@ -1407,7 +1415,11 @@ { {varint(0), varint(0)}, {varint(1), varint(1)}, + {varint(-1), varint(1)}, {varint(12345678), varint(1)}, + {varint(1LL << 33), varint(1)}, + {varint(kInt64Max), varint(1)}, + {varint(kInt64Min), varint(1)}, }); TestValidDataForType(FieldDescriptor::TYPE_SINT32, { @@ -1415,6 +1427,7 @@ {zz32(12345), zz32(12345)}, {zz32(kInt32Max), zz32(kInt32Max)}, {zz32(kInt32Min), zz32(kInt32Min)}, + {zz64(kInt32Max + 2LL), zz32(1)}, }); TestValidDataForType(FieldDescriptor::TYPE_SINT64, { @@ -1438,15 +1451,19 @@ TestValidDataForType(FieldDescriptor::TYPE_BYTES, { {delim(""), delim("")}, + {delim("Hello world!"), delim("Hello world!")}, {delim("\x01\x02"), delim("\x01\x02")}, {delim("\xfb"), delim("\xfb")}, }); - TestValidDataForType(FieldDescriptor::TYPE_ENUM, { - {varint(0), varint(0)}, - {varint(1), varint(1)}, - {varint(2), varint(2)}, - {varint(-1), varint(-1)}, - }); + TestValidDataForType(FieldDescriptor::TYPE_ENUM, + { + {varint(0), varint(0)}, + {varint(1), varint(1)}, + {varint(2), varint(2)}, + {varint(-1), varint(-1)}, + {varint(kInt64Max), varint(-1)}, + {varint(kInt64Min + 1), varint(1)}, + }); TestValidDataForRepeatedScalarMessage(); TestValidDataForType( FieldDescriptor::TYPE_MESSAGE, @@ -1508,13 +1525,74 @@ // TODO(haberman): // TestValidDataForType(FieldDescriptor::TYPE_GROUP + // Unknown fields. + { + TestAllTypesProto3 messageProto3; + TestAllTypesProto2 messageProto2; + // TODO(yilunchong): update this behavior when unknown field's behavior + // changed in open source. Also delete + // Required.Proto3.ProtobufInput.UnknownVarint.ProtobufOutput + // from failure list of python_cpp python java + TestUnknownMessage(messageProto3, true); + TestUnknownMessage(messageProto2, false); + } + + RunJsonTests(); +} + +void BinaryAndJsonConformanceSuite::RunJsonTests() { RunValidJsonTest("HelloWorld", REQUIRED, "{\"optionalString\":\"Hello, World!\"}", "optional_string: 'Hello, World!'"); // NOTE: The spec for JSON support is still being sorted out, these may not // all be correct. - // Test field name conventions. + + RunJsonTestsForFieldNameConvention(); + RunJsonTestsForNonRepeatedTypes(); + RunJsonTestsForRepeatedTypes(); + RunJsonTestsForNullTypes(); + RunJsonTestsForWrapperTypes(); + RunJsonTestsForFieldMask(); + RunJsonTestsForStruct(); + RunJsonTestsForValue(); + RunJsonTestsForAny(); + + RunValidJsonIgnoreUnknownTest("IgnoreUnknownJsonNumber", REQUIRED, + R"({ + "unknown": 1 + })", + ""); + RunValidJsonIgnoreUnknownTest("IgnoreUnknownJsonString", REQUIRED, + R"({ + "unknown": "a" + })", + ""); + RunValidJsonIgnoreUnknownTest("IgnoreUnknownJsonTrue", REQUIRED, + R"({ + "unknown": true + })", + ""); + RunValidJsonIgnoreUnknownTest("IgnoreUnknownJsonFalse", REQUIRED, + R"({ + "unknown": false + })", + ""); + RunValidJsonIgnoreUnknownTest("IgnoreUnknownJsonNull", REQUIRED, + R"({ + "unknown": null + })", + ""); + RunValidJsonIgnoreUnknownTest("IgnoreUnknownJsonObject", REQUIRED, + R"({ + "unknown": {"a": 1} + })", + ""); + + ExpectParseFailureForJson("RejectTopLevelNull", REQUIRED, "null"); +} + +void BinaryAndJsonConformanceSuite::RunJsonTestsForFieldNameConvention() { RunValidJsonTest( "FieldNameInSnakeCase", REQUIRED, R"({ @@ -1769,7 +1847,9 @@ value.isMember("fieldName17") && value.isMember("FieldName18"); }); +} +void BinaryAndJsonConformanceSuite::RunJsonTestsForNonRepeatedTypes() { // Integer fields. RunValidJsonTest( "Int32FieldMaxValue", REQUIRED, @@ -2254,71 +2334,6 @@ "OneofZeroEnum", RECOMMENDED, R"({"oneofEnum":"FOO"})", "oneof_enum: FOO"); - // Repeated fields. - RunValidJsonTest( - "PrimitiveRepeatedField", REQUIRED, - R"({"repeatedInt32": [1, 2, 3, 4]})", - "repeated_int32: [1, 2, 3, 4]"); - RunValidJsonTest( - "EnumRepeatedField", REQUIRED, - R"({"repeatedNestedEnum": ["FOO", "BAR", "BAZ"]})", - "repeated_nested_enum: [FOO, BAR, BAZ]"); - RunValidJsonTest( - "StringRepeatedField", REQUIRED, - R"({"repeatedString": ["Hello", "world"]})", - R"(repeated_string: ["Hello", "world"])"); - RunValidJsonTest( - "BytesRepeatedField", REQUIRED, - R"({"repeatedBytes": ["AAEC", "AQI="]})", - R"(repeated_bytes: ["\x00\x01\x02", "\x01\x02"])"); - RunValidJsonTest( - "MessageRepeatedField", REQUIRED, - R"({"repeatedNestedMessage": [{"a": 1234}, {"a": 5678}]})", - "repeated_nested_message: {a: 1234}" - "repeated_nested_message: {a: 5678}"); - - // Repeated field elements are of incorrect type. - ExpectParseFailureForJson( - "RepeatedFieldWrongElementTypeExpectingIntegersGotBool", REQUIRED, - R"({"repeatedInt32": [1, false, 3, 4]})"); - ExpectParseFailureForJson( - "RepeatedFieldWrongElementTypeExpectingIntegersGotString", REQUIRED, - R"({"repeatedInt32": [1, 2, "name", 4]})"); - ExpectParseFailureForJson( - "RepeatedFieldWrongElementTypeExpectingIntegersGotMessage", REQUIRED, - R"({"repeatedInt32": [1, 2, 3, {"a": 4}]})"); - ExpectParseFailureForJson( - "RepeatedFieldWrongElementTypeExpectingStringsGotInt", REQUIRED, - R"({"repeatedString": ["1", 2, "3", "4"]})"); - ExpectParseFailureForJson( - "RepeatedFieldWrongElementTypeExpectingStringsGotBool", REQUIRED, - R"({"repeatedString": ["1", "2", false, "4"]})"); - ExpectParseFailureForJson( - "RepeatedFieldWrongElementTypeExpectingStringsGotMessage", REQUIRED, - R"({"repeatedString": ["1", 2, "3", {"a": 4}]})"); - ExpectParseFailureForJson( - "RepeatedFieldWrongElementTypeExpectingMessagesGotInt", REQUIRED, - R"({"repeatedNestedMessage": [{"a": 1}, 2]})"); - ExpectParseFailureForJson( - "RepeatedFieldWrongElementTypeExpectingMessagesGotBool", REQUIRED, - R"({"repeatedNestedMessage": [{"a": 1}, false]})"); - ExpectParseFailureForJson( - "RepeatedFieldWrongElementTypeExpectingMessagesGotString", REQUIRED, - R"({"repeatedNestedMessage": [{"a": 1}, "2"]})"); - // Trailing comma in the repeated field is not allowed. - ExpectParseFailureForJson( - "RepeatedFieldTrailingComma", RECOMMENDED, - R"({"repeatedInt32": [1, 2, 3, 4,]})"); - ExpectParseFailureForJson( - "RepeatedFieldTrailingCommaWithSpace", RECOMMENDED, - "{\"repeatedInt32\": [1, 2, 3, 4 ,]}"); - ExpectParseFailureForJson( - "RepeatedFieldTrailingCommaWithSpaceCommaSpace", RECOMMENDED, - "{\"repeatedInt32\": [1, 2, 3, 4 , ]}"); - ExpectParseFailureForJson( - "RepeatedFieldTrailingCommaWithNewlines", RECOMMENDED, - "{\"repeatedInt32\": [\n 1,\n 2,\n 3,\n 4,\n]}"); - // Map fields. RunValidJsonTest( "Int32MapField", REQUIRED, @@ -2392,6 +2407,77 @@ R"({"mapBoolBool": {"tr\u0075e": true}})", "map_bool_bool: {key: true value: true}"); + // http://www.rfc-editor.org/rfc/rfc7159.txt says strings have to use double + // quotes. + ExpectParseFailureForJson("StringFieldSingleQuoteKey", RECOMMENDED, + R"({'optionalString': "Hello world!"})"); + ExpectParseFailureForJson("StringFieldSingleQuoteValue", RECOMMENDED, + R"({"optionalString": 'Hello world!'})"); + ExpectParseFailureForJson("StringFieldSingleQuoteBoth", RECOMMENDED, + R"({'optionalString': 'Hello world!'})"); +} + +void BinaryAndJsonConformanceSuite::RunJsonTestsForRepeatedTypes() { + // Repeated fields. + RunValidJsonTest("PrimitiveRepeatedField", REQUIRED, + R"({"repeatedInt32": [1, 2, 3, 4]})", + "repeated_int32: [1, 2, 3, 4]"); + RunValidJsonTest("EnumRepeatedField", REQUIRED, + R"({"repeatedNestedEnum": ["FOO", "BAR", "BAZ"]})", + "repeated_nested_enum: [FOO, BAR, BAZ]"); + RunValidJsonTest("StringRepeatedField", REQUIRED, + R"({"repeatedString": ["Hello", "world"]})", + R"(repeated_string: ["Hello", "world"])"); + RunValidJsonTest("BytesRepeatedField", REQUIRED, + R"({"repeatedBytes": ["AAEC", "AQI="]})", + R"(repeated_bytes: ["\x00\x01\x02", "\x01\x02"])"); + RunValidJsonTest("MessageRepeatedField", REQUIRED, + R"({"repeatedNestedMessage": [{"a": 1234}, {"a": 5678}]})", + "repeated_nested_message: {a: 1234}" + "repeated_nested_message: {a: 5678}"); + + // Repeated field elements are of incorrect type. + ExpectParseFailureForJson( + "RepeatedFieldWrongElementTypeExpectingIntegersGotBool", REQUIRED, + R"({"repeatedInt32": [1, false, 3, 4]})"); + ExpectParseFailureForJson( + "RepeatedFieldWrongElementTypeExpectingIntegersGotString", REQUIRED, + R"({"repeatedInt32": [1, 2, "name", 4]})"); + ExpectParseFailureForJson( + "RepeatedFieldWrongElementTypeExpectingIntegersGotMessage", REQUIRED, + R"({"repeatedInt32": [1, 2, 3, {"a": 4}]})"); + ExpectParseFailureForJson( + "RepeatedFieldWrongElementTypeExpectingStringsGotInt", REQUIRED, + R"({"repeatedString": ["1", 2, "3", "4"]})"); + ExpectParseFailureForJson( + "RepeatedFieldWrongElementTypeExpectingStringsGotBool", REQUIRED, + R"({"repeatedString": ["1", "2", false, "4"]})"); + ExpectParseFailureForJson( + "RepeatedFieldWrongElementTypeExpectingStringsGotMessage", REQUIRED, + R"({"repeatedString": ["1", 2, "3", {"a": 4}]})"); + ExpectParseFailureForJson( + "RepeatedFieldWrongElementTypeExpectingMessagesGotInt", REQUIRED, + R"({"repeatedNestedMessage": [{"a": 1}, 2]})"); + ExpectParseFailureForJson( + "RepeatedFieldWrongElementTypeExpectingMessagesGotBool", REQUIRED, + R"({"repeatedNestedMessage": [{"a": 1}, false]})"); + ExpectParseFailureForJson( + "RepeatedFieldWrongElementTypeExpectingMessagesGotString", REQUIRED, + R"({"repeatedNestedMessage": [{"a": 1}, "2"]})"); + // Trailing comma in the repeated field is not allowed. + ExpectParseFailureForJson("RepeatedFieldTrailingComma", RECOMMENDED, + R"({"repeatedInt32": [1, 2, 3, 4,]})"); + ExpectParseFailureForJson("RepeatedFieldTrailingCommaWithSpace", RECOMMENDED, + "{\"repeatedInt32\": [1, 2, 3, 4 ,]}"); + ExpectParseFailureForJson("RepeatedFieldTrailingCommaWithSpaceCommaSpace", + RECOMMENDED, + "{\"repeatedInt32\": [1, 2, 3, 4 , ]}"); + ExpectParseFailureForJson( + "RepeatedFieldTrailingCommaWithNewlines", RECOMMENDED, + "{\"repeatedInt32\": [\n 1,\n 2,\n 3,\n 4,\n]}"); +} + +void BinaryAndJsonConformanceSuite::RunJsonTestsForNullTypes() { // "null" is accepted for all fields types. RunValidJsonTest( "AllFieldAcceptNull", REQUIRED, @@ -2451,36 +2537,12 @@ ExpectParseFailureForJson( "MapFieldValueIsNull", RECOMMENDED, R"({"mapInt32Int32": {"0": null}})"); +} - // http://www.rfc-editor.org/rfc/rfc7159.txt says strings have to use double - // quotes. - ExpectParseFailureForJson( - "StringFieldSingleQuoteKey", RECOMMENDED, - R"({'optionalString': "Hello world!"})"); - ExpectParseFailureForJson( - "StringFieldSingleQuoteValue", RECOMMENDED, - R"({"optionalString": 'Hello world!'})"); - ExpectParseFailureForJson( - "StringFieldSingleQuoteBoth", RECOMMENDED, - R"({'optionalString': 'Hello world!'})"); - - // Unknown fields. - { - TestAllTypesProto3 messageProto3; - TestAllTypesProto2 messageProto2; - //TODO(yilunchong): update this behavior when unknown field's behavior - // changed in open source. Also delete - // Required.Proto3.ProtobufInput.UnknownVarint.ProtobufOutput - // from failure list of python_cpp python java - TestUnknownMessage(messageProto3, true); - TestUnknownMessage(messageProto2, false); - } - - // Wrapper types. - RunValidJsonTest( - "OptionalBoolWrapper", REQUIRED, - R"({"optionalBoolWrapper": false})", - "optional_bool_wrapper: {value: false}"); +void BinaryAndJsonConformanceSuite::RunJsonTestsForWrapperTypes() { + RunValidJsonTest("OptionalBoolWrapper", REQUIRED, + R"({"optionalBoolWrapper": false})", + "optional_bool_wrapper: {value: false}"); RunValidJsonTest( "OptionalInt32Wrapper", REQUIRED, R"({"optionalInt32Wrapper": 0})", @@ -2689,10 +2751,9 @@ })", "repeated_timestamp: {seconds: -62135596800}" "repeated_timestamp: {seconds: 253402300799 nanos: 999999999}"); - RunValidJsonTest( - "TimestampLeap", REQUIRED, - R"({"optionalTimestamp": "1993-02-10T00:00:00.000Z"})", - "optional_timestamp: {seconds: 729302400}"); + RunValidJsonTest("TimestampLeap", REQUIRED, + R"({"optionalTimestamp": "1993-02-10T00:00:00.000Z"})", + "optional_timestamp: {seconds: 729302400}"); RunValidJsonTest("TimestampWithPositiveOffset", REQUIRED, R"({"optionalTimestamp": "1970-01-01T08:00:01+08:00"})", "optional_timestamp: {seconds: 1}"); @@ -2732,39 +2793,38 @@ "TimestampZeroNormalized", RECOMMENDED, R"({"optionalTimestamp": "1969-12-31T16:00:00-08:00"})", [](const Json::Value& value) { - return value["optionalTimestamp"].asString() == - "1970-01-01T00:00:00Z"; + return value["optionalTimestamp"].asString() == "1970-01-01T00:00:00Z"; }); RunValidJsonTestWithValidator( "TimestampHasZeroFractionalDigit", RECOMMENDED, R"({"optionalTimestamp": "1970-01-01T00:00:00.000000000Z"})", [](const Json::Value& value) { - return value["optionalTimestamp"].asString() == - "1970-01-01T00:00:00Z"; + return value["optionalTimestamp"].asString() == "1970-01-01T00:00:00Z"; }); RunValidJsonTestWithValidator( "TimestampHas3FractionalDigits", RECOMMENDED, R"({"optionalTimestamp": "1970-01-01T00:00:00.010000000Z"})", [](const Json::Value& value) { return value["optionalTimestamp"].asString() == - "1970-01-01T00:00:00.010Z"; + "1970-01-01T00:00:00.010Z"; }); RunValidJsonTestWithValidator( "TimestampHas6FractionalDigits", RECOMMENDED, R"({"optionalTimestamp": "1970-01-01T00:00:00.000010000Z"})", [](const Json::Value& value) { return value["optionalTimestamp"].asString() == - "1970-01-01T00:00:00.000010Z"; + "1970-01-01T00:00:00.000010Z"; }); RunValidJsonTestWithValidator( "TimestampHas9FractionalDigits", RECOMMENDED, R"({"optionalTimestamp": "1970-01-01T00:00:00.000000010Z"})", [](const Json::Value& value) { return value["optionalTimestamp"].asString() == - "1970-01-01T00:00:00.000000010Z"; + "1970-01-01T00:00:00.000000010Z"; }); +} - // FieldMask +void BinaryAndJsonConformanceSuite::RunJsonTestsForFieldMask() { RunValidJsonTest( "FieldMask", REQUIRED, R"({"optionalFieldMask": "foo,barBaz"})", @@ -2785,8 +2845,9 @@ ExpectSerializeFailureForJson( "FieldMaskTooManyUnderscore", RECOMMENDED, R"(optional_field_mask: {paths: "foo__bar"})"); +} - // Struct +void BinaryAndJsonConformanceSuite::RunJsonTestsForStruct() { RunValidJsonTest( "Struct", REQUIRED, R"({ @@ -2870,7 +2931,9 @@ } } )"); - // Value +} + +void BinaryAndJsonConformanceSuite::RunJsonTestsForValue() { RunValidJsonTest( "ValueAcceptInteger", REQUIRED, R"({"optionalValue": 1})", @@ -2951,8 +3014,9 @@ } ] )"); +} - // Any +void BinaryAndJsonConformanceSuite::RunJsonTestsForAny() { RunValidJsonTest( "Any", REQUIRED, R"({ @@ -3128,45 +3192,6 @@ } } )"); - - RunValidJsonIgnoreUnknownTest( - "IgnoreUnknownJsonNumber", REQUIRED, - R"({ - "unknown": 1 - })", - ""); - RunValidJsonIgnoreUnknownTest( - "IgnoreUnknownJsonString", REQUIRED, - R"({ - "unknown": "a" - })", - ""); - RunValidJsonIgnoreUnknownTest( - "IgnoreUnknownJsonTrue", REQUIRED, - R"({ - "unknown": true - })", - ""); - RunValidJsonIgnoreUnknownTest( - "IgnoreUnknownJsonFalse", REQUIRED, - R"({ - "unknown": false - })", - ""); - RunValidJsonIgnoreUnknownTest( - "IgnoreUnknownJsonNull", REQUIRED, - R"({ - "unknown": null - })", - ""); - RunValidJsonIgnoreUnknownTest( - "IgnoreUnknownJsonObject", REQUIRED, - R"({ - "unknown": {"a": 1} - })", - ""); - - ExpectParseFailureForJson("RejectTopLevelNull", REQUIRED, "null"); } } // namespace protobuf
diff --git a/conformance/binary_json_conformance_suite.h b/conformance/binary_json_conformance_suite.h index 08182b6..aaf8bb4 100644 --- a/conformance/binary_json_conformance_suite.h +++ b/conformance/binary_json_conformance_suite.h
@@ -31,8 +31,8 @@ #ifndef CONFORMANCE_BINARY_JSON_CONFORMANCE_SUITE_H #define CONFORMANCE_BINARY_JSON_CONFORMANCE_SUITE_H -#include "conformance_test.h" #include "third_party/jsoncpp/json.h" +#include "conformance_test.h" namespace google { namespace protobuf { @@ -43,6 +43,16 @@ private: void RunSuiteImpl(); + void RunJsonTests(); + void RunJsonTestsForFieldNameConvention(); + void RunJsonTestsForNonRepeatedTypes(); + void RunJsonTestsForRepeatedTypes(); + void RunJsonTestsForNullTypes(); + void RunJsonTestsForWrapperTypes(); + void RunJsonTestsForFieldMask(); + void RunJsonTestsForStruct(); + void RunJsonTestsForValue(); + void RunJsonTestsForAny(); void RunValidJsonTest(const string& test_name, ConformanceLevel level, const string& input_json, @@ -121,8 +131,7 @@ void TestMergeOneofMessage(); void TestOverwriteMessageValueMap(); - std::unique_ptr<google::protobuf::util::TypeResolver> - type_resolver_; + std::unique_ptr<google::protobuf::util::TypeResolver> type_resolver_; std::string type_url_; };
diff --git a/conformance/conformance.proto b/conformance/conformance.proto index 54da406..1db4000 100644 --- a/conformance/conformance.proto +++ b/conformance/conformance.proto
@@ -95,7 +95,7 @@ // // TODO(haberman): if/when we expand the conformance tests to support proto2, // we will want to include a field that lets the payload/response be a - // protobuf_test_messages.proto2.TestAllTypes message instead. + // protobuf_test_messages.google.protobuf.TestAllTypes message instead. oneof payload { bytes protobuf_payload = 1; string json_payload = 2; @@ -109,7 +109,7 @@ // The full name for the test message to use; for the moment, either: // protobuf_test_messages.proto3.TestAllTypesProto3 or - // protobuf_test_messages.proto2.TestAllTypesProto2. + // protobuf_test_messages.google.protobuf.TestAllTypesProto2. string message_type = 4; // Each test is given a specific test category. Some category may need
diff --git a/conformance/conformance_cpp.cc b/conformance/conformance_cpp.cc index c7f4b2d..1cdfdae 100644 --- a/conformance/conformance_cpp.cc +++ b/conformance/conformance_cpp.cc
@@ -32,13 +32,14 @@ #include <stdarg.h> #include <unistd.h> -#include "conformance.pb.h" -#include <google/protobuf/test_messages_proto3.pb.h> -#include <google/protobuf/test_messages_proto2.pb.h> #include <google/protobuf/message.h> #include <google/protobuf/text_format.h> #include <google/protobuf/util/json_util.h> #include <google/protobuf/util/type_resolver_util.h> +#include "conformance.pb.h" +#include <google/protobuf/test_messages_proto2.pb.h> +#include <google/protobuf/test_messages_proto3.pb.h> +#include <google/protobuf/stubs/status.h> using conformance::ConformanceRequest; using conformance::ConformanceResponse; @@ -51,9 +52,7 @@ using google::protobuf::util::JsonParseOptions; using google::protobuf::util::JsonToBinaryString; using google::protobuf::util::NewTypeResolverForDescriptorPool; -using google::protobuf::util::Status; using google::protobuf::util::TypeResolver; -using protobuf_test_messages::proto2::TestAllTypesProto2; using protobuf_test_messages::proto3::TestAllTypesProto3; using std::string; @@ -71,6 +70,10 @@ TypeResolver* type_resolver; string* type_url; +namespace google { +namespace protobuf { + +using util::Status; bool CheckedRead(int fd, void *buf, size_t len) { size_t ofs = 0; @@ -80,7 +83,7 @@ if (bytes_read == 0) return false; if (bytes_read < 0) { - GOOGLE_LOG(FATAL) << "Error reading from test runner: " << strerror(errno); + GOOGLE_LOG(FATAL) << "Error reading from test runner: " << strerror(errno); } len -= bytes_read; @@ -127,7 +130,7 @@ options); if (!status.ok()) { response->set_parse_error(string("Parse error: ") + - status.error_message().as_string()); + std::string(status.error_message())); return; } @@ -152,8 +155,7 @@ break; default: - GOOGLE_LOG(FATAL) << "unknown payload type: " - << request.payload_case(); + GOOGLE_LOG(FATAL) << "unknown payload type: " << request.payload_case(); break; } @@ -169,7 +171,8 @@ break; case conformance::PROTOBUF: { - GOOGLE_CHECK(test_message->SerializeToString(response->mutable_protobuf_payload())); + GOOGLE_CHECK(test_message->SerializeToString( + response->mutable_protobuf_payload())); break; } @@ -181,7 +184,7 @@ if (!status.ok()) { response->set_serialize_error( string("Failed to serialize JSON output: ") + - status.error_message().as_string()); + std::string(status.error_message())); return; } break; @@ -191,13 +194,13 @@ TextFormat::Printer printer; printer.SetHideUnknownFields(!request.print_unknown_fields()); GOOGLE_CHECK(printer.PrintToString(*test_message, - response->mutable_text_payload())); + response->mutable_text_payload())); break; } default: GOOGLE_LOG(FATAL) << "Unknown output format: " - << request.requested_output_format(); + << request.requested_output_format(); } } @@ -243,12 +246,15 @@ return true; } +} // namespace protobuf +} // namespace google + int main() { type_resolver = NewTypeResolverForDescriptorPool( kTypeUrlPrefix, DescriptorPool::generated_pool()); type_url = new string(GetTypeUrl(TestAllTypesProto3::descriptor())); while (1) { - if (!DoTestIo()) { + if (!google::protobuf::DoTestIo()) { fprintf(stderr, "conformance-cpp: received EOF from test runner " "after %d tests, exiting\n", test_count); return 0;
diff --git a/conformance/conformance_python.py b/conformance/conformance_python.py index 88d9749..37ee36e 100755 --- a/conformance/conformance_python.py +++ b/conformance/conformance_python.py
@@ -1,5 +1,4 @@ #!/usr/bin/env python -# # Protocol Buffers - Google's data interchange format # Copyright 2008 Google Inc. All rights reserved. # https://developers.google.com/protocol-buffers/ @@ -38,8 +37,6 @@ import struct import sys import os -from google.protobuf import descriptor -from google.protobuf import descriptor_pool from google.protobuf import json_format from google.protobuf import message from google.protobuf import test_messages_proto3_pb2
diff --git a/conformance/conformance_test.cc b/conformance/conformance_test.cc index 0743b5e..07b4150 100644 --- a/conformance/conformance_test.cc +++ b/conformance/conformance_test.cc
@@ -28,30 +28,28 @@ // (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 <set> -#include <stdarg.h> -#include <string> -#include <fstream> - -#include "conformance.pb.h" #include "conformance_test.h" +#include <stdarg.h> + +#include <fstream> +#include <set> +#include <string> + #include <google/protobuf/stubs/stringprintf.h> -#include <google/protobuf/stubs/strutil.h> #include <google/protobuf/message.h> #include <google/protobuf/text_format.h> #include <google/protobuf/util/field_comparator.h> #include <google/protobuf/util/json_util.h> #include <google/protobuf/util/message_differencer.h> +#include "conformance.pb.h" using conformance::ConformanceRequest; using conformance::ConformanceResponse; using conformance::WireFormat; using google::protobuf::TextFormat; using google::protobuf::util::DefaultFieldComparator; -using google::protobuf::util::JsonToBinaryString; using google::protobuf::util::MessageDifferencer; -using google::protobuf::util::Status; using std::string; namespace { @@ -120,9 +118,9 @@ request_.set_requested_output_format(output_format); } -Message* ConformanceTestSuite::ConformanceRequestSetting:: - GetTestMessage() const { - return prototype_message_for_compare_->New(); +std::unique_ptr<Message> +ConformanceTestSuite::ConformanceRequestSetting::NewTestMessage() const { + return std::unique_ptr<Message>(prototype_message_for_compare_->New()); } string ConformanceTestSuite::ConformanceRequestSetting:: @@ -131,11 +129,9 @@ prototype_message_.GetDescriptor()->file()->syntax() == FileDescriptor::SYNTAX_PROTO3 ? "Proto3" : "Proto2"; - return StrCat(ConformanceLevelToString(level_), ".", - rname, ".", - InputFormatString(input_format_), - ".", test_name_, ".", - OutputFormatString(output_format_)); + return StrCat(ConformanceLevelToString(level_), ".", rname, ".", + InputFormatString(input_format_), ".", test_name_, ".", + OutputFormatString(output_format_)); } string ConformanceTestSuite::ConformanceRequestSetting:: @@ -228,11 +224,11 @@ void ConformanceTestSuite::RunValidInputTest( const ConformanceRequestSetting& setting, const string& equivalent_text_format) { - Message* reference_message = setting.GetTestMessage(); - GOOGLE_CHECK( - TextFormat::ParseFromString(equivalent_text_format, reference_message)) - << "Failed to parse data for test case: " << setting.GetTestName() - << ", data: " << equivalent_text_format; + std::unique_ptr<Message> reference_message(setting.NewTestMessage()); + GOOGLE_CHECK(TextFormat::ParseFromString(equivalent_text_format, + reference_message.get())) + << "Failed to parse data for test case: " << setting.GetTestName() + << ", data: " << equivalent_text_format; const string equivalent_wire_format = reference_message->SerializeAsString(); RunValidBinaryInputTest(setting, equivalent_wire_format); } @@ -251,15 +247,14 @@ const ConformanceRequestSetting& setting, const string& equivalent_wire_format, const ConformanceResponse& response, bool need_report_success, bool require_same_wire_format) { - Message* test_message = setting.GetTestMessage(); + std::unique_ptr<Message> test_message(setting.NewTestMessage()); const ConformanceRequest& request = setting.GetRequest(); const string& test_name = setting.GetTestName(); ConformanceLevel level = setting.GetLevel(); - Message* reference_message = setting.GetTestMessage(); + std::unique_ptr<Message> reference_message = setting.NewTestMessage(); - GOOGLE_CHECK( - reference_message->ParseFromString(equivalent_wire_format)) - << "Failed to parse wire data for test case: " << test_name; + GOOGLE_CHECK(reference_message->ParseFromString(equivalent_wire_format)) + << "Failed to parse wire data for test case: " << test_name; switch (response.result_case()) { case ConformanceResponse::RESULT_NOT_SET: @@ -279,7 +274,7 @@ return; default: - if (!ParseResponse(response, setting, test_message)) return; + if (!ParseResponse(response, setting, test_message.get())) return; } MessageDifferencer differencer; @@ -292,12 +287,11 @@ bool check = false; if (require_same_wire_format) { - GOOGLE_DCHECK_EQ(response.result_case(), - ConformanceResponse::kProtobufPayload); + GOOGLE_DCHECK_EQ(response.result_case(), ConformanceResponse::kProtobufPayload); const string& protobuf_payload = response.protobuf_payload(); check = equivalent_wire_format == protobuf_payload; differences = StrCat("Expect: ", ToOctString(equivalent_wire_format), - ", but got: ", ToOctString(protobuf_payload)); + ", but got: ", ToOctString(protobuf_payload)); } else { check = differencer.Compare(*reference_message, *test_message); } @@ -386,8 +380,7 @@ case conformance::UNSPECIFIED: return "UNSPECIFIED"; default: - GOOGLE_LOG(FATAL) << "unknown wire type: " - << wire_format; + GOOGLE_LOG(FATAL) << "unknown wire type: " << wire_format; } return ""; } @@ -450,8 +443,8 @@ } StringAppendF(&output_, - "CONFORMANCE SUITE %s: %d successes, %d skipped, " - "%d expected failures, %d unexpected failures.\n", + "CONFORMANCE SUITE %s: %d successes, %zu skipped, " + "%d expected failures, %zu unexpected failures.\n", ok ? "PASSED" : "FAILED", successes_, skipped_.size(), expected_failures_, unexpected_failing_tests_.size()); StringAppendF(&output_, "\n");
diff --git a/conformance/conformance_test.h b/conformance/conformance_test.h index 6a993de..9f4ce37 100644 --- a/conformance/conformance_test.h +++ b/conformance/conformance_test.h
@@ -38,15 +38,13 @@ #ifndef CONFORMANCE_CONFORMANCE_TEST_H #define CONFORMANCE_CONFORMANCE_TEST_H -#include <google/protobuf/descriptor.h> -#include <google/protobuf/stubs/common.h> -#include <google/protobuf/util/type_resolver.h> -#include <google/protobuf/wire_format_lite.h> - #include <functional> #include <string> #include <vector> +#include <google/protobuf/descriptor.h> +#include <google/protobuf/wire_format_lite.h> +#include <google/protobuf/util/type_resolver.h> #include "conformance.pb.h" namespace conformance { @@ -218,7 +216,7 @@ const string& test_name, const string& input); virtual ~ConformanceRequestSetting() {} - Message* GetTestMessage() const; + std::unique_ptr<Message> NewTestMessage() const; string GetTestName() const;
diff --git a/conformance/conformance_test_runner.cc b/conformance/conformance_test_runner.cc index c68b2c7..9f893cb 100644 --- a/conformance/conformance_test_runner.cc +++ b/conformance/conformance_test_runner.cc
@@ -53,28 +53,27 @@ // 3. testee sends 4-byte length M (little endian) // 4. testee sends M bytes representing a ConformanceResponse proto -#include <algorithm> #include <errno.h> -#include <fstream> #include <sys/types.h> #include <sys/wait.h> #include <unistd.h> + +#include <algorithm> +#include <fstream> #include <vector> #include <google/protobuf/stubs/stringprintf.h> - #include "conformance.pb.h" #include "conformance_test.h" using conformance::ConformanceResponse; -using google::protobuf::StringAppendF; using google::protobuf::ConformanceTestSuite; using std::string; using std::vector; #define STRINGIFY(x) #x #define TOSTRING(x) STRINGIFY(x) -#define CHECK_SYSCALL(call) \ +#define GOOGLE_CHECK_SYSCALL(call) \ if (call < 0) { \ perror(#call " " __FILE__ ":" TOSTRING(__LINE__)); \ exit(1); \ @@ -275,22 +274,22 @@ if (pid) { // Parent. - CHECK_SYSCALL(close(toproc_pipe_fd[0])); - CHECK_SYSCALL(close(fromproc_pipe_fd[1])); + GOOGLE_CHECK_SYSCALL(close(toproc_pipe_fd[0])); + GOOGLE_CHECK_SYSCALL(close(fromproc_pipe_fd[1])); write_fd_ = toproc_pipe_fd[1]; read_fd_ = fromproc_pipe_fd[0]; child_pid_ = pid; } else { // Child. - CHECK_SYSCALL(close(STDIN_FILENO)); - CHECK_SYSCALL(close(STDOUT_FILENO)); - CHECK_SYSCALL(dup2(toproc_pipe_fd[0], STDIN_FILENO)); - CHECK_SYSCALL(dup2(fromproc_pipe_fd[1], STDOUT_FILENO)); + GOOGLE_CHECK_SYSCALL(close(STDIN_FILENO)); + GOOGLE_CHECK_SYSCALL(close(STDOUT_FILENO)); + GOOGLE_CHECK_SYSCALL(dup2(toproc_pipe_fd[0], STDIN_FILENO)); + GOOGLE_CHECK_SYSCALL(dup2(fromproc_pipe_fd[1], STDOUT_FILENO)); - CHECK_SYSCALL(close(toproc_pipe_fd[0])); - CHECK_SYSCALL(close(fromproc_pipe_fd[1])); - CHECK_SYSCALL(close(toproc_pipe_fd[1])); - CHECK_SYSCALL(close(fromproc_pipe_fd[0])); + GOOGLE_CHECK_SYSCALL(close(toproc_pipe_fd[0])); + GOOGLE_CHECK_SYSCALL(close(fromproc_pipe_fd[1])); + GOOGLE_CHECK_SYSCALL(close(toproc_pipe_fd[1])); + GOOGLE_CHECK_SYSCALL(close(fromproc_pipe_fd[0])); std::unique_ptr<char[]> executable(new char[executable_.size() + 1]); memcpy(executable.get(), executable_.c_str(), executable_.size()); @@ -303,15 +302,14 @@ } argv.push_back(nullptr); // Never returns. - CHECK_SYSCALL(execv(executable.get(), const_cast<char **>(argv.data()))); + GOOGLE_CHECK_SYSCALL(execv(executable.get(), const_cast<char **>(argv.data()))); } } void ForkPipeRunner::CheckedWrite(int fd, const void *buf, size_t len) { if (write(fd, buf, len) != len) { GOOGLE_LOG(FATAL) << current_test_name_ - << ": error writing to test program: " - << strerror(errno); + << ": error writing to test program: " << strerror(errno); } } @@ -321,13 +319,11 @@ ssize_t bytes_read = read(fd, (char*)buf + ofs, len); if (bytes_read == 0) { - GOOGLE_LOG(ERROR) << current_test_name_ - << ": unexpected EOF from test program"; + GOOGLE_LOG(ERROR) << current_test_name_ << ": unexpected EOF from test program"; return false; } else if (bytes_read < 0) { GOOGLE_LOG(ERROR) << current_test_name_ - << ": error reading from test program: " - << strerror(errno); + << ": error reading from test program: " << strerror(errno); return false; } @@ -341,8 +337,7 @@ void ForkPipeRunner::CheckedRead(int fd, void *buf, size_t len) { if (!TryRead(fd, buf, len)) { GOOGLE_LOG(FATAL) << current_test_name_ - << ": error reading from test program: " - << strerror(errno); + << ": error reading from test program: " << strerror(errno); } }
diff --git a/conformance/failure_list_js.txt b/conformance/failure_list_js.txt index 4cb0a05..ef9131a 100644 --- a/conformance/failure_list_js.txt +++ b/conformance/failure_list_js.txt
@@ -1,3 +1,4 @@ + Recommended.Proto2.ProtobufInput.ValidDataRepeated.BOOL.PackedInput.DefaultOutput.ProtobufOutput Recommended.Proto2.ProtobufInput.ValidDataRepeated.BOOL.PackedInput.UnpackedOutput.ProtobufOutput Recommended.Proto2.ProtobufInput.ValidDataRepeated.BOOL.UnpackedInput.PackedOutput.ProtobufOutput
diff --git a/conformance/text_format_conformance_suite.cc b/conformance/text_format_conformance_suite.cc index 97b7b90..fc7b251 100644 --- a/conformance/text_format_conformance_suite.cc +++ b/conformance/text_format_conformance_suite.cc
@@ -30,20 +30,21 @@ #include "text_format_conformance_suite.h" -#include "conformance_test.h" - #include <google/protobuf/any.pb.h> +#include <google/protobuf/text_format.h> +#include "conformance_test.h" #include <google/protobuf/test_messages_proto2.pb.h> #include <google/protobuf/test_messages_proto3.pb.h> -#include <google/protobuf/text_format.h> + +namespace proto2_messages = protobuf_test_messages::proto2; using conformance::ConformanceRequest; using conformance::ConformanceResponse; using conformance::WireFormat; using google::protobuf::Message; using google::protobuf::TextFormat; -using protobuf_test_messages::proto2::TestAllTypesProto2; -using protobuf_test_messages::proto2::UnknownToTestAllTypes; +using proto2_messages::TestAllTypesProto2; +using proto2_messages::UnknownToTestAllTypes; using protobuf_test_messages::proto3::TestAllTypesProto3; using std::string; @@ -64,8 +65,8 @@ } if (!parser.ParseFromString(response.text_payload(), test_message)) { GOOGLE_LOG(ERROR) << "INTERNAL ERROR: internal text->protobuf transcode " - << "yielded unparseable proto. Text payload: " - << response.text_payload(); + << "yielded unparseable proto. Text payload: " + << response.text_payload(); return false; } @@ -83,11 +84,11 @@ switch (response.result_case()) { case ConformanceResponse::kProtobufPayload: { if (requested_output != conformance::PROTOBUF) { - ReportFailure( - test_name, level, request, response, - StrCat("Test was asked for ", WireFormatToString(requested_output), - " output but provided PROTOBUF instead.") - .c_str()); + ReportFailure(test_name, level, request, response, + StrCat("Test was asked for ", + WireFormatToString(requested_output), + " output but provided PROTOBUF instead.") + .c_str()); return false; } @@ -102,11 +103,11 @@ case ConformanceResponse::kTextPayload: { if (requested_output != conformance::TEXT_FORMAT) { - ReportFailure( - test_name, level, request, response, - StrCat("Test was asked for ", WireFormatToString(requested_output), - " output but provided TEXT_FORMAT instead.") - .c_str()); + ReportFailure(test_name, level, request, response, + StrCat("Test was asked for ", + WireFormatToString(requested_output), + " output but provided TEXT_FORMAT instead.") + .c_str()); return false; } @@ -122,7 +123,7 @@ default: GOOGLE_LOG(FATAL) << test_name - << ": unknown payload type: " << response.result_case(); + << ": unknown payload type: " << response.result_case(); } return true; @@ -139,8 +140,9 @@ conformance::TEXT_FORMAT_TEST, prototype, test_name, input); const ConformanceRequest& request = setting.GetRequest(); ConformanceResponse response; - string effective_test_name = StrCat(setting.ConformanceLevelToString(level), - ".Proto3.TextFormatInput.", test_name); + string effective_test_name = + StrCat(setting.ConformanceLevelToString(level), + ".Proto3.TextFormatInput.", test_name); RunTest(effective_test_name, request, &response); if (response.result_case() == ConformanceResponse::kParseError) {
diff --git a/csharp/src/Google.Protobuf.Conformance/Conformance.cs b/csharp/src/Google.Protobuf.Conformance/Conformance.cs index 65ba9b1..849dc55 100644 --- a/csharp/src/Google.Protobuf.Conformance/Conformance.cs +++ b/csharp/src/Google.Protobuf.Conformance/Conformance.cs
@@ -355,7 +355,7 @@ /// <summary> /// The full name for the test message to use; for the moment, either: /// protobuf_test_messages.proto3.TestAllTypesProto3 or - /// protobuf_test_messages.proto2.TestAllTypesProto2. + /// protobuf_test_messages.google.protobuf.TestAllTypesProto2. /// </summary> [global::System.Diagnostics.DebuggerNonUserCodeAttribute] public string MessageType {
diff --git a/csharp/src/Google.Protobuf.Test/testprotos.pb b/csharp/src/Google.Protobuf.Test/testprotos.pb index 4404d16..818b227 100644 --- a/csharp/src/Google.Protobuf.Test/testprotos.pb +++ b/csharp/src/Google.Protobuf.Test/testprotos.pb Binary files differ
diff --git a/csharp/src/Google.Protobuf/WellKnownTypes/FieldMask.cs b/csharp/src/Google.Protobuf/WellKnownTypes/FieldMask.cs index 0bbf313..00e1e9f 100644 --- a/csharp/src/Google.Protobuf/WellKnownTypes/FieldMask.cs +++ b/csharp/src/Google.Protobuf/WellKnownTypes/FieldMask.cs
@@ -238,7 +238,7 @@ /// /// The implementation of any API method which has a FieldMask type field in the /// request should verify the included field paths, and return an - /// `INVALID_ARGUMENT` error if any path is duplicated or unmappable. + /// `INVALID_ARGUMENT` error if any path is unmappable. /// </summary> public sealed partial class FieldMask : pb::IMessage<FieldMask> { private static readonly pb::MessageParser<FieldMask> _parser = new pb::MessageParser<FieldMask>(() => new FieldMask());
diff --git a/java/core/src/main/java/com/google/protobuf/ByteString.java b/java/core/src/main/java/com/google/protobuf/ByteString.java index a13f1da..17b7c98 100644 --- a/java/core/src/main/java/com/google/protobuf/ByteString.java +++ b/java/core/src/main/java/com/google/protobuf/ByteString.java
@@ -57,13 +57,17 @@ import java.util.NoSuchElementException; /** - * Immutable sequence of bytes. Substring is supported by sharing the reference to the immutable - * underlying bytes. Concatenation is likewise supported without copying (long strings) by building - * a tree of pieces in {@link RopeByteString}. + * Immutable sequence of bytes. Provides conversions to and from {@code byte[]}, {@link + * java.lang.String}, {@link ByteBuffer}, {@link InputStream}, {@link OutputStream}. Also provides a + * conversion to {@link CodedInputStream}. * * <p>Like {@link String}, the contents of a {@link ByteString} can never be observed to change, not * even in the presence of a data race or incorrect API usage in the client code. * + * <p>Substring is supported by sharing the reference to the immutable underlying bytes. + * Concatenation is likewise supported without copying (long strings) by building a tree of pieces + * in {@link RopeByteString}. + * * @author crazybob@google.com Bob Lee * @author kenton@google.com Kenton Varda * @author carlanton@google.com Carl Haverl
diff --git a/java/core/src/main/java/com/google/protobuf/GeneratedMessageLite.java b/java/core/src/main/java/com/google/protobuf/GeneratedMessageLite.java index d46b1ba..1ee785d 100644 --- a/java/core/src/main/java/com/google/protobuf/GeneratedMessageLite.java +++ b/java/core/src/main/java/com/google/protobuf/GeneratedMessageLite.java
@@ -1023,7 +1023,7 @@ } /** Clear an extension. */ - public final <Type> BuilderType clearExtension(final ExtensionLite<MessageType, ?> extension) { + public final BuilderType clearExtension(final ExtensionLite<MessageType, ?> extension) { GeneratedExtension<MessageType, ?> extensionLite = checkIsLite(extension); verifyExtensionContainingType(extensionLite);
diff --git a/java/core/src/main/java/com/google/protobuf/GeneratedMessageV3.java b/java/core/src/main/java/com/google/protobuf/GeneratedMessageV3.java index 4e00bb4..5f7b387 100644 --- a/java/core/src/main/java/com/google/protobuf/GeneratedMessageV3.java +++ b/java/core/src/main/java/com/google/protobuf/GeneratedMessageV3.java
@@ -1498,8 +1498,7 @@ } /** Clear an extension. */ - public final <Type> BuilderType clearExtension( - final ExtensionLite<MessageType, ?> extensionLite) { + public final BuilderType clearExtension(final ExtensionLite<MessageType, ?> extensionLite) { Extension<MessageType, ?> extension = checkNotLite(extensionLite); verifyExtensionContainingType(extension);
diff --git a/java/core/src/main/java/com/google/protobuf/MessageLiteToString.java b/java/core/src/main/java/com/google/protobuf/MessageLiteToString.java index 8e26593..4aea952 100644 --- a/java/core/src/main/java/com/google/protobuf/MessageLiteToString.java +++ b/java/core/src/main/java/com/google/protobuf/MessageLiteToString.java
@@ -88,7 +88,7 @@ } for (String getter : getters) { - String suffix = getter.replaceFirst("get", ""); + String suffix = getter.startsWith("get") ? getter.substring(3) : getter; if (suffix.endsWith(LIST_SUFFIX) && !suffix.endsWith(BUILDER_LIST_SUFFIX) // Sometimes people have fields named 'list' that aren't repeated.
diff --git a/java/core/src/main/java/com/google/protobuf/MessageSchema.java b/java/core/src/main/java/com/google/protobuf/MessageSchema.java index 0c6cf99..8f9ce73 100755 --- a/java/core/src/main/java/com/google/protobuf/MessageSchema.java +++ b/java/core/src/main/java/com/google/protobuf/MessageSchema.java
@@ -1173,12 +1173,10 @@ mergeSingleField(message, other, i); } - if (!proto3) { - SchemaUtil.mergeUnknownFields(unknownFieldSchema, message, other); + SchemaUtil.mergeUnknownFields(unknownFieldSchema, message, other); - if (hasExtensions) { - SchemaUtil.mergeExtensions(extensionSchema, message, other); - } + if (hasExtensions) { + SchemaUtil.mergeExtensions(extensionSchema, message, other); } }
diff --git a/java/core/src/main/java/com/google/protobuf/RopeByteString.java b/java/core/src/main/java/com/google/protobuf/RopeByteString.java index c2557ab..54d4180 100644 --- a/java/core/src/main/java/com/google/protobuf/RopeByteString.java +++ b/java/core/src/main/java/com/google/protobuf/RopeByteString.java
@@ -211,7 +211,7 @@ // Fine, we'll add a node and increase the tree depth--unless we rebalance ;^) int newDepth = Math.max(left.getTreeDepth(), right.getTreeDepth()) + 1; - if (newLength >= minLengthByDepth[newDepth]) { + if (newLength >= minLength(newDepth)) { // The tree is shallow enough, so don't rebalance return new RopeByteString(left, right); } @@ -251,6 +251,22 @@ } /** + * Returns the minimum length for which a tree of the given depth is considered balanced according + * to BAP95, which means the tree is flat-enough with respect to the bounds. Defaults to {@code + * Integer.MAX_VALUE} if {@code depth >= minLengthByDepth.length} in order to avoid an {@code + * ArrayIndexOutOfBoundsException}. + * + * @param depth tree depth + * @return minimum balanced length + */ + static int minLength(int depth) { + if (depth >= minLengthByDepth.length) { + return Integer.MAX_VALUE; + } + return minLengthByDepth[depth]; + } + + /** * Gets the byte at the given index. Throws {@link ArrayIndexOutOfBoundsException} for * backwards-compatibility reasons although it would more properly be {@link * IndexOutOfBoundsException}. @@ -328,7 +344,7 @@ */ @Override protected boolean isBalanced() { - return totalLength >= minLengthByDepth[treeDepth]; + return totalLength >= minLength(treeDepth); } /** @@ -656,7 +672,7 @@ */ private void insert(ByteString byteString) { int depthBin = getDepthBinForLength(byteString.size()); - int binEnd = minLengthByDepth[depthBin + 1]; + int binEnd = minLength(depthBin + 1); // BAP95: Concatenate all trees occupying bins representing the length of // our new piece or of shorter pieces, to the extent that is possible. @@ -665,7 +681,7 @@ if (prefixesStack.isEmpty() || prefixesStack.peek().size() >= binEnd) { prefixesStack.push(byteString); } else { - int binStart = minLengthByDepth[depthBin]; + int binStart = minLength(depthBin); // Concatenate the subtrees of shorter length ByteString newTree = prefixesStack.pop(); @@ -680,7 +696,7 @@ // Continue concatenating until we land in an empty bin while (!prefixesStack.isEmpty()) { depthBin = getDepthBinForLength(newTree.size()); - binEnd = minLengthByDepth[depthBin + 1]; + binEnd = minLength(depthBin + 1); if (prefixesStack.peek().size() < binEnd) { ByteString left = prefixesStack.pop(); newTree = new RopeByteString(left, newTree); @@ -816,7 +832,7 @@ * * <p>Note that {@link InputStream#read(byte[], int, int)} and {@link * ByteArrayInputStream#read(byte[], int, int)} behave inconsistently when reading 0 bytes at - * EOF; the interface defines the return value to be 0 and the latter returns -1. We use the + * EOF; the interface defines the return value to be 0 and the latter returns -1. We use the * latter behavior so that all ByteString streams are consistent. * * @return -1 if at EOF, otherwise the actual number of bytes read.
diff --git a/java/core/src/test/java/com/google/protobuf/RopeByteStringTest.java b/java/core/src/test/java/com/google/protobuf/RopeByteStringTest.java index 9299267..46c2d86 100644 --- a/java/core/src/test/java/com/google/protobuf/RopeByteStringTest.java +++ b/java/core/src/test/java/com/google/protobuf/RopeByteStringTest.java
@@ -62,18 +62,19 @@ expectedHashCode = -1214197238; } - public void testMinLengthByDepth() { - // minLengthByDepth should match the Fibonacci sequence + public void testMinLength() { + // minLength should match the Fibonacci sequence int a = 1; int b = 1; int i; for (i = 0; a > 0; i++) { - assertEquals(a, RopeByteString.minLengthByDepth[i]); + assertEquals(a, RopeByteString.minLength(i)); int c = a + b; a = b; b = c; } - assertEquals(Integer.MAX_VALUE, RopeByteString.minLengthByDepth[i]); + assertEquals(Integer.MAX_VALUE, RopeByteString.minLength(i)); + assertEquals(Integer.MAX_VALUE, RopeByteString.minLength(i + 1)); assertEquals(i + 1, RopeByteString.minLengthByDepth.length); }
diff --git a/java/core/src/test/java/com/google/protobuf/UnknownFieldSetTest.java b/java/core/src/test/java/com/google/protobuf/UnknownFieldSetTest.java index 6316bd8..c7eb57c 100644 --- a/java/core/src/test/java/com/google/protobuf/UnknownFieldSetTest.java +++ b/java/core/src/test/java/com/google/protobuf/UnknownFieldSetTest.java
@@ -38,6 +38,7 @@ import protobuf_unittest.UnittestProto.TestEmptyMessageWithExtensions; import protobuf_unittest.UnittestProto.TestPackedExtensions; import protobuf_unittest.UnittestProto.TestPackedTypes; +import proto3_unittest.UnittestProto3; import java.util.Arrays; import java.util.Map; import junit.framework.TestCase; @@ -379,4 +380,28 @@ } // ================================================================= + + public void testProto3RoundTrip() throws Exception { + ByteString data = getBizarroData(); + + UnittestProto3.TestEmptyMessage message = + UnittestProto3.TestEmptyMessage.parseFrom(data, ExtensionRegistryLite.getEmptyRegistry()); + assertEquals(data, message.toByteString()); + + message = UnittestProto3.TestEmptyMessage.newBuilder().mergeFrom(message).build(); + assertEquals(data, message.toByteString()); + + assertEquals( + data, + UnittestProto3.TestMessageWithDummy.parseFrom( + data, ExtensionRegistryLite.getEmptyRegistry()) + .toBuilder() + // force copy-on-write + .setDummy(true) + .build() + .toBuilder() + .clearDummy() + .build() + .toByteString()); + } }
diff --git a/java/lite/proguard.pgcfg b/java/lite/proguard.pgcfg new file mode 100755 index 0000000..4bb31e5 --- /dev/null +++ b/java/lite/proguard.pgcfg
@@ -0,0 +1,3 @@ +-keepclassmembers class * extends com.google.protobuf.GeneratedMessageLite { + <fields>; +}
diff --git a/js/binary/decoder.js b/js/binary/decoder.js index e0cd12e..75d4ff7 100644 --- a/js/binary/decoder.js +++ b/js/binary/decoder.js
@@ -180,9 +180,9 @@ jspb.BinaryDecoder.prototype.setBlock = function(data, opt_start, opt_length) { this.bytes_ = jspb.utils.byteSourceToUint8Array(data); - this.start_ = goog.isDef(opt_start) ? opt_start : 0; - this.end_ = - goog.isDef(opt_length) ? this.start_ + opt_length : this.bytes_.length; + this.start_ = (opt_start !== undefined) ? opt_start : 0; + this.end_ = (opt_length !== undefined) ? this.start_ + opt_length : + this.bytes_.length; this.cursor_ = this.start_; };
diff --git a/js/binary/encoder.js b/js/binary/encoder.js index 0387f04..726481b 100644 --- a/js/binary/encoder.js +++ b/js/binary/encoder.js
@@ -414,7 +414,7 @@ * @param {boolean|number} value The value to write. */ jspb.BinaryEncoder.prototype.writeBool = function(value) { - goog.asserts.assert(goog.isBoolean(value) || goog.isNumber(value)); + goog.asserts.assert(typeof value === 'boolean' || typeof value === 'number'); this.buffer_.push(value ? 1 : 0); };
diff --git a/js/binary/proto_test.js b/js/binary/proto_test.js index ae31c8d..aee327a 100644 --- a/js/binary/proto_test.js +++ b/js/binary/proto_test.js
@@ -176,7 +176,7 @@ * @return {boolean} */ function bytesCompare(arr, expected) { - if (goog.isString(arr)) { + if (typeof arr === 'string') { arr = goog.crypt.base64.decodeStringToUint8Array(arr); } if (arr.length != expected.length) { @@ -481,8 +481,8 @@ var msg = new proto.jspb.test.TestAllTypes(); function assertGetters() { - assertTrue(goog.isString(msg.getRepeatedBytesList_asB64()[0])); - assertTrue(goog.isString(msg.getRepeatedBytesList_asB64()[1])); + assertTrue(typeof msg.getRepeatedBytesList_asB64()[0] === 'string'); + assertTrue(typeof msg.getRepeatedBytesList_asB64()[1] === 'string'); assertTrue(msg.getRepeatedBytesList_asU8()[0] instanceof Uint8Array); assertTrue(msg.getRepeatedBytesList_asU8()[1] instanceof Uint8Array);
diff --git a/js/binary/reader.js b/js/binary/reader.js index 9e193ac..2af1a4a 100644 --- a/js/binary/reader.js +++ b/js/binary/reader.js
@@ -445,9 +445,9 @@ * @param {string} callbackName * @param {function(!jspb.BinaryReader):*} callback */ -jspb.BinaryReader.prototype.registerReadCallback = - function(callbackName, callback) { - if (goog.isNull(this.readCallbacks_)) { +jspb.BinaryReader.prototype.registerReadCallback = function( + callbackName, callback) { + if (this.readCallbacks_ === null) { this.readCallbacks_ = {}; } goog.asserts.assert(!this.readCallbacks_[callbackName]); @@ -461,7 +461,7 @@ * @return {*} The value returned by the callback. */ jspb.BinaryReader.prototype.runReadCallback = function(callbackName) { - goog.asserts.assert(!goog.isNull(this.readCallbacks_)); + goog.asserts.assert(this.readCallbacks_ !== null); var callback = this.readCallbacks_[callbackName]; goog.asserts.assert(callback); return callback(this);
diff --git a/js/binary/utils.js b/js/binary/utils.js index c2965c4..195247e 100644 --- a/js/binary/utils.js +++ b/js/binary/utils.js
@@ -1001,7 +1001,7 @@ * @return {string} Stringified scalar for text format. */ jspb.utils.debugScalarToTextFormat = function(scalar) { - if (goog.isString(scalar)) { + if (typeof scalar === 'string') { return goog.string.quote(scalar); } else { return scalar.toString();
diff --git a/js/binary/utils_test.js b/js/binary/utils_test.js index 51a9dee..e953ace 100644 --- a/js/binary/utils_test.js +++ b/js/binary/utils_test.js
@@ -356,7 +356,7 @@ */ function test(x, opt_bits) { jspb.utils.splitFloat32(x); - if (goog.isDef(opt_bits)) { + if (opt_bits !== undefined) { if (opt_bits != jspb.utils.split64Low) throw 'fail!'; } expect(truncate(x)) @@ -428,11 +428,11 @@ */ function test(x, opt_highBits, opt_lowBits) { jspb.utils.splitFloat64(x); - if (goog.isDef(opt_highBits)) { + if (opt_highBits !== undefined) { var split64High = jspb.utils.split64High; expect(opt_highBits.toString(16)).toEqual(split64High.toString(16)); } - if (goog.isDef(opt_lowBits)) { + if (opt_lowBits !== undefined) { var split64Low = jspb.utils.split64Low; expect(opt_lowBits.toString(16)).toEqual(split64Low.toString(16)); }
diff --git a/js/binary/writer.js b/js/binary/writer.js index 8c5bff8..ab9a815 100644 --- a/js/binary/writer.js +++ b/js/binary/writer.js
@@ -748,7 +748,7 @@ */ jspb.BinaryWriter.prototype.writeBool = function(field, value) { if (value == null) return; - goog.asserts.assert(goog.isBoolean(value) || goog.isNumber(value)); + goog.asserts.assert(typeof value === 'boolean' || typeof value === 'number'); this.writeFieldHeader_(field, jspb.BinaryConstants.WireType.VARINT); this.encoder_.writeBool(value); };
diff --git a/js/map.js b/js/map.js index 589a293..ab852e4 100644 --- a/js/map.js +++ b/js/map.js
@@ -208,13 +208,13 @@ } }; -if (typeof(Symbol) != 'undefined') { - /** @override */ - jspb.Map.ArrayIteratorIterable_.prototype[Symbol.iterator] = function() { - return this; - }; -} +if (typeof(Symbol) != 'undefined') { +/** @override */ +jspb.Map.ArrayIteratorIterable_.prototype[Symbol.iterator] = function() { + return this; +}; +} /** * Returns the map's length (number of key/value pairs).
diff --git a/js/message.js b/js/message.js index 52c541e..4bf0378 100644 --- a/js/message.js +++ b/js/message.js
@@ -778,7 +778,7 @@ * @return {?string} The field's coerced value. */ jspb.Message.bytesAsB64 = function(value) { - if (value == null || goog.isString(value)) { + if (value == null || typeof value === 'string') { return value; } if (jspb.Message.SUPPORTS_UINT8ARRAY_ && value instanceof Uint8Array) { @@ -800,7 +800,7 @@ if (value == null || value instanceof Uint8Array) { return value; } - if (goog.isString(value)) { + if (typeof value === 'string') { return goog.crypt.base64.decodeStringToUint8Array(value); } goog.asserts.fail('Cannot coerce to Uint8Array: ' + goog.typeOf(value)); @@ -816,7 +816,7 @@ */ jspb.Message.bytesListAsB64 = function(value) { jspb.Message.assertConsistentTypes_(value); - if (!value.length || goog.isString(value[0])) { + if (!value.length || typeof value[0] === 'string') { return /** @type {!Array<string>} */ (value); } return goog.array.map(value, jspb.Message.bytesAsB64); @@ -1654,8 +1654,8 @@ if (!goog.isObject(field1) || !goog.isObject(field2)) { // NaN != NaN so we cover this case. - if ((goog.isNumber(field1) && isNaN(field1)) || - (goog.isNumber(field2) && isNaN(field2))) { + if ((typeof field1 === 'number' && isNaN(field1)) || + (typeof field2 === 'number' && isNaN(field2))) { // One of the fields might be a string 'NaN'. return String(field1) == String(field2); }
diff --git a/js/message_test.js b/js/message_test.js index b2d0da1..e038f65 100644 --- a/js/message_test.js +++ b/js/message_test.js
@@ -855,7 +855,7 @@ var assertNan = function(x) { assertTrue( 'Expected ' + x + ' (' + goog.typeOf(x) + ') to be NaN.', - goog.isNumber(x) && isNaN(x)); + typeof x === 'number' && isNaN(x)); }; var message = new proto.jspb.test.FloatingPointFields([
diff --git a/js/proto3_test.js b/js/proto3_test.js index 7f9d71d..79acc3c 100644 --- a/js/proto3_test.js +++ b/js/proto3_test.js
@@ -54,7 +54,7 @@ * @return {boolean} */ function bytesCompare(arr, expected) { - if (goog.isString(arr)) { + if (typeof arr === 'string') { arr = goog.crypt.base64.decodeStringToUint8Array(arr); } if (arr.length != expected.length) {
diff --git a/objectivec/google/protobuf/FieldMask.pbobjc.h b/objectivec/google/protobuf/FieldMask.pbobjc.h index 61fdd25..92d5042 100644 --- a/objectivec/google/protobuf/FieldMask.pbobjc.h +++ b/objectivec/google/protobuf/FieldMask.pbobjc.h
@@ -253,7 +253,7 @@ * * The implementation of any API method which has a FieldMask type field in the * request should verify the included field paths, and return an - * `INVALID_ARGUMENT` error if any path is duplicated or unmappable. + * `INVALID_ARGUMENT` error if any path is unmappable. **/ @interface GPBFieldMask : GPBMessage
diff --git a/python/google/protobuf/descriptor.py b/python/google/protobuf/descriptor.py index 2c2a079..383cb66 100755 --- a/python/google/protobuf/descriptor.py +++ b/python/google/protobuf/descriptor.py
@@ -45,7 +45,7 @@ import binascii import os from google.protobuf.pyext import _message - _USE_C_DESCRIPTORS = getattr(_message, '_USE_C_DESCRIPTORS', False) + _USE_C_DESCRIPTORS = True class Error(Exception): @@ -904,10 +904,6 @@ self.dependencies = (dependencies or []) self.public_dependencies = (public_dependencies or []) - if (api_implementation.Type() == 'cpp' and - self.serialized_pb is not None): - _message.default_pool.AddSerializedFile(self.serialized_pb) - def CopyToProto(self, proto): """Copies this to a descriptor_pb2.FileDescriptorProto.
diff --git a/python/google/protobuf/internal/enum_type_wrapper.py b/python/google/protobuf/internal/enum_type_wrapper.py index b4d30e2..eeb2dae 100644 --- a/python/google/protobuf/internal/enum_type_wrapper.py +++ b/python/google/protobuf/internal/enum_type_wrapper.py
@@ -37,6 +37,8 @@ __author__ = 'rabsatt@google.com (Kevin Rabsatt)' +import six + class EnumTypeWrapper(object): """A utility for finding the names of enum values.""" @@ -52,8 +54,14 @@ """Returns a string containing the name of an enum value.""" if number in self._enum_type.values_by_number: return self._enum_type.values_by_number[number].name - raise ValueError('Enum %s has no name defined for value %d' % ( - self._enum_type.name, number)) + + if not isinstance(number, six.integer_types): + raise TypeError('Enum value for %s must be an int, but got %r.' % ( + self._enum_type.name, number)) + else: + # %r here to handle the odd case when you pass in a boolean. + raise ValueError('Enum %s has no name defined for value %r' % ( + self._enum_type.name, number)) def Value(self, name): """Returns the value corresponding to the given enum name."""
diff --git a/python/google/protobuf/internal/json_format_test.py b/python/google/protobuf/internal/json_format_test.py index 939d496..e3992f9 100644 --- a/python/google/protobuf/internal/json_format_test.py +++ b/python/google/protobuf/internal/json_format_test.py
@@ -818,6 +818,14 @@ self.assertEqual(message.repeated_float_value[0], float('inf')) self.assertAlmostEqual(message.repeated_float_value[1], 1.4028235e-39) + def testFloatPrecision(self): + message = json_format_proto3_pb2.TestMessage() + message.float_value = 1.123456789 + # Set to 7 valid digits. + text = '{\n "floatValue": 1.123457\n}' + self.assertEqual( + json_format.MessageToJson(message, float_precision=7), text) + def testParseEmptyText(self): self.CheckError('', r'Failed to load JSON: (Expecting value)|(No JSON).')
diff --git a/python/google/protobuf/internal/reflection_test.py b/python/google/protobuf/internal/reflection_test.py index 786a7ca..dace154 100755 --- a/python/google/protobuf/internal/reflection_test.py +++ b/python/google/protobuf/internal/reflection_test.py
@@ -49,6 +49,7 @@ from google.protobuf import unittest_import_pb2 from google.protobuf import unittest_mset_pb2 from google.protobuf import unittest_pb2 +from google.protobuf import unittest_proto3_arena_pb2 from google.protobuf import descriptor_pb2 from google.protobuf import descriptor from google.protobuf import message @@ -62,6 +63,7 @@ from google.protobuf.internal import test_util from google.protobuf.internal import testing_refleaks from google.protobuf.internal import decoder +from google.protobuf.internal import _parameterized if six.PY3: @@ -113,6 +115,9 @@ return self._pos == len(self._bytes) +@_parameterized.named_parameters( + ('_proto2', unittest_pb2), + ('_proto3', unittest_proto3_arena_pb2)) @testing_refleaks.TestCase class ReflectionTest(unittest.TestCase): @@ -121,9 +126,9 @@ for i in range(len(values)): self.assertEqual(values[i], others[i]) - def testScalarConstructor(self): + def testScalarConstructor(self, message_module): # Constructor with only scalar types should succeed. - proto = unittest_pb2.TestAllTypes( + proto = message_module.TestAllTypes( optional_int32=24, optional_double=54.321, optional_string='optional_string', @@ -132,11 +137,12 @@ self.assertEqual(24, proto.optional_int32) self.assertEqual(54.321, proto.optional_double) self.assertEqual('optional_string', proto.optional_string) - self.assertFalse(proto.HasField("optional_float")) + if message_module is unittest_pb2: + self.assertFalse(proto.HasField("optional_float")) - def testRepeatedScalarConstructor(self): + def testRepeatedScalarConstructor(self, message_module): # Constructor with only repeated scalar types should succeed. - proto = unittest_pb2.TestAllTypes( + proto = message_module.TestAllTypes( repeated_int32=[1, 2, 3, 4], repeated_double=[1.23, 54.321], repeated_bool=[True, False, False], @@ -149,6 +155,756 @@ self.assertEqual(["optional_string"], list(proto.repeated_string)) self.assertEqual([], list(proto.repeated_float)) + def testMixedConstructor(self, message_module): + # Constructor with only mixed types should succeed. + proto = message_module.TestAllTypes( + optional_int32=24, + optional_string='optional_string', + repeated_double=[1.23, 54.321], + repeated_bool=[True, False, False], + repeated_nested_message=[ + message_module.TestAllTypes.NestedMessage( + bb=message_module.TestAllTypes.FOO), + message_module.TestAllTypes.NestedMessage( + bb=message_module.TestAllTypes.BAR)], + repeated_foreign_message=[ + message_module.ForeignMessage(c=-43), + message_module.ForeignMessage(c=45324), + message_module.ForeignMessage(c=12)], + optional_nested_message=None) + + self.assertEqual(24, proto.optional_int32) + self.assertEqual('optional_string', proto.optional_string) + self.assertEqual([1.23, 54.321], list(proto.repeated_double)) + self.assertEqual([True, False, False], list(proto.repeated_bool)) + self.assertEqual( + [message_module.TestAllTypes.NestedMessage( + bb=message_module.TestAllTypes.FOO), + message_module.TestAllTypes.NestedMessage( + bb=message_module.TestAllTypes.BAR)], + list(proto.repeated_nested_message)) + self.assertEqual( + [message_module.ForeignMessage(c=-43), + message_module.ForeignMessage(c=45324), + message_module.ForeignMessage(c=12)], + list(proto.repeated_foreign_message)) + self.assertFalse(proto.HasField("optional_nested_message")) + + def testConstructorTypeError(self, message_module): + self.assertRaises( + TypeError, message_module.TestAllTypes, optional_int32='foo') + self.assertRaises( + TypeError, message_module.TestAllTypes, optional_string=1234) + self.assertRaises( + TypeError, message_module.TestAllTypes, optional_nested_message=1234) + self.assertRaises( + TypeError, message_module.TestAllTypes, repeated_int32=1234) + self.assertRaises( + TypeError, message_module.TestAllTypes, repeated_int32=['foo']) + self.assertRaises( + TypeError, message_module.TestAllTypes, repeated_string=1234) + self.assertRaises( + TypeError, message_module.TestAllTypes, repeated_string=[1234]) + self.assertRaises( + TypeError, message_module.TestAllTypes, repeated_nested_message=1234) + self.assertRaises( + TypeError, message_module.TestAllTypes, repeated_nested_message=[1234]) + + def testConstructorInvalidatesCachedByteSize(self, message_module): + message = message_module.TestAllTypes(optional_int32=12) + self.assertEqual(2, message.ByteSize()) + + message = message_module.TestAllTypes( + optional_nested_message=message_module.TestAllTypes.NestedMessage()) + self.assertEqual(3, message.ByteSize()) + + message = message_module.TestAllTypes(repeated_int32=[12]) + # TODO(jieluo): Add this test back for proto3 + if message_module is unittest_pb2: + self.assertEqual(3, message.ByteSize()) + + message = message_module.TestAllTypes( + repeated_nested_message=[message_module.TestAllTypes.NestedMessage()]) + self.assertEqual(3, message.ByteSize()) + + def testReferencesToNestedMessage(self, message_module): + proto = message_module.TestAllTypes() + nested = proto.optional_nested_message + del proto + # A previous version had a bug where this would raise an exception when + # hitting a now-dead weak reference. + nested.bb = 23 + + def testOneOf(self, message_module): + proto = message_module.TestAllTypes() + proto.oneof_uint32 = 10 + proto.oneof_nested_message.bb = 11 + self.assertEqual(11, proto.oneof_nested_message.bb) + self.assertFalse(proto.HasField('oneof_uint32')) + nested = proto.oneof_nested_message + proto.oneof_string = 'abc' + self.assertEqual('abc', proto.oneof_string) + self.assertEqual(11, nested.bb) + self.assertFalse(proto.HasField('oneof_nested_message')) + + def testGetDefaultMessageAfterDisconnectingDefaultMessage( + self, message_module): + proto = message_module.TestAllTypes() + nested = proto.optional_nested_message + proto.ClearField('optional_nested_message') + del proto + del nested + # Force a garbage collect so that the underlying CMessages are freed along + # with the Messages they point to. This is to make sure we're not deleting + # default message instances. + gc.collect() + proto = message_module.TestAllTypes() + nested = proto.optional_nested_message + + def testDisconnectingNestedMessageAfterSettingField(self, message_module): + proto = message_module.TestAllTypes() + nested = proto.optional_nested_message + nested.bb = 5 + self.assertTrue(proto.HasField('optional_nested_message')) + proto.ClearField('optional_nested_message') # Should disconnect from parent + self.assertEqual(5, nested.bb) + self.assertEqual(0, proto.optional_nested_message.bb) + self.assertIsNot(nested, proto.optional_nested_message) + nested.bb = 23 + self.assertFalse(proto.HasField('optional_nested_message')) + self.assertEqual(0, proto.optional_nested_message.bb) + + def testDisconnectingNestedMessageBeforeGettingField(self, message_module): + proto = message_module.TestAllTypes() + self.assertFalse(proto.HasField('optional_nested_message')) + proto.ClearField('optional_nested_message') + self.assertFalse(proto.HasField('optional_nested_message')) + + def testDisconnectingNestedMessageAfterMerge(self, message_module): + # This test exercises the code path that does not use ReleaseMessage(). + # The underlying fear is that if we use ReleaseMessage() incorrectly, + # we will have memory leaks. It's hard to check that that doesn't happen, + # but at least we can exercise that code path to make sure it works. + proto1 = message_module.TestAllTypes() + proto2 = message_module.TestAllTypes() + proto2.optional_nested_message.bb = 5 + proto1.MergeFrom(proto2) + self.assertTrue(proto1.HasField('optional_nested_message')) + proto1.ClearField('optional_nested_message') + self.assertFalse(proto1.HasField('optional_nested_message')) + + def testDisconnectingLazyNestedMessage(self, message_module): + # This test exercises releasing a nested message that is lazy. This test + # only exercises real code in the C++ implementation as Python does not + # support lazy parsing, but the current C++ implementation results in + # memory corruption and a crash. + if api_implementation.Type() != 'python': + return + proto = message_module.TestAllTypes() + proto.optional_lazy_message.bb = 5 + proto.ClearField('optional_lazy_message') + del proto + gc.collect() + + def testSingularListFields(self, message_module): + proto = message_module.TestAllTypes() + proto.optional_fixed32 = 1 + proto.optional_int32 = 5 + proto.optional_string = 'foo' + # Access sub-message but don't set it yet. + nested_message = proto.optional_nested_message + self.assertEqual( + [ (proto.DESCRIPTOR.fields_by_name['optional_int32' ], 5), + (proto.DESCRIPTOR.fields_by_name['optional_fixed32'], 1), + (proto.DESCRIPTOR.fields_by_name['optional_string' ], 'foo') ], + proto.ListFields()) + + proto.optional_nested_message.bb = 123 + self.assertEqual( + [ (proto.DESCRIPTOR.fields_by_name['optional_int32' ], 5), + (proto.DESCRIPTOR.fields_by_name['optional_fixed32'], 1), + (proto.DESCRIPTOR.fields_by_name['optional_string' ], 'foo'), + (proto.DESCRIPTOR.fields_by_name['optional_nested_message' ], + nested_message) ], + proto.ListFields()) + + def testRepeatedListFields(self, message_module): + proto = message_module.TestAllTypes() + proto.repeated_fixed32.append(1) + proto.repeated_int32.append(5) + proto.repeated_int32.append(11) + proto.repeated_string.extend(['foo', 'bar']) + proto.repeated_string.extend([]) + proto.repeated_string.append('baz') + proto.repeated_string.extend(str(x) for x in range(2)) + proto.optional_int32 = 21 + proto.repeated_bool # Access but don't set anything; should not be listed. + self.assertEqual( + [ (proto.DESCRIPTOR.fields_by_name['optional_int32' ], 21), + (proto.DESCRIPTOR.fields_by_name['repeated_int32' ], [5, 11]), + (proto.DESCRIPTOR.fields_by_name['repeated_fixed32'], [1]), + (proto.DESCRIPTOR.fields_by_name['repeated_string' ], + ['foo', 'bar', 'baz', '0', '1']) ], + proto.ListFields()) + + def testClearFieldWithUnknownFieldName(self, message_module): + proto = message_module.TestAllTypes() + self.assertRaises(ValueError, proto.ClearField, 'nonexistent_field') + self.assertRaises(ValueError, proto.ClearField, b'nonexistent_field') + + def testDisallowedAssignments(self, message_module): + # It's illegal to assign values directly to repeated fields + # or to nonrepeated composite fields. Ensure that this fails. + proto = message_module.TestAllTypes() + # Repeated fields. + self.assertRaises(AttributeError, setattr, proto, 'repeated_int32', 10) + # Lists shouldn't work, either. + self.assertRaises(AttributeError, setattr, proto, 'repeated_int32', [10]) + # Composite fields. + self.assertRaises(AttributeError, setattr, proto, + 'optional_nested_message', 23) + # Assignment to a repeated nested message field without specifying + # the index in the array of nested messages. + self.assertRaises(AttributeError, setattr, proto.repeated_nested_message, + 'bb', 34) + # Assignment to an attribute of a repeated field. + self.assertRaises(AttributeError, setattr, proto.repeated_float, + 'some_attribute', 34) + # proto.nonexistent_field = 23 should fail as well. + self.assertRaises(AttributeError, setattr, proto, 'nonexistent_field', 23) + + def testSingleScalarTypeSafety(self, message_module): + proto = message_module.TestAllTypes() + self.assertRaises(TypeError, setattr, proto, 'optional_int32', 1.1) + self.assertRaises(TypeError, setattr, proto, 'optional_int32', 'foo') + self.assertRaises(TypeError, setattr, proto, 'optional_string', 10) + self.assertRaises(TypeError, setattr, proto, 'optional_bytes', 10) + self.assertRaises(TypeError, setattr, proto, 'optional_bool', 'foo') + self.assertRaises(TypeError, setattr, proto, 'optional_float', 'foo') + self.assertRaises(TypeError, setattr, proto, 'optional_double', 'foo') + # TODO(jieluo): Fix type checking difference for python and c extension + if api_implementation.Type() == 'python': + self.assertRaises(TypeError, setattr, proto, 'optional_bool', 1.1) + else: + proto.optional_bool = 1.1 + + def assertIntegerTypes(self, integer_fn, message_module): + """Verifies setting of scalar integers. + + Args: + integer_fn: A function to wrap the integers that will be assigned. + message_module: unittest_pb2 or unittest_proto3_arena_pb2 + """ + def TestGetAndDeserialize(field_name, value, expected_type): + proto = message_module.TestAllTypes() + value = integer_fn(value) + setattr(proto, field_name, value) + self.assertIsInstance(getattr(proto, field_name), expected_type) + proto2 = message_module.TestAllTypes() + proto2.ParseFromString(proto.SerializeToString()) + self.assertIsInstance(getattr(proto2, field_name), expected_type) + + TestGetAndDeserialize('optional_int32', 1, int) + TestGetAndDeserialize('optional_int32', 1 << 30, int) + TestGetAndDeserialize('optional_uint32', 1 << 30, int) + integer_64 = long + if struct.calcsize('L') == 4: + # Python only has signed ints, so 32-bit python can't fit an uint32 + # in an int. + TestGetAndDeserialize('optional_uint32', 1 << 31, integer_64) + else: + # 64-bit python can fit uint32 inside an int + TestGetAndDeserialize('optional_uint32', 1 << 31, int) + TestGetAndDeserialize('optional_int64', 1 << 30, integer_64) + TestGetAndDeserialize('optional_int64', 1 << 60, integer_64) + TestGetAndDeserialize('optional_uint64', 1 << 30, integer_64) + TestGetAndDeserialize('optional_uint64', 1 << 60, integer_64) + + def testIntegerTypes(self, message_module): + self.assertIntegerTypes(lambda x: x, message_module) + + def testNonStandardIntegerTypes(self, message_module): + self.assertIntegerTypes(test_util.NonStandardInteger, message_module) + + def testIllegalValuesForIntegers(self, message_module): + pb = message_module.TestAllTypes() + + # Strings are illegal, even when the represent an integer. + with self.assertRaises(TypeError): + pb.optional_uint64 = '2' + + # The exact error should propagate with a poorly written custom integer. + with self.assertRaisesRegexp(RuntimeError, 'my_error'): + pb.optional_uint64 = test_util.NonStandardInteger(5, 'my_error') + + def assetIntegerBoundsChecking(self, integer_fn, message_module): + """Verifies bounds checking for scalar integer fields. + + Args: + integer_fn: A function to wrap the integers that will be assigned. + message_module: unittest_pb2 or unittest_proto3_arena_pb2 + """ + def TestMinAndMaxIntegers(field_name, expected_min, expected_max): + pb = message_module.TestAllTypes() + expected_min = integer_fn(expected_min) + expected_max = integer_fn(expected_max) + setattr(pb, field_name, expected_min) + self.assertEqual(expected_min, getattr(pb, field_name)) + setattr(pb, field_name, expected_max) + self.assertEqual(expected_max, getattr(pb, field_name)) + self.assertRaises((ValueError, TypeError), setattr, pb, field_name, + expected_min - 1) + self.assertRaises((ValueError, TypeError), setattr, pb, field_name, + expected_max + 1) + + TestMinAndMaxIntegers('optional_int32', -(1 << 31), (1 << 31) - 1) + TestMinAndMaxIntegers('optional_uint32', 0, 0xffffffff) + TestMinAndMaxIntegers('optional_int64', -(1 << 63), (1 << 63) - 1) + TestMinAndMaxIntegers('optional_uint64', 0, 0xffffffffffffffff) + # A bit of white-box testing since -1 is an int and not a long in C++ and + # so goes down a different path. + pb = message_module.TestAllTypes() + with self.assertRaises((ValueError, TypeError)): + pb.optional_uint64 = integer_fn(-(1 << 63)) + + pb = message_module.TestAllTypes() + pb.optional_nested_enum = integer_fn(1) + self.assertEqual(1, pb.optional_nested_enum) + + def testSingleScalarBoundsChecking(self, message_module): + self.assetIntegerBoundsChecking(lambda x: x, message_module) + + def testNonStandardSingleScalarBoundsChecking(self, message_module): + self.assetIntegerBoundsChecking( + test_util.NonStandardInteger, message_module) + + def testRepeatedScalarTypeSafety(self, message_module): + proto = message_module.TestAllTypes() + self.assertRaises(TypeError, proto.repeated_int32.append, 1.1) + self.assertRaises(TypeError, proto.repeated_int32.append, 'foo') + self.assertRaises(TypeError, proto.repeated_string, 10) + self.assertRaises(TypeError, proto.repeated_bytes, 10) + + proto.repeated_int32.append(10) + proto.repeated_int32[0] = 23 + self.assertRaises(IndexError, proto.repeated_int32.__setitem__, 500, 23) + self.assertRaises(TypeError, proto.repeated_int32.__setitem__, 0, 'abc') + self.assertRaises(TypeError, proto.repeated_int32.__setitem__, 0, []) + self.assertRaises(TypeError, proto.repeated_int32.__setitem__, + 'index', 23) + + proto.repeated_string.append('2') + self.assertRaises(TypeError, proto.repeated_string.__setitem__, 0, 10) + + # Repeated enums tests. + #proto.repeated_nested_enum.append(0) + + def testSingleScalarGettersAndSetters(self, message_module): + proto = message_module.TestAllTypes() + self.assertEqual(0, proto.optional_int32) + proto.optional_int32 = 1 + self.assertEqual(1, proto.optional_int32) + + proto.optional_uint64 = 0xffffffffffff + self.assertEqual(0xffffffffffff, proto.optional_uint64) + proto.optional_uint64 = 0xffffffffffffffff + self.assertEqual(0xffffffffffffffff, proto.optional_uint64) + # TODO(robinson): Test all other scalar field types. + + def testEnums(self, message_module): + proto = message_module.TestAllTypes() + self.assertEqual(1, proto.FOO) + self.assertEqual(1, message_module.TestAllTypes.FOO) + self.assertEqual(2, proto.BAR) + self.assertEqual(2, message_module.TestAllTypes.BAR) + self.assertEqual(3, proto.BAZ) + self.assertEqual(3, message_module.TestAllTypes.BAZ) + + def testEnum_Name(self, message_module): + self.assertEqual( + 'FOREIGN_FOO', + message_module.ForeignEnum.Name(message_module.FOREIGN_FOO)) + self.assertEqual( + 'FOREIGN_BAR', + message_module.ForeignEnum.Name(message_module.FOREIGN_BAR)) + self.assertEqual( + 'FOREIGN_BAZ', + message_module.ForeignEnum.Name(message_module.FOREIGN_BAZ)) + self.assertRaises(ValueError, + message_module.ForeignEnum.Name, 11312) + + proto = message_module.TestAllTypes() + self.assertEqual('FOO', + proto.NestedEnum.Name(proto.FOO)) + self.assertEqual('FOO', + message_module.TestAllTypes.NestedEnum.Name(proto.FOO)) + self.assertEqual('BAR', + proto.NestedEnum.Name(proto.BAR)) + self.assertEqual('BAR', + message_module.TestAllTypes.NestedEnum.Name(proto.BAR)) + self.assertEqual('BAZ', + proto.NestedEnum.Name(proto.BAZ)) + self.assertEqual('BAZ', + message_module.TestAllTypes.NestedEnum.Name(proto.BAZ)) + self.assertRaises(ValueError, + proto.NestedEnum.Name, 11312) + self.assertRaises(ValueError, + message_module.TestAllTypes.NestedEnum.Name, 11312) + + # Check some coercion cases. + self.assertRaises(TypeError, message_module.TestAllTypes.NestedEnum.Name, + 11312.0) + self.assertRaises(TypeError, message_module.TestAllTypes.NestedEnum.Name, + None) + self.assertEqual('FOO', message_module.TestAllTypes.NestedEnum.Name(True)) + + def testEnum_Value(self, message_module): + self.assertEqual(message_module.FOREIGN_FOO, + message_module.ForeignEnum.Value('FOREIGN_FOO')) + self.assertEqual(message_module.FOREIGN_FOO, + message_module.ForeignEnum.FOREIGN_FOO) + + self.assertEqual(message_module.FOREIGN_BAR, + message_module.ForeignEnum.Value('FOREIGN_BAR')) + self.assertEqual(message_module.FOREIGN_BAR, + message_module.ForeignEnum.FOREIGN_BAR) + + self.assertEqual(message_module.FOREIGN_BAZ, + message_module.ForeignEnum.Value('FOREIGN_BAZ')) + self.assertEqual(message_module.FOREIGN_BAZ, + message_module.ForeignEnum.FOREIGN_BAZ) + + self.assertRaises(ValueError, + message_module.ForeignEnum.Value, 'FO') + with self.assertRaises(AttributeError): + message_module.ForeignEnum.FO + + proto = message_module.TestAllTypes() + self.assertEqual(proto.FOO, + proto.NestedEnum.Value('FOO')) + self.assertEqual(proto.FOO, + proto.NestedEnum.FOO) + + self.assertEqual(proto.FOO, + message_module.TestAllTypes.NestedEnum.Value('FOO')) + self.assertEqual(proto.FOO, + message_module.TestAllTypes.NestedEnum.FOO) + + self.assertEqual(proto.BAR, + proto.NestedEnum.Value('BAR')) + self.assertEqual(proto.BAR, + proto.NestedEnum.BAR) + + self.assertEqual(proto.BAR, + message_module.TestAllTypes.NestedEnum.Value('BAR')) + self.assertEqual(proto.BAR, + message_module.TestAllTypes.NestedEnum.BAR) + + self.assertEqual(proto.BAZ, + proto.NestedEnum.Value('BAZ')) + self.assertEqual(proto.BAZ, + proto.NestedEnum.BAZ) + + self.assertEqual(proto.BAZ, + message_module.TestAllTypes.NestedEnum.Value('BAZ')) + self.assertEqual(proto.BAZ, + message_module.TestAllTypes.NestedEnum.BAZ) + + self.assertRaises(ValueError, + proto.NestedEnum.Value, 'Foo') + with self.assertRaises(AttributeError): + proto.NestedEnum.Value.Foo + + self.assertRaises(ValueError, + message_module.TestAllTypes.NestedEnum.Value, 'Foo') + with self.assertRaises(AttributeError): + message_module.TestAllTypes.NestedEnum.Value.Foo + + def testEnum_KeysAndValues(self, message_module): + if message_module == unittest_pb2: + keys = ['FOREIGN_FOO', 'FOREIGN_BAR', 'FOREIGN_BAZ'] + values = [4, 5, 6] + items = [('FOREIGN_FOO', 4), ('FOREIGN_BAR', 5), ('FOREIGN_BAZ', 6)] + else: + keys = ['FOREIGN_ZERO', 'FOREIGN_FOO', 'FOREIGN_BAR', 'FOREIGN_BAZ'] + values = [0, 4, 5, 6] + items = [('FOREIGN_ZERO', 0), ('FOREIGN_FOO', 4), + ('FOREIGN_BAR', 5), ('FOREIGN_BAZ', 6)] + self.assertEqual(keys, + list(message_module.ForeignEnum.keys())) + self.assertEqual(values, + list(message_module.ForeignEnum.values())) + self.assertEqual(items, + list(message_module.ForeignEnum.items())) + + proto = message_module.TestAllTypes() + if message_module == unittest_pb2: + keys = ['FOO', 'BAR', 'BAZ', 'NEG'] + values = [1, 2, 3, -1] + items = [('FOO', 1), ('BAR', 2), ('BAZ', 3), ('NEG', -1)] + else: + keys = ['ZERO', 'FOO', 'BAR', 'BAZ', 'NEG'] + values = [0, 1, 2, 3, -1] + items = [('ZERO', 0), ('FOO', 1), ('BAR', 2), ('BAZ', 3), ('NEG', -1)] + self.assertEqual(keys, list(proto.NestedEnum.keys())) + self.assertEqual(values, list(proto.NestedEnum.values())) + self.assertEqual(items, + list(proto.NestedEnum.items())) + + def testStaticParseFrom(self, message_module): + proto1 = message_module.TestAllTypes() + test_util.SetAllFields(proto1) + + string1 = proto1.SerializeToString() + proto2 = message_module.TestAllTypes.FromString(string1) + + # Messages should be equal. + self.assertEqual(proto2, proto1) + + def testMergeFromSingularField(self, message_module): + # Test merge with just a singular field. + proto1 = message_module.TestAllTypes() + proto1.optional_int32 = 1 + + proto2 = message_module.TestAllTypes() + # This shouldn't get overwritten. + proto2.optional_string = 'value' + + proto2.MergeFrom(proto1) + self.assertEqual(1, proto2.optional_int32) + self.assertEqual('value', proto2.optional_string) + + def testMergeFromRepeatedField(self, message_module): + # Test merge with just a repeated field. + proto1 = message_module.TestAllTypes() + proto1.repeated_int32.append(1) + proto1.repeated_int32.append(2) + + proto2 = message_module.TestAllTypes() + proto2.repeated_int32.append(0) + proto2.MergeFrom(proto1) + + self.assertEqual(0, proto2.repeated_int32[0]) + self.assertEqual(1, proto2.repeated_int32[1]) + self.assertEqual(2, proto2.repeated_int32[2]) + + def testMergeFromRepeatedNestedMessage(self, message_module): + # Test merge with a repeated nested message. + proto1 = message_module.TestAllTypes() + m = proto1.repeated_nested_message.add() + m.bb = 123 + m = proto1.repeated_nested_message.add() + m.bb = 321 + + proto2 = message_module.TestAllTypes() + m = proto2.repeated_nested_message.add() + m.bb = 999 + proto2.MergeFrom(proto1) + self.assertEqual(999, proto2.repeated_nested_message[0].bb) + self.assertEqual(123, proto2.repeated_nested_message[1].bb) + self.assertEqual(321, proto2.repeated_nested_message[2].bb) + + proto3 = message_module.TestAllTypes() + proto3.repeated_nested_message.MergeFrom(proto2.repeated_nested_message) + self.assertEqual(999, proto3.repeated_nested_message[0].bb) + self.assertEqual(123, proto3.repeated_nested_message[1].bb) + self.assertEqual(321, proto3.repeated_nested_message[2].bb) + + def testMergeFromAllFields(self, message_module): + # With all fields set. + proto1 = message_module.TestAllTypes() + test_util.SetAllFields(proto1) + proto2 = message_module.TestAllTypes() + proto2.MergeFrom(proto1) + + # Messages should be equal. + self.assertEqual(proto2, proto1) + + # Serialized string should be equal too. + string1 = proto1.SerializeToString() + string2 = proto2.SerializeToString() + self.assertEqual(string1, string2) + + def testMergeFromBug(self, message_module): + message1 = message_module.TestAllTypes() + message2 = message_module.TestAllTypes() + + # Cause optional_nested_message to be instantiated within message1, even + # though it is not considered to be "present". + message1.optional_nested_message + self.assertFalse(message1.HasField('optional_nested_message')) + + # Merge into message2. This should not instantiate the field is message2. + message2.MergeFrom(message1) + self.assertFalse(message2.HasField('optional_nested_message')) + + def testCopyFromSingularField(self, message_module): + # Test copy with just a singular field. + proto1 = message_module.TestAllTypes() + proto1.optional_int32 = 1 + proto1.optional_string = 'important-text' + + proto2 = message_module.TestAllTypes() + proto2.optional_string = 'value' + + proto2.CopyFrom(proto1) + self.assertEqual(1, proto2.optional_int32) + self.assertEqual('important-text', proto2.optional_string) + + def testCopyFromRepeatedField(self, message_module): + # Test copy with a repeated field. + proto1 = message_module.TestAllTypes() + proto1.repeated_int32.append(1) + proto1.repeated_int32.append(2) + + proto2 = message_module.TestAllTypes() + proto2.repeated_int32.append(0) + proto2.CopyFrom(proto1) + + self.assertEqual(1, proto2.repeated_int32[0]) + self.assertEqual(2, proto2.repeated_int32[1]) + + def testCopyFromAllFields(self, message_module): + # With all fields set. + proto1 = message_module.TestAllTypes() + test_util.SetAllFields(proto1) + proto2 = message_module.TestAllTypes() + proto2.CopyFrom(proto1) + + # Messages should be equal. + self.assertEqual(proto2, proto1) + + # Serialized string should be equal too. + string1 = proto1.SerializeToString() + string2 = proto2.SerializeToString() + self.assertEqual(string1, string2) + + def testCopyFromSelf(self, message_module): + proto1 = message_module.TestAllTypes() + proto1.repeated_int32.append(1) + proto1.optional_int32 = 2 + proto1.optional_string = 'important-text' + + proto1.CopyFrom(proto1) + self.assertEqual(1, proto1.repeated_int32[0]) + self.assertEqual(2, proto1.optional_int32) + self.assertEqual('important-text', proto1.optional_string) + + def testDeepCopy(self, message_module): + proto1 = message_module.TestAllTypes() + proto1.optional_int32 = 1 + proto2 = copy.deepcopy(proto1) + self.assertEqual(1, proto2.optional_int32) + + proto1.repeated_int32.append(2) + proto1.repeated_int32.append(3) + container = copy.deepcopy(proto1.repeated_int32) + self.assertEqual([2, 3], container) + container.remove(container[0]) + self.assertEqual([3], container) + + message1 = proto1.repeated_nested_message.add() + message1.bb = 1 + messages = copy.deepcopy(proto1.repeated_nested_message) + self.assertEqual(proto1.repeated_nested_message, messages) + message1.bb = 2 + self.assertNotEqual(proto1.repeated_nested_message, messages) + messages.remove(messages[0]) + self.assertEqual(len(messages), 0) + + # TODO(anuraag): Implement deepcopy for extension dict + + def testDisconnectingBeforeClear(self, message_module): + proto = message_module.TestAllTypes() + nested = proto.optional_nested_message + proto.Clear() + self.assertIsNot(nested, proto.optional_nested_message) + nested.bb = 23 + self.assertFalse(proto.HasField('optional_nested_message')) + self.assertEqual(0, proto.optional_nested_message.bb) + + proto = message_module.TestAllTypes() + nested = proto.optional_nested_message + nested.bb = 5 + foreign = proto.optional_foreign_message + foreign.c = 6 + proto.Clear() + self.assertIsNot(nested, proto.optional_nested_message) + self.assertIsNot(foreign, proto.optional_foreign_message) + self.assertEqual(5, nested.bb) + self.assertEqual(6, foreign.c) + nested.bb = 15 + foreign.c = 16 + self.assertFalse(proto.HasField('optional_nested_message')) + self.assertEqual(0, proto.optional_nested_message.bb) + self.assertFalse(proto.HasField('optional_foreign_message')) + self.assertEqual(0, proto.optional_foreign_message.c) + + def testStringUTF8Encoding(self, message_module): + proto = message_module.TestAllTypes() + + # Assignment of a unicode object to a field of type 'bytes' is not allowed. + self.assertRaises(TypeError, + setattr, proto, 'optional_bytes', u'unicode object') + + # Check that the default value is of python's 'unicode' type. + self.assertEqual(type(proto.optional_string), six.text_type) + + proto.optional_string = six.text_type('Testing') + self.assertEqual(proto.optional_string, str('Testing')) + + # Assign a value of type 'str' which can be encoded in UTF-8. + proto.optional_string = str('Testing') + self.assertEqual(proto.optional_string, six.text_type('Testing')) + + # Try to assign a 'bytes' object which contains non-UTF-8. + self.assertRaises(ValueError, + setattr, proto, 'optional_string', b'a\x80a') + # No exception: Assign already encoded UTF-8 bytes to a string field. + utf8_bytes = u'Тест'.encode('utf-8') + proto.optional_string = utf8_bytes + # No exception: Assign the a non-ascii unicode object. + proto.optional_string = u'Тест' + # No exception thrown (normal str assignment containing ASCII). + proto.optional_string = 'abc' + + def testBytesInTextFormat(self, message_module): + proto = message_module.TestAllTypes(optional_bytes=b'\x00\x7f\x80\xff') + self.assertEqual(u'optional_bytes: "\\000\\177\\200\\377"\n', + six.text_type(proto)) + + def testEmptyNestedMessage(self, message_module): + proto = message_module.TestAllTypes() + proto.optional_nested_message.MergeFrom( + message_module.TestAllTypes.NestedMessage()) + self.assertTrue(proto.HasField('optional_nested_message')) + + proto = message_module.TestAllTypes() + proto.optional_nested_message.CopyFrom( + message_module.TestAllTypes.NestedMessage()) + self.assertTrue(proto.HasField('optional_nested_message')) + + proto = message_module.TestAllTypes() + bytes_read = proto.optional_nested_message.MergeFromString(b'') + self.assertEqual(0, bytes_read) + self.assertTrue(proto.HasField('optional_nested_message')) + + proto = message_module.TestAllTypes() + proto.optional_nested_message.ParseFromString(b'') + self.assertTrue(proto.HasField('optional_nested_message')) + + serialized = proto.SerializeToString() + proto2 = message_module.TestAllTypes() + self.assertEqual( + len(serialized), + proto2.MergeFromString(serialized)) + self.assertTrue(proto2.HasField('optional_nested_message')) + + +# Class to test proto2-only features (required, extensions, etc.) +@testing_refleaks.TestCase +class Proto2ReflectionTest(unittest.TestCase): + def testRepeatedCompositeConstructor(self): # Constructor with only repeated composite types should succeed. proto = unittest_pb2.TestAllTypes( @@ -183,90 +939,25 @@ unittest_pb2.TestAllTypes.RepeatedGroup(a=2)], list(proto.repeatedgroup)) - def testMixedConstructor(self): - # Constructor with only mixed types should succeed. - proto = unittest_pb2.TestAllTypes( - optional_int32=24, - optional_string='optional_string', - repeated_double=[1.23, 54.321], - repeated_bool=[True, False, False], - repeated_nested_message=[ - unittest_pb2.TestAllTypes.NestedMessage( - bb=unittest_pb2.TestAllTypes.FOO), - unittest_pb2.TestAllTypes.NestedMessage( - bb=unittest_pb2.TestAllTypes.BAR)], - repeated_foreign_message=[ - unittest_pb2.ForeignMessage(c=-43), - unittest_pb2.ForeignMessage(c=45324), - unittest_pb2.ForeignMessage(c=12)], - optional_nested_message=None) - - self.assertEqual(24, proto.optional_int32) - self.assertEqual('optional_string', proto.optional_string) - self.assertEqual([1.23, 54.321], list(proto.repeated_double)) - self.assertEqual([True, False, False], list(proto.repeated_bool)) - self.assertEqual( - [unittest_pb2.TestAllTypes.NestedMessage( - bb=unittest_pb2.TestAllTypes.FOO), - unittest_pb2.TestAllTypes.NestedMessage( - bb=unittest_pb2.TestAllTypes.BAR)], - list(proto.repeated_nested_message)) - self.assertEqual( - [unittest_pb2.ForeignMessage(c=-43), - unittest_pb2.ForeignMessage(c=45324), - unittest_pb2.ForeignMessage(c=12)], - list(proto.repeated_foreign_message)) - self.assertFalse(proto.HasField("optional_nested_message")) - - def testConstructorTypeError(self): - self.assertRaises( - TypeError, unittest_pb2.TestAllTypes, optional_int32="foo") - self.assertRaises( - TypeError, unittest_pb2.TestAllTypes, optional_string=1234) - self.assertRaises( - TypeError, unittest_pb2.TestAllTypes, optional_nested_message=1234) - self.assertRaises( - TypeError, unittest_pb2.TestAllTypes, repeated_int32=1234) - self.assertRaises( - TypeError, unittest_pb2.TestAllTypes, repeated_int32=["foo"]) - self.assertRaises( - TypeError, unittest_pb2.TestAllTypes, repeated_string=1234) - self.assertRaises( - TypeError, unittest_pb2.TestAllTypes, repeated_string=[1234]) - self.assertRaises( - TypeError, unittest_pb2.TestAllTypes, repeated_nested_message=1234) - self.assertRaises( - TypeError, unittest_pb2.TestAllTypes, repeated_nested_message=[1234]) - - def testConstructorInvalidatesCachedByteSize(self): - message = unittest_pb2.TestAllTypes(optional_int32 = 12) - self.assertEqual(2, message.ByteSize()) - - message = unittest_pb2.TestAllTypes( - optional_nested_message = unittest_pb2.TestAllTypes.NestedMessage()) - self.assertEqual(3, message.ByteSize()) - - message = unittest_pb2.TestAllTypes(repeated_int32 = [12]) - self.assertEqual(3, message.ByteSize()) - - message = unittest_pb2.TestAllTypes( - repeated_nested_message = [unittest_pb2.TestAllTypes.NestedMessage()]) - self.assertEqual(3, message.ByteSize()) + def assertListsEqual(self, values, others): + self.assertEqual(len(values), len(others)) + for i in range(len(values)): + self.assertEqual(values[i], others[i]) def testSimpleHasBits(self): # Test a scalar. proto = unittest_pb2.TestAllTypes() - self.assertTrue(not proto.HasField('optional_int32')) + self.assertFalse(proto.HasField('optional_int32')) self.assertEqual(0, proto.optional_int32) # HasField() shouldn't be true if all we've done is # read the default value. - self.assertTrue(not proto.HasField('optional_int32')) + self.assertFalse(proto.HasField('optional_int32')) proto.optional_int32 = 1 # Setting a value however *should* set the "has" bit. self.assertTrue(proto.HasField('optional_int32')) proto.ClearField('optional_int32') # And clearing that value should unset the "has" bit. - self.assertTrue(not proto.HasField('optional_int32')) + self.assertFalse(proto.HasField('optional_int32')) def testHasBitsWithSinglyNestedScalar(self): # Helper used to test foreign messages and groups. @@ -311,9 +1002,9 @@ original_scalar_value = getattr(composite_field, scalar_field_name) self.assertEqual(0, original_scalar_value) # Assert that the composite object does not "have" the scalar. - self.assertTrue(not composite_field.HasField(scalar_field_name)) + self.assertFalse(composite_field.HasField(scalar_field_name)) # Assert that proto does not "have" the composite field. - self.assertTrue(not proto.HasField(composite_field_name)) + self.assertFalse(proto.HasField(composite_field_name)) # Now set the scalar within the composite field. Ensure that the setting # is reflected, and that proto.HasField('composite') and @@ -332,15 +1023,15 @@ # ...and ensure that the "has" bits are all back to False... composite_field = getattr(proto, composite_field_name) - self.assertTrue(not composite_field.HasField(scalar_field_name)) - self.assertTrue(not proto.HasField(composite_field_name)) + self.assertFalse(composite_field.HasField(scalar_field_name)) + self.assertFalse(proto.HasField(composite_field_name)) # ...and ensure that the scalar field has returned to its default. self.assertEqual(0, getattr(composite_field, scalar_field_name)) - self.assertTrue(old_composite_field is not composite_field) + self.assertIsNot(old_composite_field, composite_field) setattr(old_composite_field, scalar_field_name, new_val) - self.assertTrue(not composite_field.HasField(scalar_field_name)) - self.assertTrue(not proto.HasField(composite_field_name)) + self.assertFalse(composite_field.HasField(scalar_field_name)) + self.assertFalse(proto.HasField(composite_field_name)) self.assertEqual(0, getattr(composite_field, scalar_field_name)) # Test simple, single-level nesting when we set a scalar. @@ -349,81 +1040,6 @@ TestCompositeHasBits('optional_foreign_message', 'c') TestCompositeHasBits('optional_import_message', 'd') - def testReferencesToNestedMessage(self): - proto = unittest_pb2.TestAllTypes() - nested = proto.optional_nested_message - del proto - # A previous version had a bug where this would raise an exception when - # hitting a now-dead weak reference. - nested.bb = 23 - - def testDisconnectingNestedMessageBeforeSettingField(self): - proto = unittest_pb2.TestAllTypes() - nested = proto.optional_nested_message - proto.ClearField('optional_nested_message') # Should disconnect from parent - self.assertTrue(nested is not proto.optional_nested_message) - nested.bb = 23 - self.assertTrue(not proto.HasField('optional_nested_message')) - self.assertEqual(0, proto.optional_nested_message.bb) - - def testGetDefaultMessageAfterDisconnectingDefaultMessage(self): - proto = unittest_pb2.TestAllTypes() - nested = proto.optional_nested_message - proto.ClearField('optional_nested_message') - del proto - del nested - # Force a garbage collect so that the underlying CMessages are freed along - # with the Messages they point to. This is to make sure we're not deleting - # default message instances. - gc.collect() - proto = unittest_pb2.TestAllTypes() - nested = proto.optional_nested_message - - def testDisconnectingNestedMessageAfterSettingField(self): - proto = unittest_pb2.TestAllTypes() - nested = proto.optional_nested_message - nested.bb = 5 - self.assertTrue(proto.HasField('optional_nested_message')) - proto.ClearField('optional_nested_message') # Should disconnect from parent - self.assertEqual(5, nested.bb) - self.assertEqual(0, proto.optional_nested_message.bb) - self.assertTrue(nested is not proto.optional_nested_message) - nested.bb = 23 - self.assertTrue(not proto.HasField('optional_nested_message')) - self.assertEqual(0, proto.optional_nested_message.bb) - - def testDisconnectingNestedMessageBeforeGettingField(self): - proto = unittest_pb2.TestAllTypes() - self.assertTrue(not proto.HasField('optional_nested_message')) - proto.ClearField('optional_nested_message') - self.assertTrue(not proto.HasField('optional_nested_message')) - - def testDisconnectingNestedMessageAfterMerge(self): - # This test exercises the code path that does not use ReleaseMessage(). - # The underlying fear is that if we use ReleaseMessage() incorrectly, - # we will have memory leaks. It's hard to check that that doesn't happen, - # but at least we can exercise that code path to make sure it works. - proto1 = unittest_pb2.TestAllTypes() - proto2 = unittest_pb2.TestAllTypes() - proto2.optional_nested_message.bb = 5 - proto1.MergeFrom(proto2) - self.assertTrue(proto1.HasField('optional_nested_message')) - proto1.ClearField('optional_nested_message') - self.assertTrue(not proto1.HasField('optional_nested_message')) - - def testDisconnectingLazyNestedMessage(self): - # This test exercises releasing a nested message that is lazy. This test - # only exercises real code in the C++ implementation as Python does not - # support lazy parsing, but the current C++ implementation results in - # memory corruption and a crash. - if api_implementation.Type() != 'python': - return - proto = unittest_pb2.TestAllTypes() - proto.optional_lazy_message.bb = 5 - proto.ClearField('optional_lazy_message') - del proto - gc.collect() - def testHasBitsWhenModifyingRepeatedFields(self): # Test nesting when we add an element to a repeated field in a submessage. proto = unittest_pb2.TestNestedMessageHasBits() @@ -435,16 +1051,16 @@ # Do the same test, but with a repeated composite field within the # submessage. proto.ClearField('optional_nested_message') - self.assertTrue(not proto.HasField('optional_nested_message')) + self.assertFalse(proto.HasField('optional_nested_message')) proto.optional_nested_message.nestedmessage_repeated_foreignmessage.add() self.assertTrue(proto.HasField('optional_nested_message')) def testHasBitsForManyLevelsOfNesting(self): # Test nesting many levels deep. recursive_proto = unittest_pb2.TestMutualRecursionA() - self.assertTrue(not recursive_proto.HasField('bb')) + self.assertFalse(recursive_proto.HasField('bb')) self.assertEqual(0, recursive_proto.bb.a.bb.a.bb.optional_int32) - self.assertTrue(not recursive_proto.HasField('bb')) + self.assertFalse(recursive_proto.HasField('bb')) recursive_proto.bb.a.bb.a.bb.optional_int32 = 5 self.assertEqual(5, recursive_proto.bb.a.bb.a.bb.optional_int32) self.assertTrue(recursive_proto.HasField('bb')) @@ -452,50 +1068,9 @@ self.assertTrue(recursive_proto.bb.a.HasField('bb')) self.assertTrue(recursive_proto.bb.a.bb.HasField('a')) self.assertTrue(recursive_proto.bb.a.bb.a.HasField('bb')) - self.assertTrue(not recursive_proto.bb.a.bb.a.bb.HasField('a')) + self.assertFalse(recursive_proto.bb.a.bb.a.bb.HasField('a')) self.assertTrue(recursive_proto.bb.a.bb.a.bb.HasField('optional_int32')) - def testSingularListFields(self): - proto = unittest_pb2.TestAllTypes() - proto.optional_fixed32 = 1 - proto.optional_int32 = 5 - proto.optional_string = 'foo' - # Access sub-message but don't set it yet. - nested_message = proto.optional_nested_message - self.assertEqual( - [ (proto.DESCRIPTOR.fields_by_name['optional_int32' ], 5), - (proto.DESCRIPTOR.fields_by_name['optional_fixed32'], 1), - (proto.DESCRIPTOR.fields_by_name['optional_string' ], 'foo') ], - proto.ListFields()) - - proto.optional_nested_message.bb = 123 - self.assertEqual( - [ (proto.DESCRIPTOR.fields_by_name['optional_int32' ], 5), - (proto.DESCRIPTOR.fields_by_name['optional_fixed32'], 1), - (proto.DESCRIPTOR.fields_by_name['optional_string' ], 'foo'), - (proto.DESCRIPTOR.fields_by_name['optional_nested_message' ], - nested_message) ], - proto.ListFields()) - - def testRepeatedListFields(self): - proto = unittest_pb2.TestAllTypes() - proto.repeated_fixed32.append(1) - proto.repeated_int32.append(5) - proto.repeated_int32.append(11) - proto.repeated_string.extend(['foo', 'bar']) - proto.repeated_string.extend([]) - proto.repeated_string.append('baz') - proto.repeated_string.extend(str(x) for x in range(2)) - proto.optional_int32 = 21 - proto.repeated_bool # Access but don't set anything; should not be listed. - self.assertEqual( - [ (proto.DESCRIPTOR.fields_by_name['optional_int32' ], 21), - (proto.DESCRIPTOR.fields_by_name['repeated_int32' ], [5, 11]), - (proto.DESCRIPTOR.fields_by_name['repeated_fixed32'], [1]), - (proto.DESCRIPTOR.fields_by_name['repeated_string' ], - ['foo', 'bar', 'baz', '0', '1']) ], - proto.ListFields()) - def testSingularListExtensions(self): proto = unittest_pb2.TestAllExtensions() proto.Extensions[unittest_pb2.optional_fixed32_extension] = 1 @@ -591,11 +1166,6 @@ proto = unittest_pb2.TestAllTypes() self.assertRaises(ValueError, proto.HasField, 'nonexistent_field') - def testClearFieldWithUnknownFieldName(self): - proto = unittest_pb2.TestAllTypes() - self.assertRaises(ValueError, proto.ClearField, 'nonexistent_field') - self.assertRaises(ValueError, proto.ClearField, b'nonexistent_field') - def testClearRemovesChildren(self): # Make sure there aren't any implementation bugs that are only partially # clearing the message (which can happen in the more complex C++ @@ -607,162 +1177,6 @@ proto.CopyFrom(proto2) self.assertRaises(IndexError, lambda: proto.repeated_message[5]) - def testDisallowedAssignments(self): - # It's illegal to assign values directly to repeated fields - # or to nonrepeated composite fields. Ensure that this fails. - proto = unittest_pb2.TestAllTypes() - # Repeated fields. - self.assertRaises(AttributeError, setattr, proto, 'repeated_int32', 10) - # Lists shouldn't work, either. - self.assertRaises(AttributeError, setattr, proto, 'repeated_int32', [10]) - # Composite fields. - self.assertRaises(AttributeError, setattr, proto, - 'optional_nested_message', 23) - # Assignment to a repeated nested message field without specifying - # the index in the array of nested messages. - self.assertRaises(AttributeError, setattr, proto.repeated_nested_message, - 'bb', 34) - # Assignment to an attribute of a repeated field. - self.assertRaises(AttributeError, setattr, proto.repeated_float, - 'some_attribute', 34) - # proto.nonexistent_field = 23 should fail as well. - self.assertRaises(AttributeError, setattr, proto, 'nonexistent_field', 23) - - def testSingleScalarTypeSafety(self): - proto = unittest_pb2.TestAllTypes() - self.assertRaises(TypeError, setattr, proto, 'optional_int32', 1.1) - self.assertRaises(TypeError, setattr, proto, 'optional_int32', 'foo') - self.assertRaises(TypeError, setattr, proto, 'optional_string', 10) - self.assertRaises(TypeError, setattr, proto, 'optional_bytes', 10) - self.assertRaises(TypeError, setattr, proto, 'optional_bool', 'foo') - self.assertRaises(TypeError, setattr, proto, 'optional_float', 'foo') - self.assertRaises(TypeError, setattr, proto, 'optional_double', 'foo') - # TODO(jieluo): Fix type checking difference for python and c extension - if api_implementation.Type() == 'python': - self.assertRaises(TypeError, setattr, proto, 'optional_bool', 1.1) - else: - proto.optional_bool = 1.1 - - def assertIntegerTypes(self, integer_fn): - """Verifies setting of scalar integers. - - Args: - integer_fn: A function to wrap the integers that will be assigned. - """ - def TestGetAndDeserialize(field_name, value, expected_type): - proto = unittest_pb2.TestAllTypes() - value = integer_fn(value) - setattr(proto, field_name, value) - self.assertIsInstance(getattr(proto, field_name), expected_type) - proto2 = unittest_pb2.TestAllTypes() - proto2.ParseFromString(proto.SerializeToString()) - self.assertIsInstance(getattr(proto2, field_name), expected_type) - - TestGetAndDeserialize('optional_int32', 1, int) - TestGetAndDeserialize('optional_int32', 1 << 30, int) - TestGetAndDeserialize('optional_uint32', 1 << 30, int) - integer_64 = long - if struct.calcsize('L') == 4: - # Python only has signed ints, so 32-bit python can't fit an uint32 - # in an int. - TestGetAndDeserialize('optional_uint32', 1 << 31, integer_64) - else: - # 64-bit python can fit uint32 inside an int - TestGetAndDeserialize('optional_uint32', 1 << 31, int) - TestGetAndDeserialize('optional_int64', 1 << 30, integer_64) - TestGetAndDeserialize('optional_int64', 1 << 60, integer_64) - TestGetAndDeserialize('optional_uint64', 1 << 30, integer_64) - TestGetAndDeserialize('optional_uint64', 1 << 60, integer_64) - - def testIntegerTypes(self): - self.assertIntegerTypes(lambda x: x) - - def testNonStandardIntegerTypes(self): - self.assertIntegerTypes(test_util.NonStandardInteger) - - def testIllegalValuesForIntegers(self): - pb = unittest_pb2.TestAllTypes() - - # Strings are illegal, even when the represent an integer. - with self.assertRaises(TypeError): - pb.optional_uint64 = '2' - - # The exact error should propagate with a poorly written custom integer. - with self.assertRaisesRegexp(RuntimeError, 'my_error'): - pb.optional_uint64 = test_util.NonStandardInteger(5, 'my_error') - - def assetIntegerBoundsChecking(self, integer_fn): - """Verifies bounds checking for scalar integer fields. - - Args: - integer_fn: A function to wrap the integers that will be assigned. - """ - def TestMinAndMaxIntegers(field_name, expected_min, expected_max): - pb = unittest_pb2.TestAllTypes() - expected_min = integer_fn(expected_min) - expected_max = integer_fn(expected_max) - setattr(pb, field_name, expected_min) - self.assertEqual(expected_min, getattr(pb, field_name)) - setattr(pb, field_name, expected_max) - self.assertEqual(expected_max, getattr(pb, field_name)) - self.assertRaises((ValueError, TypeError), setattr, pb, field_name, - expected_min - 1) - self.assertRaises((ValueError, TypeError), setattr, pb, field_name, - expected_max + 1) - - TestMinAndMaxIntegers('optional_int32', -(1 << 31), (1 << 31) - 1) - TestMinAndMaxIntegers('optional_uint32', 0, 0xffffffff) - TestMinAndMaxIntegers('optional_int64', -(1 << 63), (1 << 63) - 1) - TestMinAndMaxIntegers('optional_uint64', 0, 0xffffffffffffffff) - # A bit of white-box testing since -1 is an int and not a long in C++ and - # so goes down a different path. - pb = unittest_pb2.TestAllTypes() - with self.assertRaises((ValueError, TypeError)): - pb.optional_uint64 = integer_fn(-(1 << 63)) - - pb = unittest_pb2.TestAllTypes() - pb.optional_nested_enum = integer_fn(1) - self.assertEqual(1, pb.optional_nested_enum) - - def testSingleScalarBoundsChecking(self): - self.assetIntegerBoundsChecking(lambda x: x) - - def testNonStandardSingleScalarBoundsChecking(self): - self.assetIntegerBoundsChecking(test_util.NonStandardInteger) - - def testRepeatedScalarTypeSafety(self): - proto = unittest_pb2.TestAllTypes() - self.assertRaises(TypeError, proto.repeated_int32.append, 1.1) - self.assertRaises(TypeError, proto.repeated_int32.append, 'foo') - self.assertRaises(TypeError, proto.repeated_string, 10) - self.assertRaises(TypeError, proto.repeated_bytes, 10) - - proto.repeated_int32.append(10) - proto.repeated_int32[0] = 23 - self.assertRaises(IndexError, proto.repeated_int32.__setitem__, 500, 23) - self.assertRaises(TypeError, proto.repeated_int32.__setitem__, 0, 'abc') - self.assertRaises(TypeError, proto.repeated_int32.__setitem__, 0, []) - self.assertRaises(TypeError, proto.repeated_int32.__setitem__, - 'index', 23) - - proto.repeated_string.append('2') - self.assertRaises(TypeError, proto.repeated_string.__setitem__, 0, 10) - - # Repeated enums tests. - #proto.repeated_nested_enum.append(0) - - def testSingleScalarGettersAndSetters(self): - proto = unittest_pb2.TestAllTypes() - self.assertEqual(0, proto.optional_int32) - proto.optional_int32 = 1 - self.assertEqual(1, proto.optional_int32) - - proto.optional_uint64 = 0xffffffffffff - self.assertEqual(0xffffffffffff, proto.optional_uint64) - proto.optional_uint64 = 0xffffffffffffffff - self.assertEqual(0xffffffffffffffff, proto.optional_uint64) - # TODO(robinson): Test all other scalar field types. - def testSingleScalarClearField(self): proto = unittest_pb2.TestAllTypes() # Should be allowed to clear something that's not there (a no-op). @@ -771,127 +1185,13 @@ self.assertTrue(proto.HasField('optional_int32')) proto.ClearField('optional_int32') self.assertEqual(0, proto.optional_int32) - self.assertTrue(not proto.HasField('optional_int32')) + self.assertFalse(proto.HasField('optional_int32')) # TODO(robinson): Test all other scalar field types. - def testEnums(self): - proto = unittest_pb2.TestAllTypes() - self.assertEqual(1, proto.FOO) - self.assertEqual(1, unittest_pb2.TestAllTypes.FOO) - self.assertEqual(2, proto.BAR) - self.assertEqual(2, unittest_pb2.TestAllTypes.BAR) - self.assertEqual(3, proto.BAZ) - self.assertEqual(3, unittest_pb2.TestAllTypes.BAZ) - - def testEnum_Name(self): - self.assertEqual('FOREIGN_FOO', - unittest_pb2.ForeignEnum.Name(unittest_pb2.FOREIGN_FOO)) - self.assertEqual('FOREIGN_BAR', - unittest_pb2.ForeignEnum.Name(unittest_pb2.FOREIGN_BAR)) - self.assertEqual('FOREIGN_BAZ', - unittest_pb2.ForeignEnum.Name(unittest_pb2.FOREIGN_BAZ)) - self.assertRaises(ValueError, - unittest_pb2.ForeignEnum.Name, 11312) - - proto = unittest_pb2.TestAllTypes() - self.assertEqual('FOO', - proto.NestedEnum.Name(proto.FOO)) - self.assertEqual('FOO', - unittest_pb2.TestAllTypes.NestedEnum.Name(proto.FOO)) - self.assertEqual('BAR', - proto.NestedEnum.Name(proto.BAR)) - self.assertEqual('BAR', - unittest_pb2.TestAllTypes.NestedEnum.Name(proto.BAR)) - self.assertEqual('BAZ', - proto.NestedEnum.Name(proto.BAZ)) - self.assertEqual('BAZ', - unittest_pb2.TestAllTypes.NestedEnum.Name(proto.BAZ)) - self.assertRaises(ValueError, - proto.NestedEnum.Name, 11312) - self.assertRaises(ValueError, - unittest_pb2.TestAllTypes.NestedEnum.Name, 11312) - - def testEnum_Value(self): - self.assertEqual(unittest_pb2.FOREIGN_FOO, - unittest_pb2.ForeignEnum.Value('FOREIGN_FOO')) - self.assertEqual(unittest_pb2.FOREIGN_FOO, - unittest_pb2.ForeignEnum.FOREIGN_FOO) - - self.assertEqual(unittest_pb2.FOREIGN_BAR, - unittest_pb2.ForeignEnum.Value('FOREIGN_BAR')) - self.assertEqual(unittest_pb2.FOREIGN_BAR, - unittest_pb2.ForeignEnum.FOREIGN_BAR) - - self.assertEqual(unittest_pb2.FOREIGN_BAZ, - unittest_pb2.ForeignEnum.Value('FOREIGN_BAZ')) - self.assertEqual(unittest_pb2.FOREIGN_BAZ, - unittest_pb2.ForeignEnum.FOREIGN_BAZ) - - self.assertRaises(ValueError, - unittest_pb2.ForeignEnum.Value, 'FO') - with self.assertRaises(AttributeError): - unittest_pb2.ForeignEnum.FO - - proto = unittest_pb2.TestAllTypes() - self.assertEqual(proto.FOO, - proto.NestedEnum.Value('FOO')) - self.assertEqual(proto.FOO, - proto.NestedEnum.FOO) - - self.assertEqual(proto.FOO, - unittest_pb2.TestAllTypes.NestedEnum.Value('FOO')) - self.assertEqual(proto.FOO, - unittest_pb2.TestAllTypes.NestedEnum.FOO) - - self.assertEqual(proto.BAR, - proto.NestedEnum.Value('BAR')) - self.assertEqual(proto.BAR, - proto.NestedEnum.BAR) - - self.assertEqual(proto.BAR, - unittest_pb2.TestAllTypes.NestedEnum.Value('BAR')) - self.assertEqual(proto.BAR, - unittest_pb2.TestAllTypes.NestedEnum.BAR) - - self.assertEqual(proto.BAZ, - proto.NestedEnum.Value('BAZ')) - self.assertEqual(proto.BAZ, - proto.NestedEnum.BAZ) - - self.assertEqual(proto.BAZ, - unittest_pb2.TestAllTypes.NestedEnum.Value('BAZ')) - self.assertEqual(proto.BAZ, - unittest_pb2.TestAllTypes.NestedEnum.BAZ) - - self.assertRaises(ValueError, - proto.NestedEnum.Value, 'Foo') - with self.assertRaises(AttributeError): - proto.NestedEnum.Value.Foo - - self.assertRaises(ValueError, - unittest_pb2.TestAllTypes.NestedEnum.Value, 'Foo') - with self.assertRaises(AttributeError): - unittest_pb2.TestAllTypes.NestedEnum.Value.Foo - - def testEnum_KeysAndValues(self): - self.assertEqual(['FOREIGN_FOO', 'FOREIGN_BAR', 'FOREIGN_BAZ'], - list(unittest_pb2.ForeignEnum.keys())) - self.assertEqual([4, 5, 6], - list(unittest_pb2.ForeignEnum.values())) - self.assertEqual([('FOREIGN_FOO', 4), ('FOREIGN_BAR', 5), - ('FOREIGN_BAZ', 6)], - list(unittest_pb2.ForeignEnum.items())) - - proto = unittest_pb2.TestAllTypes() - self.assertEqual(['FOO', 'BAR', 'BAZ', 'NEG'], list(proto.NestedEnum.keys())) - self.assertEqual([1, 2, 3, -1], list(proto.NestedEnum.values())) - self.assertEqual([('FOO', 1), ('BAR', 2), ('BAZ', 3), ('NEG', -1)], - list(proto.NestedEnum.items())) - def testRepeatedScalars(self): proto = unittest_pb2.TestAllTypes() - self.assertTrue(not proto.repeated_int32) + self.assertFalse(proto.repeated_int32) self.assertEqual(0, len(proto.repeated_int32)) proto.repeated_int32.append(5) proto.repeated_int32.append(10) @@ -952,7 +1252,7 @@ # Test clearing. proto.ClearField('repeated_int32') - self.assertTrue(not proto.repeated_int32) + self.assertFalse(proto.repeated_int32) self.assertEqual(0, len(proto.repeated_int32)) proto.repeated_int32.append(1) @@ -981,7 +1281,7 @@ def testRepeatedScalarsRemove(self): proto = unittest_pb2.TestAllTypes() - self.assertTrue(not proto.repeated_int32) + self.assertFalse(proto.repeated_int32) self.assertEqual(0, len(proto.repeated_int32)) proto.repeated_int32.append(5) proto.repeated_int32.append(10) @@ -1009,7 +1309,7 @@ def testRepeatedComposites(self): proto = unittest_pb2.TestAllTypes() - self.assertTrue(not proto.repeated_nested_message) + self.assertFalse(proto.repeated_nested_message) self.assertEqual(0, len(proto.repeated_nested_message)) m0 = proto.repeated_nested_message.add() m1 = proto.repeated_nested_message.add() @@ -1079,7 +1379,7 @@ # Test clearing. proto.ClearField('repeated_nested_message') - self.assertTrue(not proto.repeated_nested_message) + self.assertFalse(proto.repeated_nested_message) self.assertEqual(0, len(proto.repeated_nested_message)) # Test constructing an element while adding it. @@ -1143,7 +1443,7 @@ DESCRIPTOR = mydescriptor myproto_instance = MyProtoClass() self.assertEqual(0, myproto_instance.foo_field) - self.assertTrue(not myproto_instance.HasField('foo_field')) + self.assertFalse(myproto_instance.HasField('foo_field')) myproto_instance.foo_field = 23 self.assertEqual(23, myproto_instance.foo_field) self.assertTrue(myproto_instance.HasField('foo_field')) @@ -1200,7 +1500,7 @@ serialized_prius = prius.SerializeToString() new_prius = reflection.ParseMessage(desc, serialized_prius) - self.assertTrue(new_prius is not prius) + self.assertIsNot(new_prius, prius) self.assertEqual(prius, new_prius) # these are unnecessary assuming message equality works as advertised but @@ -1272,12 +1572,12 @@ def testTopLevelExtensionsForOptionalScalar(self): extendee_proto = unittest_pb2.TestAllExtensions() extension = unittest_pb2.optional_int32_extension - self.assertTrue(not extendee_proto.HasExtension(extension)) + self.assertFalse(extendee_proto.HasExtension(extension)) self.assertNotIn(extension, extendee_proto.Extensions) self.assertEqual(0, extendee_proto.Extensions[extension]) # As with normal scalar fields, just doing a read doesn't actually set the # "has" bit. - self.assertTrue(not extendee_proto.HasExtension(extension)) + self.assertFalse(extendee_proto.HasExtension(extension)) self.assertNotIn(extension, extendee_proto.Extensions) # Actually set the thing. extendee_proto.Extensions[extension] = 23 @@ -1287,7 +1587,7 @@ # Ensure that clearing works as well. extendee_proto.ClearExtension(extension) self.assertEqual(0, extendee_proto.Extensions[extension]) - self.assertTrue(not extendee_proto.HasExtension(extension)) + self.assertFalse(extendee_proto.HasExtension(extension)) self.assertNotIn(extension, extendee_proto.Extensions) def testTopLevelExtensionsForRepeatedScalar(self): @@ -1302,7 +1602,7 @@ extendee_proto.ClearExtension(extension) self.assertEqual(0, len(extendee_proto.Extensions[extension])) self.assertNotIn(extension, extendee_proto.Extensions) - self.assertTrue(string_list is not extendee_proto.Extensions[extension]) + self.assertIsNot(string_list, extendee_proto.Extensions[extension]) # Shouldn't be allowed to do Extensions[extension] = 'a' self.assertRaises(TypeError, operator.setitem, extendee_proto.Extensions, extension, 'a') @@ -1310,12 +1610,12 @@ def testTopLevelExtensionsForOptionalMessage(self): extendee_proto = unittest_pb2.TestAllExtensions() extension = unittest_pb2.optional_foreign_message_extension - self.assertTrue(not extendee_proto.HasExtension(extension)) + self.assertFalse(extendee_proto.HasExtension(extension)) self.assertNotIn(extension, extendee_proto.Extensions) self.assertEqual(0, extendee_proto.Extensions[extension].c) # As with normal (non-extension) fields, merely reading from the # thing shouldn't set the "has" bit. - self.assertTrue(not extendee_proto.HasExtension(extension)) + self.assertFalse(extendee_proto.HasExtension(extension)) self.assertNotIn(extension, extendee_proto.Extensions) extendee_proto.Extensions[extension].c = 23 self.assertEqual(23, extendee_proto.Extensions[extension].c) @@ -1324,13 +1624,13 @@ # Save a reference here. foreign_message = extendee_proto.Extensions[extension] extendee_proto.ClearExtension(extension) - self.assertTrue(foreign_message is not extendee_proto.Extensions[extension]) + self.assertIsNot(foreign_message, extendee_proto.Extensions[extension]) # Setting a field on foreign_message now shouldn't set # any "has" bits on extendee_proto. foreign_message.c = 42 self.assertEqual(42, foreign_message.c) self.assertTrue(foreign_message.HasField('c')) - self.assertTrue(not extendee_proto.HasExtension(extension)) + self.assertFalse(extendee_proto.HasExtension(extension)) self.assertNotIn(extension, extendee_proto.Extensions) # Shouldn't be allowed to do Extensions[extension] = 'a' self.assertRaises(TypeError, operator.setitem, extendee_proto.Extensions, @@ -1348,7 +1648,7 @@ group_list = extendee_proto.Extensions[extension] extendee_proto.ClearExtension(extension) self.assertEqual(0, len(extendee_proto.Extensions[extension])) - self.assertTrue(group_list is not extendee_proto.Extensions[extension]) + self.assertIsNot(group_list, extendee_proto.Extensions[extension]) # Shouldn't be allowed to do Extensions[extension] = 'a' self.assertRaises(TypeError, operator.setitem, extendee_proto.Extensions, extension, 'a') @@ -1358,19 +1658,19 @@ extension = unittest_pb2.TestRequired.single # We just test the non-repeated case. - self.assertTrue(not extendee_proto.HasExtension(extension)) + self.assertFalse(extendee_proto.HasExtension(extension)) self.assertNotIn(extension, extendee_proto.Extensions) required = extendee_proto.Extensions[extension] self.assertEqual(0, required.a) - self.assertTrue(not extendee_proto.HasExtension(extension)) + self.assertFalse(extendee_proto.HasExtension(extension)) self.assertNotIn(extension, extendee_proto.Extensions) required.a = 23 self.assertEqual(23, extendee_proto.Extensions[extension].a) self.assertTrue(extendee_proto.HasExtension(extension)) self.assertIn(extension, extendee_proto.Extensions) extendee_proto.ClearExtension(extension) - self.assertTrue(required is not extendee_proto.Extensions[extension]) - self.assertTrue(not extendee_proto.HasExtension(extension)) + self.assertIsNot(required, extendee_proto.Extensions[extension]) + self.assertFalse(extendee_proto.HasExtension(extension)) self.assertNotIn(extension, extendee_proto.Extensions) def testRegisteredExtensions(self): @@ -1394,10 +1694,10 @@ def testHasBitsForAncestorsOfExtendedMessage(self): # Optional scalar extension. toplevel = more_extensions_pb2.TopLevelMessage() - self.assertTrue(not toplevel.HasField('submessage')) + self.assertFalse(toplevel.HasField('submessage')) self.assertEqual(0, toplevel.submessage.Extensions[ more_extensions_pb2.optional_int_extension]) - self.assertTrue(not toplevel.HasField('submessage')) + self.assertFalse(toplevel.HasField('submessage')) toplevel.submessage.Extensions[ more_extensions_pb2.optional_int_extension] = 23 self.assertEqual(23, toplevel.submessage.Extensions[ @@ -1406,10 +1706,10 @@ # Repeated scalar extension. toplevel = more_extensions_pb2.TopLevelMessage() - self.assertTrue(not toplevel.HasField('submessage')) + self.assertFalse(toplevel.HasField('submessage')) self.assertEqual([], toplevel.submessage.Extensions[ more_extensions_pb2.repeated_int_extension]) - self.assertTrue(not toplevel.HasField('submessage')) + self.assertFalse(toplevel.HasField('submessage')) toplevel.submessage.Extensions[ more_extensions_pb2.repeated_int_extension].append(23) self.assertEqual([23], toplevel.submessage.Extensions[ @@ -1418,10 +1718,10 @@ # Optional message extension. toplevel = more_extensions_pb2.TopLevelMessage() - self.assertTrue(not toplevel.HasField('submessage')) + self.assertFalse(toplevel.HasField('submessage')) self.assertEqual(0, toplevel.submessage.Extensions[ more_extensions_pb2.optional_message_extension].foreign_message_int) - self.assertTrue(not toplevel.HasField('submessage')) + self.assertFalse(toplevel.HasField('submessage')) toplevel.submessage.Extensions[ more_extensions_pb2.optional_message_extension].foreign_message_int = 23 self.assertEqual(23, toplevel.submessage.Extensions[ @@ -1430,10 +1730,10 @@ # Repeated message extension. toplevel = more_extensions_pb2.TopLevelMessage() - self.assertTrue(not toplevel.HasField('submessage')) + self.assertFalse(toplevel.HasField('submessage')) self.assertEqual(0, len(toplevel.submessage.Extensions[ more_extensions_pb2.repeated_message_extension])) - self.assertTrue(not toplevel.HasField('submessage')) + self.assertFalse(toplevel.HasField('submessage')) foreign = toplevel.submessage.Extensions[ more_extensions_pb2.repeated_message_extension].add() self.assertEqual(foreign, toplevel.submessage.Extensions[ @@ -1448,7 +1748,7 @@ extendee_proto.ClearExtension(extension) extension_proto.foreign_message_int = 23 - self.assertTrue(extension_proto is not extendee_proto.Extensions[extension]) + self.assertIsNot(extension_proto, extendee_proto.Extensions[extension]) def testExtensionFailureModes(self): extendee_proto = unittest_pb2.TestAllExtensions() @@ -1481,43 +1781,6 @@ self.assertRaises(KeyError, extendee_proto.HasExtension, unittest_pb2.repeated_string_extension) - def testStaticParseFrom(self): - proto1 = unittest_pb2.TestAllTypes() - test_util.SetAllFields(proto1) - - string1 = proto1.SerializeToString() - proto2 = unittest_pb2.TestAllTypes.FromString(string1) - - # Messages should be equal. - self.assertEqual(proto2, proto1) - - def testMergeFromSingularField(self): - # Test merge with just a singular field. - proto1 = unittest_pb2.TestAllTypes() - proto1.optional_int32 = 1 - - proto2 = unittest_pb2.TestAllTypes() - # This shouldn't get overwritten. - proto2.optional_string = 'value' - - proto2.MergeFrom(proto1) - self.assertEqual(1, proto2.optional_int32) - self.assertEqual('value', proto2.optional_string) - - def testMergeFromRepeatedField(self): - # Test merge with just a repeated field. - proto1 = unittest_pb2.TestAllTypes() - proto1.repeated_int32.append(1) - proto1.repeated_int32.append(2) - - proto2 = unittest_pb2.TestAllTypes() - proto2.repeated_int32.append(0) - proto2.MergeFrom(proto1) - - self.assertEqual(0, proto2.repeated_int32[0]) - self.assertEqual(1, proto2.repeated_int32[1]) - self.assertEqual(2, proto2.repeated_int32[2]) - def testMergeFromOptionalGroup(self): # Test merge with an optional group. proto1 = unittest_pb2.TestAllTypes() @@ -1526,43 +1789,6 @@ proto2.MergeFrom(proto1) self.assertEqual(12, proto2.optionalgroup.a) - def testMergeFromRepeatedNestedMessage(self): - # Test merge with a repeated nested message. - proto1 = unittest_pb2.TestAllTypes() - m = proto1.repeated_nested_message.add() - m.bb = 123 - m = proto1.repeated_nested_message.add() - m.bb = 321 - - proto2 = unittest_pb2.TestAllTypes() - m = proto2.repeated_nested_message.add() - m.bb = 999 - proto2.MergeFrom(proto1) - self.assertEqual(999, proto2.repeated_nested_message[0].bb) - self.assertEqual(123, proto2.repeated_nested_message[1].bb) - self.assertEqual(321, proto2.repeated_nested_message[2].bb) - - proto3 = unittest_pb2.TestAllTypes() - proto3.repeated_nested_message.MergeFrom(proto2.repeated_nested_message) - self.assertEqual(999, proto3.repeated_nested_message[0].bb) - self.assertEqual(123, proto3.repeated_nested_message[1].bb) - self.assertEqual(321, proto3.repeated_nested_message[2].bb) - - def testMergeFromAllFields(self): - # With all fields set. - proto1 = unittest_pb2.TestAllTypes() - test_util.SetAllFields(proto1) - proto2 = unittest_pb2.TestAllTypes() - proto2.MergeFrom(proto1) - - # Messages should be equal. - self.assertEqual(proto2, proto1) - - # Serialized string should be equal too. - string1 = proto1.SerializeToString() - string2 = proto2.SerializeToString() - self.assertEqual(string1, string2) - def testMergeFromExtensionsSingular(self): proto1 = unittest_pb2.TestAllExtensions() proto1.Extensions[unittest_pb2.optional_int32_extension] = 1 @@ -1612,71 +1838,6 @@ self.assertEqual(222, ext2[1].bb) self.assertEqual(333, ext2[2].bb) - def testMergeFromBug(self): - message1 = unittest_pb2.TestAllTypes() - message2 = unittest_pb2.TestAllTypes() - - # Cause optional_nested_message to be instantiated within message1, even - # though it is not considered to be "present". - message1.optional_nested_message - self.assertFalse(message1.HasField('optional_nested_message')) - - # Merge into message2. This should not instantiate the field is message2. - message2.MergeFrom(message1) - self.assertFalse(message2.HasField('optional_nested_message')) - - def testCopyFromSingularField(self): - # Test copy with just a singular field. - proto1 = unittest_pb2.TestAllTypes() - proto1.optional_int32 = 1 - proto1.optional_string = 'important-text' - - proto2 = unittest_pb2.TestAllTypes() - proto2.optional_string = 'value' - - proto2.CopyFrom(proto1) - self.assertEqual(1, proto2.optional_int32) - self.assertEqual('important-text', proto2.optional_string) - - def testCopyFromRepeatedField(self): - # Test copy with a repeated field. - proto1 = unittest_pb2.TestAllTypes() - proto1.repeated_int32.append(1) - proto1.repeated_int32.append(2) - - proto2 = unittest_pb2.TestAllTypes() - proto2.repeated_int32.append(0) - proto2.CopyFrom(proto1) - - self.assertEqual(1, proto2.repeated_int32[0]) - self.assertEqual(2, proto2.repeated_int32[1]) - - def testCopyFromAllFields(self): - # With all fields set. - proto1 = unittest_pb2.TestAllTypes() - test_util.SetAllFields(proto1) - proto2 = unittest_pb2.TestAllTypes() - proto2.CopyFrom(proto1) - - # Messages should be equal. - self.assertEqual(proto2, proto1) - - # Serialized string should be equal too. - string1 = proto1.SerializeToString() - string2 = proto2.SerializeToString() - self.assertEqual(string1, string2) - - def testCopyFromSelf(self): - proto1 = unittest_pb2.TestAllTypes() - proto1.repeated_int32.append(1) - proto1.optional_int32 = 2 - proto1.optional_string = 'important-text' - - proto1.CopyFrom(proto1) - self.assertEqual(1, proto1.repeated_int32[0]) - self.assertEqual(2, proto1.optional_int32) - self.assertEqual('important-text', proto1.optional_string) - def testCopyFromBadType(self): # The python implementation doesn't raise an exception in this # case. In theory it should. @@ -1686,30 +1847,6 @@ proto2 = unittest_pb2.TestAllExtensions() self.assertRaises(TypeError, proto1.CopyFrom, proto2) - def testDeepCopy(self): - proto1 = unittest_pb2.TestAllTypes() - proto1.optional_int32 = 1 - proto2 = copy.deepcopy(proto1) - self.assertEqual(1, proto2.optional_int32) - - proto1.repeated_int32.append(2) - proto1.repeated_int32.append(3) - container = copy.deepcopy(proto1.repeated_int32) - self.assertEqual([2, 3], container) - container.remove(container[0]) - self.assertEqual([3], container) - - message1 = proto1.repeated_nested_message.add() - message1.bb = 1 - messages = copy.deepcopy(proto1.repeated_nested_message) - self.assertEqual(proto1.repeated_nested_message, messages) - message1.bb = 2 - self.assertNotEqual(proto1.repeated_nested_message, messages) - messages.remove(messages[0]) - self.assertEqual(len(messages), 0) - - # TODO(anuraag): Implement deepcopy for extension dict - def testClear(self): proto = unittest_pb2.TestAllTypes() # C++ implementation does not support lazy fields right now so leave it @@ -1733,33 +1870,6 @@ empty_proto = unittest_pb2.TestAllExtensions() self.assertEqual(proto, empty_proto) - def testDisconnectingBeforeClear(self): - proto = unittest_pb2.TestAllTypes() - nested = proto.optional_nested_message - proto.Clear() - self.assertTrue(nested is not proto.optional_nested_message) - nested.bb = 23 - self.assertTrue(not proto.HasField('optional_nested_message')) - self.assertEqual(0, proto.optional_nested_message.bb) - - proto = unittest_pb2.TestAllTypes() - nested = proto.optional_nested_message - nested.bb = 5 - foreign = proto.optional_foreign_message - foreign.c = 6 - - proto.Clear() - self.assertTrue(nested is not proto.optional_nested_message) - self.assertTrue(foreign is not proto.optional_foreign_message) - self.assertEqual(5, nested.bb) - self.assertEqual(6, foreign.c) - nested.bb = 15 - foreign.c = 16 - self.assertFalse(proto.HasField('optional_nested_message')) - self.assertEqual(0, proto.optional_nested_message.bb) - self.assertFalse(proto.HasField('optional_foreign_message')) - self.assertEqual(0, proto.optional_foreign_message.c) - def testDisconnectingInOneof(self): m = unittest_pb2.TestOneof2() # This message has two messages in a oneof. m.foo_message.qux_int = 5 @@ -1774,18 +1884,6 @@ self.assertEqual(sub_message.qux_int, 5) sub_message.qux_int = 7 - def testOneOf(self): - proto = unittest_pb2.TestAllTypes() - proto.oneof_uint32 = 10 - proto.oneof_nested_message.bb = 11 - self.assertEqual(11, proto.oneof_nested_message.bb) - self.assertFalse(proto.HasField('oneof_uint32')) - nested = proto.oneof_nested_message - proto.oneof_string = 'abc' - self.assertEqual('abc', proto.oneof_string) - self.assertEqual(11, nested.bb) - self.assertFalse(proto.HasField('oneof_nested_message')) - def assertInitialized(self, proto): self.assertTrue(proto.IsInitialized()) # Neither method should raise an exception. @@ -1894,34 +1992,6 @@ # dependency on the C++ logging code. self.assertIn('test_file_descriptor_errors.msg1', str(cm.exception)) - def testStringUTF8Encoding(self): - proto = unittest_pb2.TestAllTypes() - - # Assignment of a unicode object to a field of type 'bytes' is not allowed. - self.assertRaises(TypeError, - setattr, proto, 'optional_bytes', u'unicode object') - - # Check that the default value is of python's 'unicode' type. - self.assertEqual(type(proto.optional_string), six.text_type) - - proto.optional_string = six.text_type('Testing') - self.assertEqual(proto.optional_string, str('Testing')) - - # Assign a value of type 'str' which can be encoded in UTF-8. - proto.optional_string = str('Testing') - self.assertEqual(proto.optional_string, six.text_type('Testing')) - - # Try to assign a 'bytes' object which contains non-UTF-8. - self.assertRaises(ValueError, - setattr, proto, 'optional_string', b'a\x80a') - # No exception: Assign already encoded UTF-8 bytes to a string field. - utf8_bytes = u'Тест'.encode('utf-8') - proto.optional_string = utf8_bytes - # No exception: Assign the a non-ascii unicode object. - proto.optional_string = u'Тест' - # No exception thrown (normal str assignment containing ASCII). - proto.optional_string = 'abc' - def testStringUTF8Serialization(self): proto = message_set_extensions_pb2.TestMessageSet() extension_message = message_set_extensions_pb2.TestMessageSetExtension2 @@ -1976,38 +2046,6 @@ string_field = message2.str self.assertTrue(unicode_decode_failed or type(string_field) is bytes) - def testBytesInTextFormat(self): - proto = unittest_pb2.TestAllTypes(optional_bytes=b'\x00\x7f\x80\xff') - self.assertEqual(u'optional_bytes: "\\000\\177\\200\\377"\n', - six.text_type(proto)) - - def testEmptyNestedMessage(self): - proto = unittest_pb2.TestAllTypes() - proto.optional_nested_message.MergeFrom( - unittest_pb2.TestAllTypes.NestedMessage()) - self.assertTrue(proto.HasField('optional_nested_message')) - - proto = unittest_pb2.TestAllTypes() - proto.optional_nested_message.CopyFrom( - unittest_pb2.TestAllTypes.NestedMessage()) - self.assertTrue(proto.HasField('optional_nested_message')) - - proto = unittest_pb2.TestAllTypes() - bytes_read = proto.optional_nested_message.MergeFromString(b'') - self.assertEqual(0, bytes_read) - self.assertTrue(proto.HasField('optional_nested_message')) - - proto = unittest_pb2.TestAllTypes() - proto.optional_nested_message.ParseFromString(b'') - self.assertTrue(proto.HasField('optional_nested_message')) - - serialized = proto.SerializeToString() - proto2 = unittest_pb2.TestAllTypes() - self.assertEqual( - len(serialized), - proto2.MergeFromString(serialized)) - self.assertTrue(proto2.HasField('optional_nested_message')) - def testSetInParent(self): proto = unittest_pb2.TestAllTypes() self.assertFalse(proto.HasField('optionalgroup')) @@ -3065,7 +3103,7 @@ self.assertTrue(proto.HasField('a')) self.assertTrue(proto.HasField('b')) self.assertTrue(proto.HasField('c')) - self.assertTrue(not proto.HasField('dummy2')) + self.assertFalse(proto.HasField('dummy2')) self.assertEqual(1, proto.a) self.assertEqual(1, proto.b) self.assertEqual(1, proto.c) @@ -3079,7 +3117,7 @@ self.assertTrue(proto.optional_message.HasField('a')) self.assertTrue(proto.optional_message.HasField('b')) self.assertTrue(proto.optional_message.HasField('c')) - self.assertTrue(not proto.optional_message.HasField('dummy2')) + self.assertFalse(proto.optional_message.HasField('dummy2')) self.assertEqual(unittest_pb2.TestRequired(a=1, b=1, c=1), proto.optional_message) self.assertEqual(1, proto.optional_message.a) @@ -3267,3 +3305,4 @@ if __name__ == '__main__': unittest.main() +
diff --git a/python/google/protobuf/internal/text_format_test.py b/python/google/protobuf/internal/text_format_test.py index 504af13..aa6f97b 100755 --- a/python/google/protobuf/internal/text_format_test.py +++ b/python/google/protobuf/internal/text_format_test.py
@@ -817,11 +817,19 @@ r'have multiple "optional_int32" fields.'), text_format.Parse, text, message) + def testParseExistingScalarInMessage(self, message_module): + message = message_module.TestAllTypes(optional_int32=42) + text = 'optional_int32: 67' + six.assertRaisesRegex(self, text_format.ParseError, + (r'Message type "\w+.TestAllTypes" should not ' + r'have multiple "optional_int32" fields.'), + text_format.Parse, text, message) + @_parameterized.parameters(unittest_pb2, unittest_proto3_arena_pb2) class TextFormatMergeTests(TextFormatBase): - def testMergeDuplicateScalars(self, message_module): + def testMergeDuplicateScalarsInText(self, message_module): message = message_module.TestAllTypes() text = ('optional_int32: 42 ' 'optional_int32: 67') r = text_format.Merge(text, message) @@ -836,6 +844,22 @@ self.assertTrue(r is message) self.assertEqual(2, message.optional_nested_message.bb) + def testReplaceScalarInMessage(self, message_module): + message = message_module.TestAllTypes(optional_int32=42) + text = 'optional_int32: 67' + r = text_format.Merge(text, message) + self.assertIs(r, message) + self.assertEqual(67, message.optional_int32) + + def testReplaceMessageInMessage(self, message_module): + message = message_module.TestAllTypes( + optional_int32=42, optional_nested_message=dict()) + self.assertTrue(message.HasField('optional_nested_message')) + text = 'optional_nested_message{ bb: 3 }' + r = text_format.Merge(text, message) + self.assertIs(r, message) + self.assertEqual(3, message.optional_nested_message.bb) + def testMergeMultipleOneof(self, message_module): m_string = '\n'.join(['oneof_uint32: 11', 'oneof_string: "foo"']) m2 = message_module.TestAllTypes()
diff --git a/python/google/protobuf/json_format.py b/python/google/protobuf/json_format.py index 6c3b1cb..a11874d 100644 --- a/python/google/protobuf/json_format.py +++ b/python/google/protobuf/json_format.py
@@ -103,7 +103,8 @@ indent=2, sort_keys=False, use_integers_for_enums=False, - descriptor_pool=None): + descriptor_pool=None, + float_precision=None): """Converts protobuf message to JSON format. Args: @@ -121,6 +122,7 @@ use_integers_for_enums: If true, print integers instead of enum names. descriptor_pool: A Descriptor Pool for resolving types. If None use the default. + float_precision: If set, use this to specify float field valid digits. Returns: A string containing the JSON formatted protocol buffer message. @@ -129,7 +131,8 @@ including_default_value_fields, preserving_proto_field_name, use_integers_for_enums, - descriptor_pool) + descriptor_pool, + float_precision=float_precision) return printer.ToJsonString(message, indent, sort_keys) @@ -138,7 +141,8 @@ including_default_value_fields=False, preserving_proto_field_name=False, use_integers_for_enums=False, - descriptor_pool=None): + descriptor_pool=None, + float_precision=None): """Converts protobuf message to a dictionary. When the dictionary is encoded to JSON, it conforms to proto3 JSON spec. @@ -155,6 +159,7 @@ use_integers_for_enums: If true, print integers instead of enum names. descriptor_pool: A Descriptor Pool for resolving types. If None use the default. + float_precision: If set, use this to specify float field valid digits. Returns: A dict representation of the protocol buffer message. @@ -163,7 +168,8 @@ including_default_value_fields, preserving_proto_field_name, use_integers_for_enums, - descriptor_pool) + descriptor_pool, + float_precision=float_precision) # pylint: disable=protected-access return printer._MessageToJsonObject(message) @@ -182,11 +188,17 @@ including_default_value_fields=False, preserving_proto_field_name=False, use_integers_for_enums=False, - descriptor_pool=None): + descriptor_pool=None, + float_precision=None): self.including_default_value_fields = including_default_value_fields self.preserving_proto_field_name = preserving_proto_field_name self.use_integers_for_enums = use_integers_for_enums self.descriptor_pool = descriptor_pool + # TODO(jieluo): change the float precision default to 8 valid digits. + if float_precision: + self.float_format = '.{}g'.format(float_precision) + else: + self.float_format = None def ToJsonString(self, message, indent, sort_keys): js = self._MessageToJsonObject(message) @@ -301,6 +313,9 @@ return _INFINITY if math.isnan(value): return _NAN + if (self.float_format and + field.cpp_type == descriptor.FieldDescriptor.CPPTYPE_FLOAT): + return float(format(value, self.float_format)) return value def _AnyMessageToJsonObject(self, message):
diff --git a/python/google/protobuf/pyext/message.cc b/python/google/protobuf/pyext/message.cc index 7066cba..e3e66ae 100644 --- a/python/google/protobuf/pyext/message.cc +++ b/python/google/protobuf/pyext/message.cc
@@ -3029,10 +3029,6 @@ PyModule_AddObject(m, "DescriptorPool", reinterpret_cast<PyObject*>( &PyDescriptorPool_Type)); - // This implementation provides full Descriptor types, we advertise it so that - // descriptor.py can use them in replacement of the Python classes. - PyModule_AddIntConstant(m, "_USE_C_DESCRIPTORS", 1); - PyModule_AddObject(m, "Descriptor", reinterpret_cast<PyObject*>( &PyMessageDescriptor_Type)); PyModule_AddObject(m, "FieldDescriptor", reinterpret_cast<PyObject*>(
diff --git a/python/google/protobuf/text_format.py b/python/google/protobuf/text_format.py index ecdfd5a..a85184e 100755 --- a/python/google/protobuf/text_format.py +++ b/python/google/protobuf/text_format.py
@@ -617,15 +617,23 @@ NOTE: for historical reasons this function does not clear the input message. This is different from what the binary msg.ParseFrom(...) does. + If text contains a field already set in message, the value is appended if the + field is repeated. Otherwise, an error is raised. Example a = MyProto() a.repeated_field.append('test') b = MyProto() + # Repeated fields are combined text_format.Parse(repr(a), b) text_format.Parse(repr(a), b) # repeated_field contains ["test", "test"] + # Non-repeated fields cannot be overwritten + a.singular_field = 1 + b.singular_field = 2 + text_format.Parse(repr(a), b) # ParseError + # Binary version: b.ParseFromString(a.SerializeToString()) # repeated_field is now "test" @@ -665,7 +673,8 @@ """Parses a text representation of a protocol message into a message. Like Parse(), but allows repeated values for a non-repeated field, and uses - the last one. + the last one. This means any non-repeated, top-level fields specified in text + replace those in the message. Args: text: Message text representation. @@ -701,6 +710,8 @@ allow_unknown_field=False): """Parses a text representation of a protocol message into a message. + See Parse() for caveats. + Args: lines: An iterable of lines of a message's text representation. message: A protocol buffer message to merge into. @@ -733,8 +744,7 @@ allow_unknown_field=False): """Parses a text representation of a protocol message into a message. - Like ParseLines(), but allows repeated values for a non-repeated field, and - uses the last one. + See Merge() for more details. Args: lines: An iterable of lines of a message's text representation.
diff --git a/src/Makefile.am b/src/Makefile.am index a5bd9ce..60bb445 100644 --- a/src/Makefile.am +++ b/src/Makefile.am
@@ -228,8 +228,6 @@ $(libprotobuf_lite_la_SOURCES) \ google/protobuf/any.pb.cc \ google/protobuf/api.pb.cc \ - google/protobuf/stubs/mathlimits.cc \ - google/protobuf/stubs/mathlimits.h \ google/protobuf/any.cc \ google/protobuf/descriptor.cc \ google/protobuf/descriptor_database.cc \
diff --git a/src/google/protobuf/any.pb.cc b/src/google/protobuf/any.pb.cc index 3ccd921..5a79335 100644 --- a/src/google/protobuf/any.pb.cc +++ b/src/google/protobuf/any.pb.cc
@@ -169,14 +169,17 @@ // string type_url = 1; case 1: if (PROTOBUF_PREDICT_TRUE(static_cast<::PROTOBUF_NAMESPACE_ID::uint8>(tag) == 10)) { - ptr = ::PROTOBUF_NAMESPACE_ID::internal::InlineGreedyStringParserUTF8(_internal_mutable_type_url(), ptr, ctx, "google.protobuf.Any.type_url"); + auto str = _internal_mutable_type_url(); + ptr = ::PROTOBUF_NAMESPACE_ID::internal::InlineGreedyStringParser(str, ptr, ctx); + CHK_(::PROTOBUF_NAMESPACE_ID::internal::VerifyUTF8(str, "google.protobuf.Any.type_url")); CHK_(ptr); } else goto handle_unusual; continue; // bytes value = 2; case 2: if (PROTOBUF_PREDICT_TRUE(static_cast<::PROTOBUF_NAMESPACE_ID::uint8>(tag) == 18)) { - ptr = ::PROTOBUF_NAMESPACE_ID::internal::InlineGreedyStringParser(_internal_mutable_value(), ptr, ctx); + auto str = _internal_mutable_value(); + ptr = ::PROTOBUF_NAMESPACE_ID::internal::InlineGreedyStringParser(str, ptr, ctx); CHK_(ptr); } else goto handle_unusual; continue; @@ -200,7 +203,7 @@ #undef CHK_ } -::PROTOBUF_NAMESPACE_ID::uint8* Any::InternalSerializeWithCachedSizesToArray( +::PROTOBUF_NAMESPACE_ID::uint8* Any::_InternalSerialize( ::PROTOBUF_NAMESPACE_ID::uint8* target, ::PROTOBUF_NAMESPACE_ID::io::EpsCopyOutputStream* stream) const { // @@protoc_insertion_point(serialize_to_array_start:google.protobuf.Any) ::PROTOBUF_NAMESPACE_ID::uint32 cached_has_bits = 0;
diff --git a/src/google/protobuf/any.pb.h b/src/google/protobuf/any.pb.h index ca01b04..7ea175d 100644 --- a/src/google/protobuf/any.pb.h +++ b/src/google/protobuf/any.pb.h
@@ -32,7 +32,6 @@ #include <google/protobuf/repeated_field.h> // IWYU pragma: export #include <google/protobuf/extension_set.h> // IWYU pragma: export #include <google/protobuf/unknown_field_set.h> -#include <google/protobuf/any.h> // @@protoc_insertion_point(includes) #include <google/protobuf/port_def.inc> #define PROTOBUF_INTERNAL_EXPORT_google_2fprotobuf_2fany_2eproto PROTOBUF_EXPORT @@ -170,7 +169,7 @@ size_t ByteSizeLong() const final; const char* _InternalParse(const char* ptr, ::PROTOBUF_NAMESPACE_ID::internal::ParseContext* ctx) final; - ::PROTOBUF_NAMESPACE_ID::uint8* InternalSerializeWithCachedSizesToArray( + ::PROTOBUF_NAMESPACE_ID::uint8* _InternalSerialize( ::PROTOBUF_NAMESPACE_ID::uint8* target, ::PROTOBUF_NAMESPACE_ID::io::EpsCopyOutputStream* stream) const final; int GetCachedSize() const final { return _cached_size_.Get(); }
diff --git a/src/google/protobuf/api.pb.cc b/src/google/protobuf/api.pb.cc index 2b0175c..294c4ef 100644 --- a/src/google/protobuf/api.pb.cc +++ b/src/google/protobuf/api.pb.cc
@@ -282,7 +282,9 @@ // string name = 1; case 1: if (PROTOBUF_PREDICT_TRUE(static_cast<::PROTOBUF_NAMESPACE_ID::uint8>(tag) == 10)) { - ptr = ::PROTOBUF_NAMESPACE_ID::internal::InlineGreedyStringParserUTF8(_internal_mutable_name(), ptr, ctx, "google.protobuf.Api.name"); + auto str = _internal_mutable_name(); + ptr = ::PROTOBUF_NAMESPACE_ID::internal::InlineGreedyStringParser(str, ptr, ctx); + CHK_(::PROTOBUF_NAMESPACE_ID::internal::VerifyUTF8(str, "google.protobuf.Api.name")); CHK_(ptr); } else goto handle_unusual; continue; @@ -313,7 +315,9 @@ // string version = 4; case 4: if (PROTOBUF_PREDICT_TRUE(static_cast<::PROTOBUF_NAMESPACE_ID::uint8>(tag) == 34)) { - ptr = ::PROTOBUF_NAMESPACE_ID::internal::InlineGreedyStringParserUTF8(_internal_mutable_version(), ptr, ctx, "google.protobuf.Api.version"); + auto str = _internal_mutable_version(); + ptr = ::PROTOBUF_NAMESPACE_ID::internal::InlineGreedyStringParser(str, ptr, ctx); + CHK_(::PROTOBUF_NAMESPACE_ID::internal::VerifyUTF8(str, "google.protobuf.Api.version")); CHK_(ptr); } else goto handle_unusual; continue; @@ -364,7 +368,7 @@ #undef CHK_ } -::PROTOBUF_NAMESPACE_ID::uint8* Api::InternalSerializeWithCachedSizesToArray( +::PROTOBUF_NAMESPACE_ID::uint8* Api::_InternalSerialize( ::PROTOBUF_NAMESPACE_ID::uint8* target, ::PROTOBUF_NAMESPACE_ID::io::EpsCopyOutputStream* stream) const { // @@protoc_insertion_point(serialize_to_array_start:google.protobuf.Api) ::PROTOBUF_NAMESPACE_ID::uint32 cached_has_bits = 0; @@ -385,7 +389,7 @@ n = static_cast<unsigned int>(this->_internal_methods_size()); i < n; i++) { target = stream->EnsureSpace(target); target = ::PROTOBUF_NAMESPACE_ID::internal::WireFormatLite:: - InternalWriteMessageToArray(2, this->_internal_methods(i), target, stream); + InternalWriteMessage(2, this->_internal_methods(i), target, stream); } // repeated .google.protobuf.Option options = 3; @@ -393,7 +397,7 @@ n = static_cast<unsigned int>(this->_internal_options_size()); i < n; i++) { target = stream->EnsureSpace(target); target = ::PROTOBUF_NAMESPACE_ID::internal::WireFormatLite:: - InternalWriteMessageToArray(3, this->_internal_options(i), target, stream); + InternalWriteMessage(3, this->_internal_options(i), target, stream); } // string version = 4; @@ -410,7 +414,7 @@ if (this->has_source_context()) { target = stream->EnsureSpace(target); target = ::PROTOBUF_NAMESPACE_ID::internal::WireFormatLite:: - InternalWriteMessageToArray( + InternalWriteMessage( 5, _Internal::source_context(this), target, stream); } @@ -419,7 +423,7 @@ n = static_cast<unsigned int>(this->_internal_mixins_size()); i < n; i++) { target = stream->EnsureSpace(target); target = ::PROTOBUF_NAMESPACE_ID::internal::WireFormatLite:: - InternalWriteMessageToArray(6, this->_internal_mixins(i), target, stream); + InternalWriteMessage(6, this->_internal_mixins(i), target, stream); } // .google.protobuf.Syntax syntax = 7; @@ -675,14 +679,18 @@ // string name = 1; case 1: if (PROTOBUF_PREDICT_TRUE(static_cast<::PROTOBUF_NAMESPACE_ID::uint8>(tag) == 10)) { - ptr = ::PROTOBUF_NAMESPACE_ID::internal::InlineGreedyStringParserUTF8(_internal_mutable_name(), ptr, ctx, "google.protobuf.Method.name"); + auto str = _internal_mutable_name(); + ptr = ::PROTOBUF_NAMESPACE_ID::internal::InlineGreedyStringParser(str, ptr, ctx); + CHK_(::PROTOBUF_NAMESPACE_ID::internal::VerifyUTF8(str, "google.protobuf.Method.name")); CHK_(ptr); } else goto handle_unusual; continue; // string request_type_url = 2; case 2: if (PROTOBUF_PREDICT_TRUE(static_cast<::PROTOBUF_NAMESPACE_ID::uint8>(tag) == 18)) { - ptr = ::PROTOBUF_NAMESPACE_ID::internal::InlineGreedyStringParserUTF8(_internal_mutable_request_type_url(), ptr, ctx, "google.protobuf.Method.request_type_url"); + auto str = _internal_mutable_request_type_url(); + ptr = ::PROTOBUF_NAMESPACE_ID::internal::InlineGreedyStringParser(str, ptr, ctx); + CHK_(::PROTOBUF_NAMESPACE_ID::internal::VerifyUTF8(str, "google.protobuf.Method.request_type_url")); CHK_(ptr); } else goto handle_unusual; continue; @@ -696,7 +704,9 @@ // string response_type_url = 4; case 4: if (PROTOBUF_PREDICT_TRUE(static_cast<::PROTOBUF_NAMESPACE_ID::uint8>(tag) == 34)) { - ptr = ::PROTOBUF_NAMESPACE_ID::internal::InlineGreedyStringParserUTF8(_internal_mutable_response_type_url(), ptr, ctx, "google.protobuf.Method.response_type_url"); + auto str = _internal_mutable_response_type_url(); + ptr = ::PROTOBUF_NAMESPACE_ID::internal::InlineGreedyStringParser(str, ptr, ctx); + CHK_(::PROTOBUF_NAMESPACE_ID::internal::VerifyUTF8(str, "google.protobuf.Method.response_type_url")); CHK_(ptr); } else goto handle_unusual; continue; @@ -747,7 +757,7 @@ #undef CHK_ } -::PROTOBUF_NAMESPACE_ID::uint8* Method::InternalSerializeWithCachedSizesToArray( +::PROTOBUF_NAMESPACE_ID::uint8* Method::_InternalSerialize( ::PROTOBUF_NAMESPACE_ID::uint8* target, ::PROTOBUF_NAMESPACE_ID::io::EpsCopyOutputStream* stream) const { // @@protoc_insertion_point(serialize_to_array_start:google.protobuf.Method) ::PROTOBUF_NAMESPACE_ID::uint32 cached_has_bits = 0; @@ -800,7 +810,7 @@ n = static_cast<unsigned int>(this->_internal_options_size()); i < n; i++) { target = stream->EnsureSpace(target); target = ::PROTOBUF_NAMESPACE_ID::internal::WireFormatLite:: - InternalWriteMessageToArray(6, this->_internal_options(i), target, stream); + InternalWriteMessage(6, this->_internal_options(i), target, stream); } // .google.protobuf.Syntax syntax = 7; @@ -1037,14 +1047,18 @@ // string name = 1; case 1: if (PROTOBUF_PREDICT_TRUE(static_cast<::PROTOBUF_NAMESPACE_ID::uint8>(tag) == 10)) { - ptr = ::PROTOBUF_NAMESPACE_ID::internal::InlineGreedyStringParserUTF8(_internal_mutable_name(), ptr, ctx, "google.protobuf.Mixin.name"); + auto str = _internal_mutable_name(); + ptr = ::PROTOBUF_NAMESPACE_ID::internal::InlineGreedyStringParser(str, ptr, ctx); + CHK_(::PROTOBUF_NAMESPACE_ID::internal::VerifyUTF8(str, "google.protobuf.Mixin.name")); CHK_(ptr); } else goto handle_unusual; continue; // string root = 2; case 2: if (PROTOBUF_PREDICT_TRUE(static_cast<::PROTOBUF_NAMESPACE_ID::uint8>(tag) == 18)) { - ptr = ::PROTOBUF_NAMESPACE_ID::internal::InlineGreedyStringParserUTF8(_internal_mutable_root(), ptr, ctx, "google.protobuf.Mixin.root"); + auto str = _internal_mutable_root(); + ptr = ::PROTOBUF_NAMESPACE_ID::internal::InlineGreedyStringParser(str, ptr, ctx); + CHK_(::PROTOBUF_NAMESPACE_ID::internal::VerifyUTF8(str, "google.protobuf.Mixin.root")); CHK_(ptr); } else goto handle_unusual; continue; @@ -1068,7 +1082,7 @@ #undef CHK_ } -::PROTOBUF_NAMESPACE_ID::uint8* Mixin::InternalSerializeWithCachedSizesToArray( +::PROTOBUF_NAMESPACE_ID::uint8* Mixin::_InternalSerialize( ::PROTOBUF_NAMESPACE_ID::uint8* target, ::PROTOBUF_NAMESPACE_ID::io::EpsCopyOutputStream* stream) const { // @@protoc_insertion_point(serialize_to_array_start:google.protobuf.Mixin) ::PROTOBUF_NAMESPACE_ID::uint32 cached_has_bits = 0;
diff --git a/src/google/protobuf/api.pb.h b/src/google/protobuf/api.pb.h index af7ab8c..91bc34e 100644 --- a/src/google/protobuf/api.pb.h +++ b/src/google/protobuf/api.pb.h
@@ -146,7 +146,7 @@ size_t ByteSizeLong() const final; const char* _InternalParse(const char* ptr, ::PROTOBUF_NAMESPACE_ID::internal::ParseContext* ctx) final; - ::PROTOBUF_NAMESPACE_ID::uint8* InternalSerializeWithCachedSizesToArray( + ::PROTOBUF_NAMESPACE_ID::uint8* _InternalSerialize( ::PROTOBUF_NAMESPACE_ID::uint8* target, ::PROTOBUF_NAMESPACE_ID::io::EpsCopyOutputStream* stream) const final; int GetCachedSize() const final { return _cached_size_.Get(); } @@ -387,7 +387,7 @@ size_t ByteSizeLong() const final; const char* _InternalParse(const char* ptr, ::PROTOBUF_NAMESPACE_ID::internal::ParseContext* ctx) final; - ::PROTOBUF_NAMESPACE_ID::uint8* InternalSerializeWithCachedSizesToArray( + ::PROTOBUF_NAMESPACE_ID::uint8* _InternalSerialize( ::PROTOBUF_NAMESPACE_ID::uint8* target, ::PROTOBUF_NAMESPACE_ID::io::EpsCopyOutputStream* stream) const final; int GetCachedSize() const final { return _cached_size_.Get(); } @@ -611,7 +611,7 @@ size_t ByteSizeLong() const final; const char* _InternalParse(const char* ptr, ::PROTOBUF_NAMESPACE_ID::internal::ParseContext* ctx) final; - ::PROTOBUF_NAMESPACE_ID::uint8* InternalSerializeWithCachedSizesToArray( + ::PROTOBUF_NAMESPACE_ID::uint8* _InternalSerialize( ::PROTOBUF_NAMESPACE_ID::uint8* target, ::PROTOBUF_NAMESPACE_ID::io::EpsCopyOutputStream* stream) const final; int GetCachedSize() const final { return _cached_size_.Get(); }
diff --git a/src/google/protobuf/arena.cc b/src/google/protobuf/arena.cc index 0171c56..069dcdf 100644 --- a/src/google/protobuf/arena.cc +++ b/src/google/protobuf/arena.cc
@@ -144,16 +144,6 @@ AddCleanup(elem, cleanup); } -PROTOBUF_FUNC_ALIGN(32) -void* ArenaImpl::AllocateAligned(size_t n) { - SerialArena* arena; - if (PROTOBUF_PREDICT_TRUE(GetSerialArenaFast(&arena))) { - return arena->AllocateAligned(n); - } else { - return AllocateAlignedFallback(n); - } -} - void* ArenaImpl::AllocateAlignedAndAddCleanup(size_t n, void (*cleanup)(void*)) { SerialArena* arena; @@ -189,28 +179,6 @@ GetSerialArena()->AddCleanup(elem, cleanup); } -inline PROTOBUF_ALWAYS_INLINE bool ArenaImpl::GetSerialArenaFast( - ArenaImpl::SerialArena** arena) { - // If this thread already owns a block in this arena then try to use that. - // This fast path optimizes the case where multiple threads allocate from the - // same arena. - ThreadCache* tc = &thread_cache(); - if (PROTOBUF_PREDICT_TRUE(tc->last_lifecycle_id_seen == lifecycle_id_)) { - *arena = tc->last_serial_arena; - return true; - } - - // Check whether we own the last accessed SerialArena on this arena. This - // fast path optimizes the case where a single thread uses multiple arenas. - SerialArena* serial = hint_.load(std::memory_order_acquire); - if (PROTOBUF_PREDICT_TRUE(serial != NULL && serial->owner() == tc)) { - *arena = serial; - return true; - } - - return false; -} - ArenaImpl::SerialArena* ArenaImpl::GetSerialArena() { SerialArena* arena; if (PROTOBUF_PREDICT_TRUE(GetSerialArenaFast(&arena))) { @@ -391,6 +359,11 @@ } // namespace internal +PROTOBUF_FUNC_ALIGN(32) +void* Arena::AllocateAlignedNoHook(size_t n) { + return impl_.AllocateAligned(n); +} + void Arena::CallDestructorHooks() { uint64 space_allocated = impl_.SpaceAllocated(); // Call the reset hook
diff --git a/src/google/protobuf/arena.h b/src/google/protobuf/arena.h index 736b4e4..d73b53c 100644 --- a/src/google/protobuf/arena.h +++ b/src/google/protobuf/arena.h
@@ -88,6 +88,7 @@ struct ArenaStringPtr; // defined in arenastring.h class LazyField; // defined in lazy_field.h +class EpsCopyInputStream; // defined in parse_context.h template <typename Type> class GenericTypeHandler; // defined in repeated_field.h @@ -535,7 +536,7 @@ AllocHook(RTTI_TYPE_ID(T), n); // Monitor allocation if needed. if (skip_explicit_ownership) { - return impl_.AllocateAligned(n); + return AllocateAlignedNoHook(n); } else { return impl_.AllocateAlignedAndAddCleanup( n, &internal::arena_destruct_object<T>); @@ -596,7 +597,7 @@ const size_t n = internal::AlignUpTo8(sizeof(T) * num_elements); // Monitor allocation if needed. AllocHook(RTTI_TYPE_ID(T), n); - return static_cast<T*>(impl_.AllocateAligned(n)); + return static_cast<T*>(AllocateAlignedNoHook(n)); } template <typename T, typename... Args> @@ -689,9 +690,11 @@ // For friends of arena. void* AllocateAligned(size_t n) { AllocHook(NULL, n); - return impl_.AllocateAligned(internal::AlignUpTo8(n)); + return AllocateAlignedNoHook(internal::AlignUpTo8(n)); } + void* AllocateAlignedNoHook(size_t n); + internal::ArenaImpl impl_; void (*on_arena_allocation_)(const std::type_info* allocated_type, @@ -707,6 +710,7 @@ friend class internal::GenericTypeHandler; friend struct internal::ArenaStringPtr; // For AllocateAligned. friend class internal::LazyField; // For CreateMaybeMessage. + friend class internal::EpsCopyInputStream; // For parser performance friend class MessageLite; template <typename Key, typename T> friend class Map;
diff --git a/src/google/protobuf/arena_impl.h b/src/google/protobuf/arena_impl.h index 0beec17..d7b7ed7 100644 --- a/src/google/protobuf/arena_impl.h +++ b/src/google/protobuf/arena_impl.h
@@ -107,7 +107,27 @@ uint64 SpaceAllocated() const; uint64 SpaceUsed() const; - void* AllocateAligned(size_t n); + void* AllocateAligned(size_t n) { + SerialArena* arena; + if (PROTOBUF_PREDICT_TRUE(GetSerialArenaFast(&arena))) { + return arena->AllocateAligned(n); + } else { + return AllocateAlignedFallback(n); + } + } + + // This function allocates n bytes if the common happy case is true and + // returns true. Otherwise does nothing and returns false. This strange + // semantics is necessary to allow callers to program functions that only + // have fallback function calls in tail position. This substantially improves + // code for the happy path. + PROTOBUF_ALWAYS_INLINE bool MaybeAllocateAligned(size_t n, void** out) { + SerialArena* a; + if (PROTOBUF_PREDICT_TRUE(GetSerialArenaFromThreadCache(&a))) { + return a->MaybeAllocateAligned(n, out); + } + return false; + } void* AllocateAlignedAndAddCleanup(size_t n, void (*cleanup)(void*)); @@ -156,10 +176,12 @@ void CleanupList(); uint64 SpaceUsed() const; + bool HasSpace(size_t n) { return n <= static_cast<size_t>(limit_ - ptr_); } + void* AllocateAligned(size_t n) { GOOGLE_DCHECK_EQ(internal::AlignUpTo8(n), n); // Must be already aligned. GOOGLE_DCHECK_GE(limit_, ptr_); - if (PROTOBUF_PREDICT_FALSE(static_cast<size_t>(limit_ - ptr_) < n)) { + if (PROTOBUF_PREDICT_FALSE(!HasSpace(n))) { return AllocateAlignedFallback(n); } void* ret = ptr_; @@ -170,6 +192,20 @@ return ret; } + // Allocate space if the current region provides enough space. + bool MaybeAllocateAligned(size_t n, void** out) { + GOOGLE_DCHECK_EQ(internal::AlignUpTo8(n), n); // Must be already aligned. + GOOGLE_DCHECK_GE(limit_, ptr_); + if (PROTOBUF_PREDICT_FALSE(!HasSpace(n))) return false; + void* ret = ptr_; + ptr_ += n; +#ifdef ADDRESS_SANITIZER + ASAN_UNPOISON_MEMORY_REGION(ret, n); +#endif // ADDRESS_SANITIZER + *out = ret; + return true; + } + void AddCleanup(void* elem, void (*cleanup)(void*)) { if (PROTOBUF_PREDICT_FALSE(cleanup_ptr_ == cleanup_limit_)) { AddCleanupFallback(elem, cleanup); @@ -292,7 +328,32 @@ Block* NewBlock(Block* last_block, size_t min_bytes); SerialArena* GetSerialArena(); - bool GetSerialArenaFast(SerialArena** arena); + PROTOBUF_ALWAYS_INLINE bool GetSerialArenaFast(SerialArena** arena) { + if (GetSerialArenaFromThreadCache(arena)) return true; + + // Check whether we own the last accessed SerialArena on this arena. This + // fast path optimizes the case where a single thread uses multiple arenas. + ThreadCache* tc = &thread_cache(); + SerialArena* serial = hint_.load(std::memory_order_acquire); + if (PROTOBUF_PREDICT_TRUE(serial != NULL && serial->owner() == tc)) { + *arena = serial; + return true; + } + return false; + } + + PROTOBUF_ALWAYS_INLINE bool GetSerialArenaFromThreadCache( + SerialArena** arena) { + // If this thread already owns a block in this arena then try to use that. + // This fast path optimizes the case where multiple threads allocate from + // the same arena. + ThreadCache* tc = &thread_cache(); + if (PROTOBUF_PREDICT_TRUE(tc->last_lifecycle_id_seen == lifecycle_id_)) { + *arena = tc->last_serial_arena; + return true; + } + return false; + } SerialArena* GetSerialArenaFallback(void* me); LifecycleId lifecycle_id_; // Unique for each arena. Changes on Reset().
diff --git a/src/google/protobuf/arenastring.h b/src/google/protobuf/arenastring.h index 99e26b8..122f391 100644 --- a/src/google/protobuf/arenastring.h +++ b/src/google/protobuf/arenastring.h
@@ -32,6 +32,7 @@ #define GOOGLE_PROTOBUF_ARENASTRING_H__ #include <string> +#include <type_traits> #include <utility> #include <google/protobuf/stubs/logging.h>
diff --git a/src/google/protobuf/arenastring_unittest.cc b/src/google/protobuf/arenastring_unittest.cc index 70a3f76..c5da447 100644 --- a/src/google/protobuf/arenastring_unittest.cc +++ b/src/google/protobuf/arenastring_unittest.cc
@@ -43,6 +43,7 @@ #include <google/protobuf/io/coded_stream.h> #include <google/protobuf/io/zero_copy_stream_impl.h> #include <gtest/gtest.h> +#include <google/protobuf/stubs/strutil.h> namespace google { @@ -50,7 +51,6 @@ using internal::ArenaStringPtr; - static std::string WrapString(const char* value) { return value; } // Test ArenaStringPtr with arena == NULL.
diff --git a/src/google/protobuf/compiler/command_line_interface.cc b/src/google/protobuf/compiler/command_line_interface.cc index 1fbc34e..9278bd0 100644 --- a/src/google/protobuf/compiler/command_line_interface.cc +++ b/src/google/protobuf/compiler/command_line_interface.cc
@@ -869,7 +869,8 @@ } descriptor_pool->EnforceWeakDependencies(true); - if (!ParseInputFiles(descriptor_pool.get(), &parsed_files)) { + if (!ParseInputFiles(descriptor_pool.get(), disk_source_tree.get(), + &parsed_files)) { return 1; } @@ -1044,7 +1045,8 @@ for (const auto& input_file : input_files_) { FileDescriptorProto file_descriptor; if (!database->FindFileByName(input_file, &file_descriptor)) { - std::cerr << input_file << ": " << strerror(ENOENT) << std::endl; + std::cerr << "Could not find file in descriptor database: " << input_file + << ": " << strerror(ENOENT) << std::endl; return false; } @@ -1061,7 +1063,7 @@ } bool CommandLineInterface::ParseInputFiles( - DescriptorPool* descriptor_pool, + DescriptorPool* descriptor_pool, DiskSourceTree* source_tree, std::vector<const FileDescriptor*>* parsed_files) { // Track unused imports in all source files @@ -1154,7 +1156,8 @@ in_fallback_database) { return true; } else { - std::cerr << *proto << ": " << strerror(ENOENT) << std::endl; + std::cerr << "Could not make proto path relative: " << *proto << ": " + << strerror(ENOENT) << std::endl; return false; } } @@ -1177,7 +1180,8 @@ if (in_fallback_database) { return true; } - std::cerr << *proto << ": " << strerror(errno) << std::endl; + std::cerr << "Could not map to virtual file: " << *proto << ": " + << strerror(errno) << std::endl; return false; case DiskSourceTree::NO_MAPPING: { // Try to interpret the path as a virtual path.
diff --git a/src/google/protobuf/compiler/command_line_interface.h b/src/google/protobuf/compiler/command_line_interface.h index 1a9b66a..9449fa3 100644 --- a/src/google/protobuf/compiler/command_line_interface.h +++ b/src/google/protobuf/compiler/command_line_interface.h
@@ -43,6 +43,7 @@ #include <set> #include <string> #include <unordered_map> +#include <unordered_set> #include <utility> #include <vector> @@ -273,6 +274,7 @@ // Parses input_files_ into parsed_files bool ParseInputFiles(DescriptorPool* descriptor_pool, + DiskSourceTree* source_tree, std::vector<const FileDescriptor*>* parsed_files); // Generate the given output file from the given input.
diff --git a/src/google/protobuf/compiler/command_line_interface_unittest.cc b/src/google/protobuf/compiler/command_line_interface_unittest.cc index 5a31215..e4fd54e 100644 --- a/src/google/protobuf/compiler/command_line_interface_unittest.cc +++ b/src/google/protobuf/compiler/command_line_interface_unittest.cc
@@ -1778,7 +1778,9 @@ Run("protocol_compiler --test_out=$tmpdir " "--proto_path=$tmpdir foo.proto"); - ExpectErrorText("foo.proto: No such file or directory\n"); + ExpectErrorText( + "Could not make proto path relative: foo.proto: No such file or " + "directory\n"); } TEST_F(CommandLineInterfaceTest, InputNotFoundError_DescriptorSetIn) { @@ -1797,7 +1799,9 @@ Run("protocol_compiler --test_out=$tmpdir " "--proto_path=$tmpdir $tmpdir/foo.proto"); - ExpectErrorText("$tmpdir/foo.proto: No such file or directory\n"); + ExpectErrorText( + "Could not make proto path relative: $tmpdir/foo.proto: No such file or " + "directory\n"); } TEST_F(CommandLineInterfaceTest, CwdRelativeInputNotMappedError) { @@ -1834,7 +1838,9 @@ Run("protocol_compiler --test_out=$tmpdir " "--proto_path=$tmpdir/bar $tmpdir/foo.proto"); - ExpectErrorText("$tmpdir/foo.proto: No such file or directory\n"); + ExpectErrorText( + "Could not make proto path relative: $tmpdir/foo.proto: No such file or " + "directory\n"); } TEST_F(CommandLineInterfaceTest, CwdRelativeInputShadowedError) { @@ -1867,7 +1873,8 @@ ExpectErrorText( "$tmpdir/foo: warning: directory does not exist.\n" - "foo.proto: No such file or directory\n"); + "Could not make proto path relative: foo.proto: No such file or " + "directory\n"); } TEST_F(CommandLineInterfaceTest, ProtoPathAndDescriptorSetIn) { @@ -2479,6 +2486,11 @@ EXPECT_EQ(StripCR(expected_text), StripCR(captured_stderr_)); } + void ExpectStderrContainsText(const std::string& expected_text) { + EXPECT_NE(StripCR(captured_stderr_).find(StripCR(expected_text)), + std::string::npos); + } + private: void WriteUnittestProtoDescriptorSet() { unittest_proto_descriptor_set_filename_ = @@ -2569,7 +2581,7 @@ Run("net/proto2/internal/no_such_file.proto " "--encode=NoSuchType")); ExpectStdoutMatchesText(""); - ExpectStderrMatchesText( + ExpectStderrContainsText( "net/proto2/internal/no_such_file.proto: No such file or directory\n"); }
diff --git a/src/google/protobuf/compiler/cpp/cpp_enum.cc b/src/google/protobuf/compiler/cpp/cpp_enum.cc index 366fcb6..c0a03ad 100644 --- a/src/google/protobuf/compiler/cpp/cpp_enum.cc +++ b/src/google/protobuf/compiler/cpp/cpp_enum.cc
@@ -104,10 +104,8 @@ // 2147483648, and since 2147483648 can't fit in an integer, this produces a // compiler warning. This works around that issue. format_value.Set("number", Int32ToString(descriptor_->value(i)->number())); - format_value.Set( - "deprecation", - DeprecatedAttribute(options_, - descriptor_->value(i)->options().deprecated())); + format_value.Set("deprecation", + DeprecatedAttribute(options_, descriptor_->value(i))); if (i > 0) format_value(",\n"); format_value("${1$$prefix$$name$$}$ $deprecation$= $number$", @@ -213,8 +211,8 @@ format("typedef $classname$ $resolved_name$;\n"); for (int j = 0; j < descriptor_->value_count(); j++) { - std::string deprecated_attr = DeprecatedAttribute( - options_, descriptor_->value(j)->options().deprecated()); + std::string deprecated_attr = + DeprecatedAttribute(options_, descriptor_->value(j)); format( "$1$static constexpr $resolved_name$ ${2$$3$$}$ =\n" " $classname$_$3$;\n",
diff --git a/src/google/protobuf/compiler/cpp/cpp_field.cc b/src/google/protobuf/compiler/cpp/cpp_field.cc index 890387e..5b2ca15 100644 --- a/src/google/protobuf/compiler/cpp/cpp_field.cc +++ b/src/google/protobuf/compiler/cpp/cpp_field.cc
@@ -69,8 +69,7 @@ (*variables)["tag_size"] = StrCat( WireFormat::TagSize(descriptor->number(), descriptor->type())); - (*variables)["deprecated_attr"] = - DeprecatedAttribute(options, descriptor->options().deprecated()); + (*variables)["deprecated_attr"] = DeprecatedAttribute(options, descriptor); (*variables)["set_hasbit"] = ""; (*variables)["clear_hasbit"] = "";
diff --git a/src/google/protobuf/compiler/cpp/cpp_file.cc b/src/google/protobuf/compiler/cpp/cpp_file.cc index 66565fb..45fd308 100644 --- a/src/google/protobuf/compiler/cpp/cpp_file.cc +++ b/src/google/protobuf/compiler/cpp/cpp_file.cc
@@ -1357,10 +1357,6 @@ if (UseUnknownFieldSet(file_, options_) && !message_generators_.empty()) { IncludeFile("net/proto2/public/unknown_field_set.h", printer); } - - if (IsAnyMessage(file_, options_)) { - IncludeFile("net/proto2/internal/any.h", printer); - } } void FileGenerator::GenerateMetadataPragma(io::Printer* printer,
diff --git a/src/google/protobuf/compiler/cpp/cpp_helpers.cc b/src/google/protobuf/compiler/cpp/cpp_helpers.cc index f34986e..062ad6b 100644 --- a/src/google/protobuf/compiler/cpp/cpp_helpers.cc +++ b/src/google/protobuf/compiler/cpp/cpp_helpers.cc
@@ -983,12 +983,6 @@ return well_known_files.find(file->name()) != well_known_files.end(); } -enum Utf8CheckMode { - STRICT = 0, // Parsing will fail if non UTF-8 data is in string fields. - VERIFY = 1, // Only log an error but parsing will succeed. - NONE = 2, // No UTF-8 check. -}; - static bool FieldEnforceUtf8(const FieldDescriptor* field, const Options& options) { return true; @@ -1000,8 +994,8 @@ } // Which level of UTF-8 enforcemant is placed on this file. -static Utf8CheckMode GetUtf8CheckMode(const FieldDescriptor* field, - const Options& options) { +Utf8CheckMode GetUtf8CheckMode(const FieldDescriptor* field, + const Options& options) { if (field->file()->syntax() == FileDescriptor::SYNTAX_PROTO3 && FieldEnforceUtf8(field, options)) { return STRICT; @@ -1014,19 +1008,6 @@ } } -std::string GetUtf8Suffix(const FieldDescriptor* field, - const Options& options) { - switch (GetUtf8CheckMode(field, options)) { - case STRICT: - return "UTF8"; - case VERIFY: - return "UTF8Verify"; - case NONE: - default: // Some build configs warn on missing return without default. - return ""; - } -} - static void GenerateUtf8CheckCode(const FieldDescriptor* field, const Options& options, bool for_parse, const char* parameters, @@ -1418,13 +1399,7 @@ using WireFormat = internal::WireFormat; using WireFormatLite = internal::WireFormatLite; - void GenerateArenaString(const FieldDescriptor* field, - const std::string& utf8, std::string field_name) { - if (!field_name.empty()) { - format_("static const char kFieldName[] = $1$;\n", - field_name.substr(2)); // remove ", " - field_name = ", kFieldName"; - } + void GenerateArenaString(const FieldDescriptor* field) { if (HasFieldPresence(field->file())) { format_("_Internal::set_has_$1$(&$has_bits$);\n", FieldName(field)); } @@ -1436,28 +1411,17 @@ "::" + MakeDefaultName(field) + ".get()"; format_( "if (arena != nullptr) {\n" - " ptr = $pi_ns$::InlineCopyIntoArenaString$1$(&$2$_, ptr, ctx, " - " arena$3$);\n" + " ptr = ctx->ReadArenaString(ptr, &$1$_, arena);\n" "} else {\n" " ptr = " - "$pi_ns$::InlineGreedyStringParser$1$($2$_.MutableNoArenaNoDefault(&$4$" - "), ptr, ctx$3$);" - "\n}\n", - utf8, FieldName(field), field_name, default_string); + "$pi_ns$::InlineGreedyStringParser($1$_.MutableNoArenaNoDefault(&$2$" + "), ptr, ctx);" + "\n}\n" + "const std::string* str = &$1$_.Get(); (void)str;\n", + FieldName(field), default_string); } void GenerateStrings(const FieldDescriptor* field, bool check_utf8) { - std::string utf8; - std::string field_name; - if (check_utf8) { - utf8 = GetUtf8Suffix(field, options_); - if (!utf8.empty()) { - field_name = ", nullptr"; - if (HasDescriptorMethods(field->file(), options_)) { - field_name = StrCat(", \"", field->full_name(), "\""); - } - } - } FieldOptions::CType ctype = FieldOptions::STRING; if (!options_.opensource_runtime) { // Open source doesn't support other ctypes; @@ -1470,25 +1434,57 @@ field->default_value_string().empty() && !IsStringInlined(field, options_) && field->containing_oneof() == nullptr && ctype == FieldOptions::STRING) { - GenerateArenaString(field, utf8, field_name); - return; + GenerateArenaString(field); + } else { + std::string name; + switch (ctype) { + case FieldOptions::STRING: + name = "GreedyStringParser"; + break; + case FieldOptions::CORD: + name = "CordParser"; + break; + case FieldOptions::STRING_PIECE: + name = "StringPieceParser"; + break; + } + format_( + "auto str = $1$$2$_$3$();\n" + "ptr = $pi_ns$::Inline$4$(str, ptr, ctx);\n", + HasInternalAccessors(ctype) ? "_internal_" : "", + field->is_repeated() && !field->is_packable() ? "add" : "mutable", + FieldName(field), name); } - std::string name; - switch (ctype) { - case FieldOptions::STRING: - name = "GreedyStringParser" + utf8; + if (!check_utf8) return; // return if this is a bytes field + auto level = GetUtf8CheckMode(field, options_); + switch (level) { + case NONE: + return; + case VERIFY: + format_("#ifndef NDEBUG\n"); break; - case FieldOptions::CORD: - name = "CordParser" + utf8; - break; - case FieldOptions::STRING_PIECE: - name = "StringPieceParser" + utf8; + case STRICT: + format_("CHK_("); break; } - format_("ptr = $pi_ns$::Inline$1$($2$$3$_$4$(), ptr, ctx$5$);\n", name, - HasInternalAccessors(ctype) ? "_internal_" : "", - field->is_repeated() && !field->is_packable() ? "add" : "mutable", - FieldName(field), field_name); + std::string field_name; + field_name = "nullptr"; + if (HasDescriptorMethods(field->file(), options_)) { + field_name = StrCat("\"", field->full_name(), "\""); + } + format_("$pi_ns$::VerifyUTF8(str, $1$)", field_name); + switch (level) { + case NONE: + return; + case VERIFY: + format_( + ";\n" + "#endif // !NDEBUG\n"); + break; + case STRICT: + format_(");\n"); + break; + } } void GenerateLengthDelim(const FieldDescriptor* field) {
diff --git a/src/google/protobuf/compiler/cpp/cpp_helpers.h b/src/google/protobuf/compiler/cpp/cpp_helpers.h index 2f11b50..28cf78e 100644 --- a/src/google/protobuf/compiler/cpp/cpp_helpers.h +++ b/src/google/protobuf/compiler/cpp/cpp_helpers.h
@@ -66,8 +66,13 @@ } inline std::string DeprecatedAttribute(const Options& options, - bool deprecated) { - return deprecated ? "PROTOBUF_DEPRECATED " : ""; + const FieldDescriptor* d) { + return d->options().deprecated() ? "PROTOBUF_DEPRECATED " : ""; +} + +inline std::string DeprecatedAttribute(const Options& options, + const EnumValueDescriptor* d) { + return d->options().deprecated() ? "PROTOBUF_DEPRECATED_ENUM " : ""; } // Commonly-used separator comments. Thick is a line of '=', thin is a line @@ -756,7 +761,15 @@ std::vector<std::string> name_stack_; }; -std::string GetUtf8Suffix(const FieldDescriptor* field, const Options& options); +enum Utf8CheckMode { + STRICT = 0, // Parsing will fail if non UTF-8 data is in string fields. + VERIFY = 1, // Only log an error but parsing will succeed. + NONE = 2, // No UTF-8 check. +}; + +Utf8CheckMode GetUtf8CheckMode(const FieldDescriptor* field, + const Options& options); + void GenerateUtf8CheckCodeForString(const FieldDescriptor* field, const Options& options, bool for_parse, const char* parameters,
diff --git a/src/google/protobuf/compiler/cpp/cpp_message.cc b/src/google/protobuf/compiler/cpp/cpp_message.cc index 1a70755..b88c1f7 100644 --- a/src/google/protobuf/compiler/cpp/cpp_message.cc +++ b/src/google/protobuf/compiler/cpp/cpp_message.cc
@@ -1011,10 +1011,10 @@ " static const $classname$* internal_default_instance() { return " "reinterpret_cast<const " "$classname$*>(&_$classname$_default_instance_); }\n"); - std::string suffix = GetUtf8Suffix(descriptor_->field(0), options_); + auto utf8_check = GetUtf8CheckMode(descriptor_->field(0), options_); if (descriptor_->field(0)->type() == FieldDescriptor::TYPE_STRING && - !suffix.empty()) { - if (suffix == "UTF8") { + utf8_check != NONE) { + if (utf8_check == STRICT) { format( " static bool ValidateKey(std::string* s) {\n" " return ::$proto_ns$::internal::WireFormatLite::" @@ -1023,12 +1023,13 @@ " }\n", descriptor_->field(0)->full_name()); } else { - GOOGLE_CHECK(suffix == "UTF8Verify"); + GOOGLE_CHECK(utf8_check == VERIFY); format( " static bool ValidateKey(std::string* s) {\n" "#ifndef NDEBUG\n" " ::$proto_ns$::internal::WireFormatLite::VerifyUtf8String(\n" - " s->data(), static_cast<int>(s->size()), ::$proto_ns$::internal::" + " s->data(), static_cast<int>(s->size()), " + "::$proto_ns$::internal::" "WireFormatLite::PARSE, \"$1$\");\n" "#endif\n" " return true;\n" @@ -1039,8 +1040,8 @@ format(" static bool ValidateKey(void*) { return true; }\n"); } if (descriptor_->field(1)->type() == FieldDescriptor::TYPE_STRING && - !suffix.empty()) { - if (suffix == "UTF8") { + utf8_check != NONE) { + if (utf8_check == STRICT) { format( " static bool ValidateValue(std::string* s) {\n" " return ::$proto_ns$::internal::WireFormatLite::" @@ -1049,12 +1050,13 @@ " }\n", descriptor_->field(1)->full_name()); } else { - GOOGLE_CHECK(suffix == "UTF8Verify"); + GOOGLE_CHECK(utf8_check = VERIFY); format( " static bool ValidateValue(std::string* s) {\n" "#ifndef NDEBUG\n" " ::$proto_ns$::internal::WireFormatLite::VerifyUtf8String(\n" - " s->data(), static_cast<int>(s->size()), ::$proto_ns$::internal::" + " s->data(), static_cast<int>(s->size()), " + "::$proto_ns$::internal::" "WireFormatLite::PARSE, \"$1$\");\n" "#endif\n" " return true;\n" @@ -1351,7 +1353,7 @@ "size_t ByteSizeLong() const final;\n" "const char* _InternalParse(const char* ptr, " "::$proto_ns$::internal::ParseContext* ctx) final;\n" - "$uint8$* InternalSerializeWithCachedSizesToArray(\n" + "$uint8$* _InternalSerialize(\n" " $uint8$* target, ::$proto_ns$::io::EpsCopyOutputStream* stream) " "const final;\n"); @@ -3488,7 +3490,7 @@ Formatter format(printer, vars); format("// Extension range [$start$, $end$)\n"); format( - "target = _extensions_.InternalSerializeWithCachedSizesToArray(\n" + "target = _extensions_._InternalSerialize(\n" " $start$, $end$, target, stream);\n\n"); } @@ -3498,7 +3500,7 @@ if (descriptor_->options().message_set_wire_format()) { // Special-case MessageSet. format( - "$uint8$* $classname$::InternalSerializeWithCachedSizesToArray(\n" + "$uint8$* $classname$::_InternalSerialize(\n" " $uint8$* target, ::$proto_ns$::io::EpsCopyOutputStream* stream) " "const {\n" " target = _extensions_." @@ -3517,7 +3519,7 @@ } format( - "$uint8$* $classname$::InternalSerializeWithCachedSizesToArray(\n" + "$uint8$* $classname$::_InternalSerialize(\n" " $uint8$* target, ::$proto_ns$::io::EpsCopyOutputStream* stream) " "const {\n"); format.Indent(); @@ -3759,7 +3761,7 @@ if (field->is_required()) { format( "\n" - "if (has_$1$()) {\n", + "if (_internal_has_$1$()) {\n", FieldName(field)); format.Indent(); PrintFieldComment(format, field); @@ -3820,7 +3822,7 @@ for (auto field : optimized_order_) { if (!field->is_required()) continue; PrintFieldComment(format, field); - format("if (has_$1$()) {\n", FieldName(field)); + format("if (_internal_has_$1$()) {\n", FieldName(field)); format.Indent(); field_generators_.get(field).GenerateByteSize(printer); format.Outdent(); @@ -4042,13 +4044,13 @@ if (IsImplicitWeakField(field, options_, scc_analyzer_)) { format( "if " - "(!::$proto_ns$::internal::AllAreInitializedWeak(this->$1$_.weak)" + "(!::$proto_ns$::internal::AllAreInitializedWeak($1$_.weak)" ")" " return false;\n", FieldName(field)); } else { format( - "if (!::$proto_ns$::internal::AllAreInitialized(this->$1$()))" + "if (!::$proto_ns$::internal::AllAreInitialized($1$_))" " return false;\n", FieldName(field)); } @@ -4057,8 +4059,8 @@ } else { GOOGLE_CHECK(!field->containing_oneof()); format( - "if (has_$1$()) {\n" - " if (!this->$1$_->IsInitialized()) return false;\n" + "if (_internal_has_$1$()) {\n" + " if (!$1$_->IsInitialized()) return false;\n" "}\n", FieldName(field)); }
diff --git a/src/google/protobuf/compiler/cpp/cpp_message_field.cc b/src/google/protobuf/compiler/cpp/cpp_message_field.cc index 6c5a017..12c6524 100644 --- a/src/google/protobuf/compiler/cpp/cpp_message_field.cc +++ b/src/google/protobuf/compiler/cpp/cpp_message_field.cc
@@ -439,7 +439,7 @@ format( "target = stream->EnsureSpace(target);\n" "target = ::$proto_ns$::internal::WireFormatLite::\n" - " InternalWrite$declared_type$ToArray(\n" + " InternalWrite$declared_type$(\n" " $number$, _Internal::$name$(this), target, stream);\n"); } @@ -505,7 +505,7 @@ "inline $type$* $classname$::$release_name$() {\n" "$annotate_accessor$" " // @@protoc_insertion_point(field_release:$full_name$)\n" - " if (has_$name$()) {\n" + " if (_internal_has_$name$()) {\n" " clear_has_$oneof_name$();\n" " $type$* temp = $field_member$;\n"); if (SupportsArenas(descriptor_)) { @@ -540,7 +540,7 @@ "$annotate_accessor$" " // @@protoc_insertion_point(field_unsafe_arena_release" ":$full_name$)\n" - " if (has_$name$()) {\n" + " if (_internal_has_$name$()) {\n" " clear_has_$oneof_name$();\n" " $type$* temp = $field_member$;\n" " $field_member$ = nullptr;\n" @@ -752,8 +752,7 @@ " end = this->$name$_.pointer_end(); it < end; ++it) {\n" " target = stream->EnsureSpace(target);\n" " target = ::$proto_ns$::internal::WireFormatLite::\n" - " InternalWrite$declared_type$ToArray($number$, **it, target, " - "stream);\n" + " InternalWrite$declared_type$($number$, **it, target, stream);\n" "}\n"); } else { format( @@ -763,9 +762,8 @@ "{\n" " target = stream->EnsureSpace(target);\n" " target = ::$proto_ns$::internal::WireFormatLite::\n" - " InternalWrite$declared_type$ToArray($number$, " - "this->_internal_$name$(i), target, " - "stream);\n" + " InternalWrite$declared_type$($number$, " + "this->_internal_$name$(i), target, stream);\n" "}\n"); } }
diff --git a/src/google/protobuf/compiler/cpp/cpp_string_field.cc b/src/google/protobuf/compiler/cpp/cpp_string_field.cc index 966eeea..847f76c 100644 --- a/src/google/protobuf/compiler/cpp/cpp_string_field.cc +++ b/src/google/protobuf/compiler/cpp/cpp_string_field.cc
@@ -285,7 +285,7 @@ if (HasFieldPresence(descriptor_->file())) { format( - " if (!has_$name$()) {\n" + " if (!_internal_has_$name$()) {\n" " return nullptr;\n" " }\n" " $clear_hasbit$\n" @@ -391,7 +391,7 @@ if (HasFieldPresence(descriptor_->file())) { format( - " if (!has_$name$()) {\n" + " if (!_internal_has_$name$()) {\n" " return nullptr;\n" " }\n" " $clear_hasbit$\n"
diff --git a/src/google/protobuf/compiler/csharp/csharp_helpers.h b/src/google/protobuf/compiler/csharp/csharp_helpers.h index c51681e..6354e9e 100644 --- a/src/google/protobuf/compiler/csharp/csharp_helpers.h +++ b/src/google/protobuf/compiler/csharp/csharp_helpers.h
@@ -36,6 +36,7 @@ #define GOOGLE_PROTOBUF_COMPILER_CSHARP_HELPERS_H__ #include <string> +#include <google/protobuf/port.h> #include <google/protobuf/stubs/common.h> #include <google/protobuf/descriptor.pb.h> #include <google/protobuf/descriptor.h>
diff --git a/src/google/protobuf/compiler/csharp/csharp_names.h b/src/google/protobuf/compiler/csharp/csharp_names.h index fa3e245..4485272 100644 --- a/src/google/protobuf/compiler/csharp/csharp_names.h +++ b/src/google/protobuf/compiler/csharp/csharp_names.h
@@ -39,6 +39,7 @@ #define GOOGLE_PROTOBUF_COMPILER_CSHARP_NAMES_H__ #include <string> +#include <google/protobuf/port.h> #include <google/protobuf/stubs/common.h> #include <google/protobuf/port_def.inc>
diff --git a/src/google/protobuf/compiler/main.cc b/src/google/protobuf/compiler/main.cc index e1c539a..b723b14 100644 --- a/src/google/protobuf/compiler/main.cc +++ b/src/google/protobuf/compiler/main.cc
@@ -32,11 +32,10 @@ #include <google/protobuf/compiler/cpp/cpp_generator.h> #include <google/protobuf/compiler/java/java_generator.h> +#include <google/protobuf/compiler/js/js_generator.h> #include <google/protobuf/compiler/command_line_interface.h> #include <google/protobuf/compiler/python/python_generator.h> - #include <google/protobuf/compiler/csharp/csharp_generator.h> -#include <google/protobuf/compiler/js/js_generator.h> #include <google/protobuf/compiler/objectivec/objectivec_generator.h> #include <google/protobuf/compiler/php/php_generator.h> #include <google/protobuf/compiler/ruby/ruby_generator.h>
diff --git a/src/google/protobuf/compiler/objectivec/objectivec_helpers.cc b/src/google/protobuf/compiler/objectivec/objectivec_helpers.cc index 724e946..09a808b 100644 --- a/src/google/protobuf/compiler/objectivec/objectivec_helpers.cc +++ b/src/google/protobuf/compiler/objectivec/objectivec_helpers.cc
@@ -48,6 +48,7 @@ #include <google/protobuf/io/printer.h> #include <google/protobuf/io/zero_copy_stream_impl.h> #include <google/protobuf/io/io_win32.h> +#include <google/protobuf/port.h> #include <google/protobuf/stubs/common.h> #include <google/protobuf/stubs/strutil.h>
diff --git a/src/google/protobuf/compiler/plugin.pb.cc b/src/google/protobuf/compiler/plugin.pb.cc index b0f73df..354b4c8 100644 --- a/src/google/protobuf/compiler/plugin.pb.cc +++ b/src/google/protobuf/compiler/plugin.pb.cc
@@ -324,7 +324,11 @@ // optional string suffix = 4; case 4: if (PROTOBUF_PREDICT_TRUE(static_cast<::PROTOBUF_NAMESPACE_ID::uint8>(tag) == 34)) { - ptr = ::PROTOBUF_NAMESPACE_ID::internal::InlineGreedyStringParserUTF8Verify(_internal_mutable_suffix(), ptr, ctx, "google.protobuf.compiler.Version.suffix"); + auto str = _internal_mutable_suffix(); + ptr = ::PROTOBUF_NAMESPACE_ID::internal::InlineGreedyStringParser(str, ptr, ctx); + #ifndef NDEBUG + ::PROTOBUF_NAMESPACE_ID::internal::VerifyUTF8(str, "google.protobuf.compiler.Version.suffix"); + #endif // !NDEBUG CHK_(ptr); } else goto handle_unusual; continue; @@ -349,7 +353,7 @@ #undef CHK_ } -::PROTOBUF_NAMESPACE_ID::uint8* Version::InternalSerializeWithCachedSizesToArray( +::PROTOBUF_NAMESPACE_ID::uint8* Version::_InternalSerialize( ::PROTOBUF_NAMESPACE_ID::uint8* target, ::PROTOBUF_NAMESPACE_ID::io::EpsCopyOutputStream* stream) const { // @@protoc_insertion_point(serialize_to_array_start:google.protobuf.compiler.Version) ::PROTOBUF_NAMESPACE_ID::uint32 cached_has_bits = 0; @@ -625,7 +629,11 @@ ptr -= 1; do { ptr += 1; - ptr = ::PROTOBUF_NAMESPACE_ID::internal::InlineGreedyStringParserUTF8Verify(_internal_add_file_to_generate(), ptr, ctx, "google.protobuf.compiler.CodeGeneratorRequest.file_to_generate"); + auto str = _internal_add_file_to_generate(); + ptr = ::PROTOBUF_NAMESPACE_ID::internal::InlineGreedyStringParser(str, ptr, ctx); + #ifndef NDEBUG + ::PROTOBUF_NAMESPACE_ID::internal::VerifyUTF8(str, "google.protobuf.compiler.CodeGeneratorRequest.file_to_generate"); + #endif // !NDEBUG CHK_(ptr); if (!ctx->DataAvailable(ptr)) break; } while (::PROTOBUF_NAMESPACE_ID::internal::ExpectTag<10>(ptr)); @@ -634,7 +642,11 @@ // optional string parameter = 2; case 2: if (PROTOBUF_PREDICT_TRUE(static_cast<::PROTOBUF_NAMESPACE_ID::uint8>(tag) == 18)) { - ptr = ::PROTOBUF_NAMESPACE_ID::internal::InlineGreedyStringParserUTF8Verify(_internal_mutable_parameter(), ptr, ctx, "google.protobuf.compiler.CodeGeneratorRequest.parameter"); + auto str = _internal_mutable_parameter(); + ptr = ::PROTOBUF_NAMESPACE_ID::internal::InlineGreedyStringParser(str, ptr, ctx); + #ifndef NDEBUG + ::PROTOBUF_NAMESPACE_ID::internal::VerifyUTF8(str, "google.protobuf.compiler.CodeGeneratorRequest.parameter"); + #endif // !NDEBUG CHK_(ptr); } else goto handle_unusual; continue; @@ -678,7 +690,7 @@ #undef CHK_ } -::PROTOBUF_NAMESPACE_ID::uint8* CodeGeneratorRequest::InternalSerializeWithCachedSizesToArray( +::PROTOBUF_NAMESPACE_ID::uint8* CodeGeneratorRequest::_InternalSerialize( ::PROTOBUF_NAMESPACE_ID::uint8* target, ::PROTOBUF_NAMESPACE_ID::io::EpsCopyOutputStream* stream) const { // @@protoc_insertion_point(serialize_to_array_start:google.protobuf.compiler.CodeGeneratorRequest) ::PROTOBUF_NAMESPACE_ID::uint32 cached_has_bits = 0; @@ -709,7 +721,7 @@ if (cached_has_bits & 0x00000002u) { target = stream->EnsureSpace(target); target = ::PROTOBUF_NAMESPACE_ID::internal::WireFormatLite:: - InternalWriteMessageToArray( + InternalWriteMessage( 3, _Internal::compiler_version(this), target, stream); } @@ -718,7 +730,7 @@ n = static_cast<unsigned int>(this->_internal_proto_file_size()); i < n; i++) { target = stream->EnsureSpace(target); target = ::PROTOBUF_NAMESPACE_ID::internal::WireFormatLite:: - InternalWriteMessageToArray(15, this->_internal_proto_file(i), target, stream); + InternalWriteMessage(15, this->_internal_proto_file(i), target, stream); } if (PROTOBUF_PREDICT_FALSE(_internal_metadata_.have_unknown_fields())) { @@ -829,7 +841,7 @@ } bool CodeGeneratorRequest::IsInitialized() const { - if (!::PROTOBUF_NAMESPACE_ID::internal::AllAreInitialized(this->proto_file())) return false; + if (!::PROTOBUF_NAMESPACE_ID::internal::AllAreInitialized(proto_file_)) return false; return true; } @@ -952,21 +964,33 @@ // optional string name = 1; case 1: if (PROTOBUF_PREDICT_TRUE(static_cast<::PROTOBUF_NAMESPACE_ID::uint8>(tag) == 10)) { - ptr = ::PROTOBUF_NAMESPACE_ID::internal::InlineGreedyStringParserUTF8Verify(_internal_mutable_name(), ptr, ctx, "google.protobuf.compiler.CodeGeneratorResponse.File.name"); + auto str = _internal_mutable_name(); + ptr = ::PROTOBUF_NAMESPACE_ID::internal::InlineGreedyStringParser(str, ptr, ctx); + #ifndef NDEBUG + ::PROTOBUF_NAMESPACE_ID::internal::VerifyUTF8(str, "google.protobuf.compiler.CodeGeneratorResponse.File.name"); + #endif // !NDEBUG CHK_(ptr); } else goto handle_unusual; continue; // optional string insertion_point = 2; case 2: if (PROTOBUF_PREDICT_TRUE(static_cast<::PROTOBUF_NAMESPACE_ID::uint8>(tag) == 18)) { - ptr = ::PROTOBUF_NAMESPACE_ID::internal::InlineGreedyStringParserUTF8Verify(_internal_mutable_insertion_point(), ptr, ctx, "google.protobuf.compiler.CodeGeneratorResponse.File.insertion_point"); + auto str = _internal_mutable_insertion_point(); + ptr = ::PROTOBUF_NAMESPACE_ID::internal::InlineGreedyStringParser(str, ptr, ctx); + #ifndef NDEBUG + ::PROTOBUF_NAMESPACE_ID::internal::VerifyUTF8(str, "google.protobuf.compiler.CodeGeneratorResponse.File.insertion_point"); + #endif // !NDEBUG CHK_(ptr); } else goto handle_unusual; continue; // optional string content = 15; case 15: if (PROTOBUF_PREDICT_TRUE(static_cast<::PROTOBUF_NAMESPACE_ID::uint8>(tag) == 122)) { - ptr = ::PROTOBUF_NAMESPACE_ID::internal::InlineGreedyStringParserUTF8Verify(_internal_mutable_content(), ptr, ctx, "google.protobuf.compiler.CodeGeneratorResponse.File.content"); + auto str = _internal_mutable_content(); + ptr = ::PROTOBUF_NAMESPACE_ID::internal::InlineGreedyStringParser(str, ptr, ctx); + #ifndef NDEBUG + ::PROTOBUF_NAMESPACE_ID::internal::VerifyUTF8(str, "google.protobuf.compiler.CodeGeneratorResponse.File.content"); + #endif // !NDEBUG CHK_(ptr); } else goto handle_unusual; continue; @@ -991,7 +1015,7 @@ #undef CHK_ } -::PROTOBUF_NAMESPACE_ID::uint8* CodeGeneratorResponse_File::InternalSerializeWithCachedSizesToArray( +::PROTOBUF_NAMESPACE_ID::uint8* CodeGeneratorResponse_File::_InternalSerialize( ::PROTOBUF_NAMESPACE_ID::uint8* target, ::PROTOBUF_NAMESPACE_ID::io::EpsCopyOutputStream* stream) const { // @@protoc_insertion_point(serialize_to_array_start:google.protobuf.compiler.CodeGeneratorResponse.File) ::PROTOBUF_NAMESPACE_ID::uint32 cached_has_bits = 0; @@ -1230,7 +1254,11 @@ // optional string error = 1; case 1: if (PROTOBUF_PREDICT_TRUE(static_cast<::PROTOBUF_NAMESPACE_ID::uint8>(tag) == 10)) { - ptr = ::PROTOBUF_NAMESPACE_ID::internal::InlineGreedyStringParserUTF8Verify(_internal_mutable_error(), ptr, ctx, "google.protobuf.compiler.CodeGeneratorResponse.error"); + auto str = _internal_mutable_error(); + ptr = ::PROTOBUF_NAMESPACE_ID::internal::InlineGreedyStringParser(str, ptr, ctx); + #ifndef NDEBUG + ::PROTOBUF_NAMESPACE_ID::internal::VerifyUTF8(str, "google.protobuf.compiler.CodeGeneratorResponse.error"); + #endif // !NDEBUG CHK_(ptr); } else goto handle_unusual; continue; @@ -1267,7 +1295,7 @@ #undef CHK_ } -::PROTOBUF_NAMESPACE_ID::uint8* CodeGeneratorResponse::InternalSerializeWithCachedSizesToArray( +::PROTOBUF_NAMESPACE_ID::uint8* CodeGeneratorResponse::_InternalSerialize( ::PROTOBUF_NAMESPACE_ID::uint8* target, ::PROTOBUF_NAMESPACE_ID::io::EpsCopyOutputStream* stream) const { // @@protoc_insertion_point(serialize_to_array_start:google.protobuf.compiler.CodeGeneratorResponse) ::PROTOBUF_NAMESPACE_ID::uint32 cached_has_bits = 0; @@ -1289,7 +1317,7 @@ n = static_cast<unsigned int>(this->_internal_file_size()); i < n; i++) { target = stream->EnsureSpace(target); target = ::PROTOBUF_NAMESPACE_ID::internal::WireFormatLite:: - InternalWriteMessageToArray(15, this->_internal_file(i), target, stream); + InternalWriteMessage(15, this->_internal_file(i), target, stream); } if (PROTOBUF_PREDICT_FALSE(_internal_metadata_.have_unknown_fields())) {
diff --git a/src/google/protobuf/compiler/plugin.pb.h b/src/google/protobuf/compiler/plugin.pb.h index ec70e03..2dee810 100644 --- a/src/google/protobuf/compiler/plugin.pb.h +++ b/src/google/protobuf/compiler/plugin.pb.h
@@ -165,7 +165,7 @@ size_t ByteSizeLong() const final; const char* _InternalParse(const char* ptr, ::PROTOBUF_NAMESPACE_ID::internal::ParseContext* ctx) final; - ::PROTOBUF_NAMESPACE_ID::uint8* InternalSerializeWithCachedSizesToArray( + ::PROTOBUF_NAMESPACE_ID::uint8* _InternalSerialize( ::PROTOBUF_NAMESPACE_ID::uint8* target, ::PROTOBUF_NAMESPACE_ID::io::EpsCopyOutputStream* stream) const final; int GetCachedSize() const final { return _cached_size_.Get(); } @@ -357,7 +357,7 @@ size_t ByteSizeLong() const final; const char* _InternalParse(const char* ptr, ::PROTOBUF_NAMESPACE_ID::internal::ParseContext* ctx) final; - ::PROTOBUF_NAMESPACE_ID::uint8* InternalSerializeWithCachedSizesToArray( + ::PROTOBUF_NAMESPACE_ID::uint8* _InternalSerialize( ::PROTOBUF_NAMESPACE_ID::uint8* target, ::PROTOBUF_NAMESPACE_ID::io::EpsCopyOutputStream* stream) const final; int GetCachedSize() const final { return _cached_size_.Get(); } @@ -567,7 +567,7 @@ size_t ByteSizeLong() const final; const char* _InternalParse(const char* ptr, ::PROTOBUF_NAMESPACE_ID::internal::ParseContext* ctx) final; - ::PROTOBUF_NAMESPACE_ID::uint8* InternalSerializeWithCachedSizesToArray( + ::PROTOBUF_NAMESPACE_ID::uint8* _InternalSerialize( ::PROTOBUF_NAMESPACE_ID::uint8* target, ::PROTOBUF_NAMESPACE_ID::io::EpsCopyOutputStream* stream) const final; int GetCachedSize() const final { return _cached_size_.Get(); } @@ -758,7 +758,7 @@ size_t ByteSizeLong() const final; const char* _InternalParse(const char* ptr, ::PROTOBUF_NAMESPACE_ID::internal::ParseContext* ctx) final; - ::PROTOBUF_NAMESPACE_ID::uint8* InternalSerializeWithCachedSizesToArray( + ::PROTOBUF_NAMESPACE_ID::uint8* _InternalSerialize( ::PROTOBUF_NAMESPACE_ID::uint8* target, ::PROTOBUF_NAMESPACE_ID::io::EpsCopyOutputStream* stream) const final; int GetCachedSize() const final { return _cached_size_.Get(); } @@ -998,7 +998,7 @@ } inline std::string* Version::release_suffix() { // @@protoc_insertion_point(field_release:google.protobuf.compiler.Version.suffix) - if (!has_suffix()) { + if (!_internal_has_suffix()) { return nullptr; } _has_bits_[0] &= ~0x00000001u; @@ -1147,7 +1147,7 @@ } inline std::string* CodeGeneratorRequest::release_parameter() { // @@protoc_insertion_point(field_release:google.protobuf.compiler.CodeGeneratorRequest.parameter) - if (!has_parameter()) { + if (!_internal_has_parameter()) { return nullptr; } _has_bits_[0] &= ~0x00000001u; @@ -1318,7 +1318,7 @@ } inline std::string* CodeGeneratorResponse_File::release_name() { // @@protoc_insertion_point(field_release:google.protobuf.compiler.CodeGeneratorResponse.File.name) - if (!has_name()) { + if (!_internal_has_name()) { return nullptr; } _has_bits_[0] &= ~0x00000001u; @@ -1389,7 +1389,7 @@ } inline std::string* CodeGeneratorResponse_File::release_insertion_point() { // @@protoc_insertion_point(field_release:google.protobuf.compiler.CodeGeneratorResponse.File.insertion_point) - if (!has_insertion_point()) { + if (!_internal_has_insertion_point()) { return nullptr; } _has_bits_[0] &= ~0x00000002u; @@ -1460,7 +1460,7 @@ } inline std::string* CodeGeneratorResponse_File::release_content() { // @@protoc_insertion_point(field_release:google.protobuf.compiler.CodeGeneratorResponse.File.content) - if (!has_content()) { + if (!_internal_has_content()) { return nullptr; } _has_bits_[0] &= ~0x00000004u; @@ -1535,7 +1535,7 @@ } inline std::string* CodeGeneratorResponse::release_error() { // @@protoc_insertion_point(field_release:google.protobuf.compiler.CodeGeneratorResponse.error) - if (!has_error()) { + if (!_internal_has_error()) { return nullptr; } _has_bits_[0] &= ~0x00000001u;
diff --git a/src/google/protobuf/descriptor.cc b/src/google/protobuf/descriptor.cc index f42a85e..f50d29f 100644 --- a/src/google/protobuf/descriptor.cc +++ b/src/google/protobuf/descriptor.cc
@@ -6438,6 +6438,7 @@ std::vector<int> dest_path = options_path; for (int i = 0; i < uninterpreted_option_->name_size(); ++i) { + builder_->undefine_resolved_name_.clear(); const std::string& name_part = uninterpreted_option_->name(i).name_part(); if (debug_msg_name.size() > 0) { debug_msg_name += ".";
diff --git a/src/google/protobuf/descriptor.pb.cc b/src/google/protobuf/descriptor.pb.cc index 0af4fb1..470b292 100644 --- a/src/google/protobuf/descriptor.pb.cc +++ b/src/google/protobuf/descriptor.pb.cc
@@ -1486,7 +1486,7 @@ #undef CHK_ } -::PROTOBUF_NAMESPACE_ID::uint8* FileDescriptorSet::InternalSerializeWithCachedSizesToArray( +::PROTOBUF_NAMESPACE_ID::uint8* FileDescriptorSet::_InternalSerialize( ::PROTOBUF_NAMESPACE_ID::uint8* target, ::PROTOBUF_NAMESPACE_ID::io::EpsCopyOutputStream* stream) const { // @@protoc_insertion_point(serialize_to_array_start:google.protobuf.FileDescriptorSet) ::PROTOBUF_NAMESPACE_ID::uint32 cached_has_bits = 0; @@ -1497,7 +1497,7 @@ n = static_cast<unsigned int>(this->_internal_file_size()); i < n; i++) { target = stream->EnsureSpace(target); target = ::PROTOBUF_NAMESPACE_ID::internal::WireFormatLite:: - InternalWriteMessageToArray(1, this->_internal_file(i), target, stream); + InternalWriteMessage(1, this->_internal_file(i), target, stream); } if (PROTOBUF_PREDICT_FALSE(_internal_metadata_.have_unknown_fields())) { @@ -1572,7 +1572,7 @@ } bool FileDescriptorSet::IsInitialized() const { - if (!::PROTOBUF_NAMESPACE_ID::internal::AllAreInitialized(this->file())) return false; + if (!::PROTOBUF_NAMESPACE_ID::internal::AllAreInitialized(file_)) return false; return true; } @@ -1799,14 +1799,22 @@ // optional string name = 1; case 1: if (PROTOBUF_PREDICT_TRUE(static_cast<::PROTOBUF_NAMESPACE_ID::uint8>(tag) == 10)) { - ptr = ::PROTOBUF_NAMESPACE_ID::internal::InlineGreedyStringParserUTF8Verify(_internal_mutable_name(), ptr, ctx, "google.protobuf.FileDescriptorProto.name"); + auto str = _internal_mutable_name(); + ptr = ::PROTOBUF_NAMESPACE_ID::internal::InlineGreedyStringParser(str, ptr, ctx); + #ifndef NDEBUG + ::PROTOBUF_NAMESPACE_ID::internal::VerifyUTF8(str, "google.protobuf.FileDescriptorProto.name"); + #endif // !NDEBUG CHK_(ptr); } else goto handle_unusual; continue; // optional string package = 2; case 2: if (PROTOBUF_PREDICT_TRUE(static_cast<::PROTOBUF_NAMESPACE_ID::uint8>(tag) == 18)) { - ptr = ::PROTOBUF_NAMESPACE_ID::internal::InlineGreedyStringParserUTF8Verify(_internal_mutable_package(), ptr, ctx, "google.protobuf.FileDescriptorProto.package"); + auto str = _internal_mutable_package(); + ptr = ::PROTOBUF_NAMESPACE_ID::internal::InlineGreedyStringParser(str, ptr, ctx); + #ifndef NDEBUG + ::PROTOBUF_NAMESPACE_ID::internal::VerifyUTF8(str, "google.protobuf.FileDescriptorProto.package"); + #endif // !NDEBUG CHK_(ptr); } else goto handle_unusual; continue; @@ -1816,7 +1824,11 @@ ptr -= 1; do { ptr += 1; - ptr = ::PROTOBUF_NAMESPACE_ID::internal::InlineGreedyStringParserUTF8Verify(_internal_add_dependency(), ptr, ctx, "google.protobuf.FileDescriptorProto.dependency"); + auto str = _internal_add_dependency(); + ptr = ::PROTOBUF_NAMESPACE_ID::internal::InlineGreedyStringParser(str, ptr, ctx); + #ifndef NDEBUG + ::PROTOBUF_NAMESPACE_ID::internal::VerifyUTF8(str, "google.protobuf.FileDescriptorProto.dependency"); + #endif // !NDEBUG CHK_(ptr); if (!ctx->DataAvailable(ptr)) break; } while (::PROTOBUF_NAMESPACE_ID::internal::ExpectTag<26>(ptr)); @@ -1917,7 +1929,11 @@ // optional string syntax = 12; case 12: if (PROTOBUF_PREDICT_TRUE(static_cast<::PROTOBUF_NAMESPACE_ID::uint8>(tag) == 98)) { - ptr = ::PROTOBUF_NAMESPACE_ID::internal::InlineGreedyStringParserUTF8Verify(_internal_mutable_syntax(), ptr, ctx, "google.protobuf.FileDescriptorProto.syntax"); + auto str = _internal_mutable_syntax(); + ptr = ::PROTOBUF_NAMESPACE_ID::internal::InlineGreedyStringParser(str, ptr, ctx); + #ifndef NDEBUG + ::PROTOBUF_NAMESPACE_ID::internal::VerifyUTF8(str, "google.protobuf.FileDescriptorProto.syntax"); + #endif // !NDEBUG CHK_(ptr); } else goto handle_unusual; continue; @@ -1942,7 +1958,7 @@ #undef CHK_ } -::PROTOBUF_NAMESPACE_ID::uint8* FileDescriptorProto::InternalSerializeWithCachedSizesToArray( +::PROTOBUF_NAMESPACE_ID::uint8* FileDescriptorProto::_InternalSerialize( ::PROTOBUF_NAMESPACE_ID::uint8* target, ::PROTOBUF_NAMESPACE_ID::io::EpsCopyOutputStream* stream) const { // @@protoc_insertion_point(serialize_to_array_start:google.protobuf.FileDescriptorProto) ::PROTOBUF_NAMESPACE_ID::uint32 cached_has_bits = 0; @@ -1984,7 +2000,7 @@ n = static_cast<unsigned int>(this->_internal_message_type_size()); i < n; i++) { target = stream->EnsureSpace(target); target = ::PROTOBUF_NAMESPACE_ID::internal::WireFormatLite:: - InternalWriteMessageToArray(4, this->_internal_message_type(i), target, stream); + InternalWriteMessage(4, this->_internal_message_type(i), target, stream); } // repeated .google.protobuf.EnumDescriptorProto enum_type = 5; @@ -1992,7 +2008,7 @@ n = static_cast<unsigned int>(this->_internal_enum_type_size()); i < n; i++) { target = stream->EnsureSpace(target); target = ::PROTOBUF_NAMESPACE_ID::internal::WireFormatLite:: - InternalWriteMessageToArray(5, this->_internal_enum_type(i), target, stream); + InternalWriteMessage(5, this->_internal_enum_type(i), target, stream); } // repeated .google.protobuf.ServiceDescriptorProto service = 6; @@ -2000,7 +2016,7 @@ n = static_cast<unsigned int>(this->_internal_service_size()); i < n; i++) { target = stream->EnsureSpace(target); target = ::PROTOBUF_NAMESPACE_ID::internal::WireFormatLite:: - InternalWriteMessageToArray(6, this->_internal_service(i), target, stream); + InternalWriteMessage(6, this->_internal_service(i), target, stream); } // repeated .google.protobuf.FieldDescriptorProto extension = 7; @@ -2008,14 +2024,14 @@ n = static_cast<unsigned int>(this->_internal_extension_size()); i < n; i++) { target = stream->EnsureSpace(target); target = ::PROTOBUF_NAMESPACE_ID::internal::WireFormatLite:: - InternalWriteMessageToArray(7, this->_internal_extension(i), target, stream); + InternalWriteMessage(7, this->_internal_extension(i), target, stream); } // optional .google.protobuf.FileOptions options = 8; if (cached_has_bits & 0x00000008u) { target = stream->EnsureSpace(target); target = ::PROTOBUF_NAMESPACE_ID::internal::WireFormatLite:: - InternalWriteMessageToArray( + InternalWriteMessage( 8, _Internal::options(this), target, stream); } @@ -2023,7 +2039,7 @@ if (cached_has_bits & 0x00000010u) { target = stream->EnsureSpace(target); target = ::PROTOBUF_NAMESPACE_ID::internal::WireFormatLite:: - InternalWriteMessageToArray( + InternalWriteMessage( 9, _Internal::source_code_info(this), target, stream); } @@ -2230,12 +2246,12 @@ } bool FileDescriptorProto::IsInitialized() const { - if (!::PROTOBUF_NAMESPACE_ID::internal::AllAreInitialized(this->message_type())) return false; - if (!::PROTOBUF_NAMESPACE_ID::internal::AllAreInitialized(this->enum_type())) return false; - if (!::PROTOBUF_NAMESPACE_ID::internal::AllAreInitialized(this->service())) return false; - if (!::PROTOBUF_NAMESPACE_ID::internal::AllAreInitialized(this->extension())) return false; - if (has_options()) { - if (!this->options_->IsInitialized()) return false; + if (!::PROTOBUF_NAMESPACE_ID::internal::AllAreInitialized(message_type_)) return false; + if (!::PROTOBUF_NAMESPACE_ID::internal::AllAreInitialized(enum_type_)) return false; + if (!::PROTOBUF_NAMESPACE_ID::internal::AllAreInitialized(service_)) return false; + if (!::PROTOBUF_NAMESPACE_ID::internal::AllAreInitialized(extension_)) return false; + if (_internal_has_options()) { + if (!options_->IsInitialized()) return false; } return true; } @@ -2437,7 +2453,7 @@ #undef CHK_ } -::PROTOBUF_NAMESPACE_ID::uint8* DescriptorProto_ExtensionRange::InternalSerializeWithCachedSizesToArray( +::PROTOBUF_NAMESPACE_ID::uint8* DescriptorProto_ExtensionRange::_InternalSerialize( ::PROTOBUF_NAMESPACE_ID::uint8* target, ::PROTOBUF_NAMESPACE_ID::io::EpsCopyOutputStream* stream) const { // @@protoc_insertion_point(serialize_to_array_start:google.protobuf.DescriptorProto.ExtensionRange) ::PROTOBUF_NAMESPACE_ID::uint32 cached_has_bits = 0; @@ -2460,7 +2476,7 @@ if (cached_has_bits & 0x00000001u) { target = stream->EnsureSpace(target); target = ::PROTOBUF_NAMESPACE_ID::internal::WireFormatLite:: - InternalWriteMessageToArray( + InternalWriteMessage( 3, _Internal::options(this), target, stream); } @@ -2565,8 +2581,8 @@ } bool DescriptorProto_ExtensionRange::IsInitialized() const { - if (has_options()) { - if (!this->options_->IsInitialized()) return false; + if (_internal_has_options()) { + if (!options_->IsInitialized()) return false; } return true; } @@ -2715,7 +2731,7 @@ #undef CHK_ } -::PROTOBUF_NAMESPACE_ID::uint8* DescriptorProto_ReservedRange::InternalSerializeWithCachedSizesToArray( +::PROTOBUF_NAMESPACE_ID::uint8* DescriptorProto_ReservedRange::_InternalSerialize( ::PROTOBUF_NAMESPACE_ID::uint8* target, ::PROTOBUF_NAMESPACE_ID::io::EpsCopyOutputStream* stream) const { // @@protoc_insertion_point(serialize_to_array_start:google.protobuf.DescriptorProto.ReservedRange) ::PROTOBUF_NAMESPACE_ID::uint32 cached_has_bits = 0; @@ -2994,7 +3010,11 @@ // optional string name = 1; case 1: if (PROTOBUF_PREDICT_TRUE(static_cast<::PROTOBUF_NAMESPACE_ID::uint8>(tag) == 10)) { - ptr = ::PROTOBUF_NAMESPACE_ID::internal::InlineGreedyStringParserUTF8Verify(_internal_mutable_name(), ptr, ctx, "google.protobuf.DescriptorProto.name"); + auto str = _internal_mutable_name(); + ptr = ::PROTOBUF_NAMESPACE_ID::internal::InlineGreedyStringParser(str, ptr, ctx); + #ifndef NDEBUG + ::PROTOBUF_NAMESPACE_ID::internal::VerifyUTF8(str, "google.protobuf.DescriptorProto.name"); + #endif // !NDEBUG CHK_(ptr); } else goto handle_unusual; continue; @@ -3095,7 +3115,11 @@ ptr -= 1; do { ptr += 1; - ptr = ::PROTOBUF_NAMESPACE_ID::internal::InlineGreedyStringParserUTF8Verify(_internal_add_reserved_name(), ptr, ctx, "google.protobuf.DescriptorProto.reserved_name"); + auto str = _internal_add_reserved_name(); + ptr = ::PROTOBUF_NAMESPACE_ID::internal::InlineGreedyStringParser(str, ptr, ctx); + #ifndef NDEBUG + ::PROTOBUF_NAMESPACE_ID::internal::VerifyUTF8(str, "google.protobuf.DescriptorProto.reserved_name"); + #endif // !NDEBUG CHK_(ptr); if (!ctx->DataAvailable(ptr)) break; } while (::PROTOBUF_NAMESPACE_ID::internal::ExpectTag<82>(ptr)); @@ -3122,7 +3146,7 @@ #undef CHK_ } -::PROTOBUF_NAMESPACE_ID::uint8* DescriptorProto::InternalSerializeWithCachedSizesToArray( +::PROTOBUF_NAMESPACE_ID::uint8* DescriptorProto::_InternalSerialize( ::PROTOBUF_NAMESPACE_ID::uint8* target, ::PROTOBUF_NAMESPACE_ID::io::EpsCopyOutputStream* stream) const { // @@protoc_insertion_point(serialize_to_array_start:google.protobuf.DescriptorProto) ::PROTOBUF_NAMESPACE_ID::uint32 cached_has_bits = 0; @@ -3144,7 +3168,7 @@ n = static_cast<unsigned int>(this->_internal_field_size()); i < n; i++) { target = stream->EnsureSpace(target); target = ::PROTOBUF_NAMESPACE_ID::internal::WireFormatLite:: - InternalWriteMessageToArray(2, this->_internal_field(i), target, stream); + InternalWriteMessage(2, this->_internal_field(i), target, stream); } // repeated .google.protobuf.DescriptorProto nested_type = 3; @@ -3152,7 +3176,7 @@ n = static_cast<unsigned int>(this->_internal_nested_type_size()); i < n; i++) { target = stream->EnsureSpace(target); target = ::PROTOBUF_NAMESPACE_ID::internal::WireFormatLite:: - InternalWriteMessageToArray(3, this->_internal_nested_type(i), target, stream); + InternalWriteMessage(3, this->_internal_nested_type(i), target, stream); } // repeated .google.protobuf.EnumDescriptorProto enum_type = 4; @@ -3160,7 +3184,7 @@ n = static_cast<unsigned int>(this->_internal_enum_type_size()); i < n; i++) { target = stream->EnsureSpace(target); target = ::PROTOBUF_NAMESPACE_ID::internal::WireFormatLite:: - InternalWriteMessageToArray(4, this->_internal_enum_type(i), target, stream); + InternalWriteMessage(4, this->_internal_enum_type(i), target, stream); } // repeated .google.protobuf.DescriptorProto.ExtensionRange extension_range = 5; @@ -3168,7 +3192,7 @@ n = static_cast<unsigned int>(this->_internal_extension_range_size()); i < n; i++) { target = stream->EnsureSpace(target); target = ::PROTOBUF_NAMESPACE_ID::internal::WireFormatLite:: - InternalWriteMessageToArray(5, this->_internal_extension_range(i), target, stream); + InternalWriteMessage(5, this->_internal_extension_range(i), target, stream); } // repeated .google.protobuf.FieldDescriptorProto extension = 6; @@ -3176,14 +3200,14 @@ n = static_cast<unsigned int>(this->_internal_extension_size()); i < n; i++) { target = stream->EnsureSpace(target); target = ::PROTOBUF_NAMESPACE_ID::internal::WireFormatLite:: - InternalWriteMessageToArray(6, this->_internal_extension(i), target, stream); + InternalWriteMessage(6, this->_internal_extension(i), target, stream); } // optional .google.protobuf.MessageOptions options = 7; if (cached_has_bits & 0x00000002u) { target = stream->EnsureSpace(target); target = ::PROTOBUF_NAMESPACE_ID::internal::WireFormatLite:: - InternalWriteMessageToArray( + InternalWriteMessage( 7, _Internal::options(this), target, stream); } @@ -3192,7 +3216,7 @@ n = static_cast<unsigned int>(this->_internal_oneof_decl_size()); i < n; i++) { target = stream->EnsureSpace(target); target = ::PROTOBUF_NAMESPACE_ID::internal::WireFormatLite:: - InternalWriteMessageToArray(8, this->_internal_oneof_decl(i), target, stream); + InternalWriteMessage(8, this->_internal_oneof_decl(i), target, stream); } // repeated .google.protobuf.DescriptorProto.ReservedRange reserved_range = 9; @@ -3200,7 +3224,7 @@ n = static_cast<unsigned int>(this->_internal_reserved_range_size()); i < n; i++) { target = stream->EnsureSpace(target); target = ::PROTOBUF_NAMESPACE_ID::internal::WireFormatLite:: - InternalWriteMessageToArray(9, this->_internal_reserved_range(i), target, stream); + InternalWriteMessage(9, this->_internal_reserved_range(i), target, stream); } // repeated string reserved_name = 10; @@ -3368,14 +3392,14 @@ } bool DescriptorProto::IsInitialized() const { - if (!::PROTOBUF_NAMESPACE_ID::internal::AllAreInitialized(this->field())) return false; - if (!::PROTOBUF_NAMESPACE_ID::internal::AllAreInitialized(this->nested_type())) return false; - if (!::PROTOBUF_NAMESPACE_ID::internal::AllAreInitialized(this->enum_type())) return false; - if (!::PROTOBUF_NAMESPACE_ID::internal::AllAreInitialized(this->extension_range())) return false; - if (!::PROTOBUF_NAMESPACE_ID::internal::AllAreInitialized(this->extension())) return false; - if (!::PROTOBUF_NAMESPACE_ID::internal::AllAreInitialized(this->oneof_decl())) return false; - if (has_options()) { - if (!this->options_->IsInitialized()) return false; + if (!::PROTOBUF_NAMESPACE_ID::internal::AllAreInitialized(field_)) return false; + if (!::PROTOBUF_NAMESPACE_ID::internal::AllAreInitialized(nested_type_)) return false; + if (!::PROTOBUF_NAMESPACE_ID::internal::AllAreInitialized(enum_type_)) return false; + if (!::PROTOBUF_NAMESPACE_ID::internal::AllAreInitialized(extension_range_)) return false; + if (!::PROTOBUF_NAMESPACE_ID::internal::AllAreInitialized(extension_)) return false; + if (!::PROTOBUF_NAMESPACE_ID::internal::AllAreInitialized(oneof_decl_)) return false; + if (_internal_has_options()) { + if (!options_->IsInitialized()) return false; } return true; } @@ -3521,7 +3545,7 @@ #undef CHK_ } -::PROTOBUF_NAMESPACE_ID::uint8* ExtensionRangeOptions::InternalSerializeWithCachedSizesToArray( +::PROTOBUF_NAMESPACE_ID::uint8* ExtensionRangeOptions::_InternalSerialize( ::PROTOBUF_NAMESPACE_ID::uint8* target, ::PROTOBUF_NAMESPACE_ID::io::EpsCopyOutputStream* stream) const { // @@protoc_insertion_point(serialize_to_array_start:google.protobuf.ExtensionRangeOptions) ::PROTOBUF_NAMESPACE_ID::uint32 cached_has_bits = 0; @@ -3532,11 +3556,11 @@ n = static_cast<unsigned int>(this->_internal_uninterpreted_option_size()); i < n; i++) { target = stream->EnsureSpace(target); target = ::PROTOBUF_NAMESPACE_ID::internal::WireFormatLite:: - InternalWriteMessageToArray(999, this->_internal_uninterpreted_option(i), target, stream); + InternalWriteMessage(999, this->_internal_uninterpreted_option(i), target, stream); } // Extension range [1000, 536870912) - target = _extensions_.InternalSerializeWithCachedSizesToArray( + target = _extensions_._InternalSerialize( 1000, 536870912, target, stream); if (PROTOBUF_PREDICT_FALSE(_internal_metadata_.have_unknown_fields())) { @@ -3618,7 +3642,7 @@ return false; } - if (!::PROTOBUF_NAMESPACE_ID::internal::AllAreInitialized(this->uninterpreted_option())) return false; + if (!::PROTOBUF_NAMESPACE_ID::internal::AllAreInitialized(uninterpreted_option_)) return false; return true; } @@ -3844,14 +3868,22 @@ // optional string name = 1; case 1: if (PROTOBUF_PREDICT_TRUE(static_cast<::PROTOBUF_NAMESPACE_ID::uint8>(tag) == 10)) { - ptr = ::PROTOBUF_NAMESPACE_ID::internal::InlineGreedyStringParserUTF8Verify(_internal_mutable_name(), ptr, ctx, "google.protobuf.FieldDescriptorProto.name"); + auto str = _internal_mutable_name(); + ptr = ::PROTOBUF_NAMESPACE_ID::internal::InlineGreedyStringParser(str, ptr, ctx); + #ifndef NDEBUG + ::PROTOBUF_NAMESPACE_ID::internal::VerifyUTF8(str, "google.protobuf.FieldDescriptorProto.name"); + #endif // !NDEBUG CHK_(ptr); } else goto handle_unusual; continue; // optional string extendee = 2; case 2: if (PROTOBUF_PREDICT_TRUE(static_cast<::PROTOBUF_NAMESPACE_ID::uint8>(tag) == 18)) { - ptr = ::PROTOBUF_NAMESPACE_ID::internal::InlineGreedyStringParserUTF8Verify(_internal_mutable_extendee(), ptr, ctx, "google.protobuf.FieldDescriptorProto.extendee"); + auto str = _internal_mutable_extendee(); + ptr = ::PROTOBUF_NAMESPACE_ID::internal::InlineGreedyStringParser(str, ptr, ctx); + #ifndef NDEBUG + ::PROTOBUF_NAMESPACE_ID::internal::VerifyUTF8(str, "google.protobuf.FieldDescriptorProto.extendee"); + #endif // !NDEBUG CHK_(ptr); } else goto handle_unusual; continue; @@ -3890,14 +3922,22 @@ // optional string type_name = 6; case 6: if (PROTOBUF_PREDICT_TRUE(static_cast<::PROTOBUF_NAMESPACE_ID::uint8>(tag) == 50)) { - ptr = ::PROTOBUF_NAMESPACE_ID::internal::InlineGreedyStringParserUTF8Verify(_internal_mutable_type_name(), ptr, ctx, "google.protobuf.FieldDescriptorProto.type_name"); + auto str = _internal_mutable_type_name(); + ptr = ::PROTOBUF_NAMESPACE_ID::internal::InlineGreedyStringParser(str, ptr, ctx); + #ifndef NDEBUG + ::PROTOBUF_NAMESPACE_ID::internal::VerifyUTF8(str, "google.protobuf.FieldDescriptorProto.type_name"); + #endif // !NDEBUG CHK_(ptr); } else goto handle_unusual; continue; // optional string default_value = 7; case 7: if (PROTOBUF_PREDICT_TRUE(static_cast<::PROTOBUF_NAMESPACE_ID::uint8>(tag) == 58)) { - ptr = ::PROTOBUF_NAMESPACE_ID::internal::InlineGreedyStringParserUTF8Verify(_internal_mutable_default_value(), ptr, ctx, "google.protobuf.FieldDescriptorProto.default_value"); + auto str = _internal_mutable_default_value(); + ptr = ::PROTOBUF_NAMESPACE_ID::internal::InlineGreedyStringParser(str, ptr, ctx); + #ifndef NDEBUG + ::PROTOBUF_NAMESPACE_ID::internal::VerifyUTF8(str, "google.protobuf.FieldDescriptorProto.default_value"); + #endif // !NDEBUG CHK_(ptr); } else goto handle_unusual; continue; @@ -3919,7 +3959,11 @@ // optional string json_name = 10; case 10: if (PROTOBUF_PREDICT_TRUE(static_cast<::PROTOBUF_NAMESPACE_ID::uint8>(tag) == 82)) { - ptr = ::PROTOBUF_NAMESPACE_ID::internal::InlineGreedyStringParserUTF8Verify(_internal_mutable_json_name(), ptr, ctx, "google.protobuf.FieldDescriptorProto.json_name"); + auto str = _internal_mutable_json_name(); + ptr = ::PROTOBUF_NAMESPACE_ID::internal::InlineGreedyStringParser(str, ptr, ctx); + #ifndef NDEBUG + ::PROTOBUF_NAMESPACE_ID::internal::VerifyUTF8(str, "google.protobuf.FieldDescriptorProto.json_name"); + #endif // !NDEBUG CHK_(ptr); } else goto handle_unusual; continue; @@ -3944,7 +3988,7 @@ #undef CHK_ } -::PROTOBUF_NAMESPACE_ID::uint8* FieldDescriptorProto::InternalSerializeWithCachedSizesToArray( +::PROTOBUF_NAMESPACE_ID::uint8* FieldDescriptorProto::_InternalSerialize( ::PROTOBUF_NAMESPACE_ID::uint8* target, ::PROTOBUF_NAMESPACE_ID::io::EpsCopyOutputStream* stream) const { // @@protoc_insertion_point(serialize_to_array_start:google.protobuf.FieldDescriptorProto) ::PROTOBUF_NAMESPACE_ID::uint32 cached_has_bits = 0; @@ -4015,7 +4059,7 @@ if (cached_has_bits & 0x00000020u) { target = stream->EnsureSpace(target); target = ::PROTOBUF_NAMESPACE_ID::internal::WireFormatLite:: - InternalWriteMessageToArray( + InternalWriteMessage( 8, _Internal::options(this), target, stream); } @@ -4209,8 +4253,8 @@ } bool FieldDescriptorProto::IsInitialized() const { - if (has_options()) { - if (!this->options_->IsInitialized()) return false; + if (_internal_has_options()) { + if (!options_->IsInitialized()) return false; } return true; } @@ -4370,7 +4414,11 @@ // optional string name = 1; case 1: if (PROTOBUF_PREDICT_TRUE(static_cast<::PROTOBUF_NAMESPACE_ID::uint8>(tag) == 10)) { - ptr = ::PROTOBUF_NAMESPACE_ID::internal::InlineGreedyStringParserUTF8Verify(_internal_mutable_name(), ptr, ctx, "google.protobuf.OneofDescriptorProto.name"); + auto str = _internal_mutable_name(); + ptr = ::PROTOBUF_NAMESPACE_ID::internal::InlineGreedyStringParser(str, ptr, ctx); + #ifndef NDEBUG + ::PROTOBUF_NAMESPACE_ID::internal::VerifyUTF8(str, "google.protobuf.OneofDescriptorProto.name"); + #endif // !NDEBUG CHK_(ptr); } else goto handle_unusual; continue; @@ -4402,7 +4450,7 @@ #undef CHK_ } -::PROTOBUF_NAMESPACE_ID::uint8* OneofDescriptorProto::InternalSerializeWithCachedSizesToArray( +::PROTOBUF_NAMESPACE_ID::uint8* OneofDescriptorProto::_InternalSerialize( ::PROTOBUF_NAMESPACE_ID::uint8* target, ::PROTOBUF_NAMESPACE_ID::io::EpsCopyOutputStream* stream) const { // @@protoc_insertion_point(serialize_to_array_start:google.protobuf.OneofDescriptorProto) ::PROTOBUF_NAMESPACE_ID::uint32 cached_has_bits = 0; @@ -4423,7 +4471,7 @@ if (cached_has_bits & 0x00000002u) { target = stream->EnsureSpace(target); target = ::PROTOBUF_NAMESPACE_ID::internal::WireFormatLite:: - InternalWriteMessageToArray( + InternalWriteMessage( 2, _Internal::options(this), target, stream); } @@ -4517,8 +4565,8 @@ } bool OneofDescriptorProto::IsInitialized() const { - if (has_options()) { - if (!this->options_->IsInitialized()) return false; + if (_internal_has_options()) { + if (!options_->IsInitialized()) return false; } return true; } @@ -4667,7 +4715,7 @@ #undef CHK_ } -::PROTOBUF_NAMESPACE_ID::uint8* EnumDescriptorProto_EnumReservedRange::InternalSerializeWithCachedSizesToArray( +::PROTOBUF_NAMESPACE_ID::uint8* EnumDescriptorProto_EnumReservedRange::_InternalSerialize( ::PROTOBUF_NAMESPACE_ID::uint8* target, ::PROTOBUF_NAMESPACE_ID::io::EpsCopyOutputStream* stream) const { // @@protoc_insertion_point(serialize_to_array_start:google.protobuf.EnumDescriptorProto.EnumReservedRange) ::PROTOBUF_NAMESPACE_ID::uint32 cached_has_bits = 0; @@ -4931,7 +4979,11 @@ // optional string name = 1; case 1: if (PROTOBUF_PREDICT_TRUE(static_cast<::PROTOBUF_NAMESPACE_ID::uint8>(tag) == 10)) { - ptr = ::PROTOBUF_NAMESPACE_ID::internal::InlineGreedyStringParserUTF8Verify(_internal_mutable_name(), ptr, ctx, "google.protobuf.EnumDescriptorProto.name"); + auto str = _internal_mutable_name(); + ptr = ::PROTOBUF_NAMESPACE_ID::internal::InlineGreedyStringParser(str, ptr, ctx); + #ifndef NDEBUG + ::PROTOBUF_NAMESPACE_ID::internal::VerifyUTF8(str, "google.protobuf.EnumDescriptorProto.name"); + #endif // !NDEBUG CHK_(ptr); } else goto handle_unusual; continue; @@ -4972,7 +5024,11 @@ ptr -= 1; do { ptr += 1; - ptr = ::PROTOBUF_NAMESPACE_ID::internal::InlineGreedyStringParserUTF8Verify(_internal_add_reserved_name(), ptr, ctx, "google.protobuf.EnumDescriptorProto.reserved_name"); + auto str = _internal_add_reserved_name(); + ptr = ::PROTOBUF_NAMESPACE_ID::internal::InlineGreedyStringParser(str, ptr, ctx); + #ifndef NDEBUG + ::PROTOBUF_NAMESPACE_ID::internal::VerifyUTF8(str, "google.protobuf.EnumDescriptorProto.reserved_name"); + #endif // !NDEBUG CHK_(ptr); if (!ctx->DataAvailable(ptr)) break; } while (::PROTOBUF_NAMESPACE_ID::internal::ExpectTag<42>(ptr)); @@ -4999,7 +5055,7 @@ #undef CHK_ } -::PROTOBUF_NAMESPACE_ID::uint8* EnumDescriptorProto::InternalSerializeWithCachedSizesToArray( +::PROTOBUF_NAMESPACE_ID::uint8* EnumDescriptorProto::_InternalSerialize( ::PROTOBUF_NAMESPACE_ID::uint8* target, ::PROTOBUF_NAMESPACE_ID::io::EpsCopyOutputStream* stream) const { // @@protoc_insertion_point(serialize_to_array_start:google.protobuf.EnumDescriptorProto) ::PROTOBUF_NAMESPACE_ID::uint32 cached_has_bits = 0; @@ -5021,14 +5077,14 @@ n = static_cast<unsigned int>(this->_internal_value_size()); i < n; i++) { target = stream->EnsureSpace(target); target = ::PROTOBUF_NAMESPACE_ID::internal::WireFormatLite:: - InternalWriteMessageToArray(2, this->_internal_value(i), target, stream); + InternalWriteMessage(2, this->_internal_value(i), target, stream); } // optional .google.protobuf.EnumOptions options = 3; if (cached_has_bits & 0x00000002u) { target = stream->EnsureSpace(target); target = ::PROTOBUF_NAMESPACE_ID::internal::WireFormatLite:: - InternalWriteMessageToArray( + InternalWriteMessage( 3, _Internal::options(this), target, stream); } @@ -5037,7 +5093,7 @@ n = static_cast<unsigned int>(this->_internal_reserved_range_size()); i < n; i++) { target = stream->EnsureSpace(target); target = ::PROTOBUF_NAMESPACE_ID::internal::WireFormatLite:: - InternalWriteMessageToArray(4, this->_internal_reserved_range(i), target, stream); + InternalWriteMessage(4, this->_internal_reserved_range(i), target, stream); } // repeated string reserved_name = 5; @@ -5165,9 +5221,9 @@ } bool EnumDescriptorProto::IsInitialized() const { - if (!::PROTOBUF_NAMESPACE_ID::internal::AllAreInitialized(this->value())) return false; - if (has_options()) { - if (!this->options_->IsInitialized()) return false; + if (!::PROTOBUF_NAMESPACE_ID::internal::AllAreInitialized(value_)) return false; + if (_internal_has_options()) { + if (!options_->IsInitialized()) return false; } return true; } @@ -5325,7 +5381,11 @@ // optional string name = 1; case 1: if (PROTOBUF_PREDICT_TRUE(static_cast<::PROTOBUF_NAMESPACE_ID::uint8>(tag) == 10)) { - ptr = ::PROTOBUF_NAMESPACE_ID::internal::InlineGreedyStringParserUTF8Verify(_internal_mutable_name(), ptr, ctx, "google.protobuf.EnumValueDescriptorProto.name"); + auto str = _internal_mutable_name(); + ptr = ::PROTOBUF_NAMESPACE_ID::internal::InlineGreedyStringParser(str, ptr, ctx); + #ifndef NDEBUG + ::PROTOBUF_NAMESPACE_ID::internal::VerifyUTF8(str, "google.protobuf.EnumValueDescriptorProto.name"); + #endif // !NDEBUG CHK_(ptr); } else goto handle_unusual; continue; @@ -5365,7 +5425,7 @@ #undef CHK_ } -::PROTOBUF_NAMESPACE_ID::uint8* EnumValueDescriptorProto::InternalSerializeWithCachedSizesToArray( +::PROTOBUF_NAMESPACE_ID::uint8* EnumValueDescriptorProto::_InternalSerialize( ::PROTOBUF_NAMESPACE_ID::uint8* target, ::PROTOBUF_NAMESPACE_ID::io::EpsCopyOutputStream* stream) const { // @@protoc_insertion_point(serialize_to_array_start:google.protobuf.EnumValueDescriptorProto) ::PROTOBUF_NAMESPACE_ID::uint32 cached_has_bits = 0; @@ -5392,7 +5452,7 @@ if (cached_has_bits & 0x00000002u) { target = stream->EnsureSpace(target); target = ::PROTOBUF_NAMESPACE_ID::internal::WireFormatLite:: - InternalWriteMessageToArray( + InternalWriteMessage( 3, _Internal::options(this), target, stream); } @@ -5497,8 +5557,8 @@ } bool EnumValueDescriptorProto::IsInitialized() const { - if (has_options()) { - if (!this->options_->IsInitialized()) return false; + if (_internal_has_options()) { + if (!options_->IsInitialized()) return false; } return true; } @@ -5650,7 +5710,11 @@ // optional string name = 1; case 1: if (PROTOBUF_PREDICT_TRUE(static_cast<::PROTOBUF_NAMESPACE_ID::uint8>(tag) == 10)) { - ptr = ::PROTOBUF_NAMESPACE_ID::internal::InlineGreedyStringParserUTF8Verify(_internal_mutable_name(), ptr, ctx, "google.protobuf.ServiceDescriptorProto.name"); + auto str = _internal_mutable_name(); + ptr = ::PROTOBUF_NAMESPACE_ID::internal::InlineGreedyStringParser(str, ptr, ctx); + #ifndef NDEBUG + ::PROTOBUF_NAMESPACE_ID::internal::VerifyUTF8(str, "google.protobuf.ServiceDescriptorProto.name"); + #endif // !NDEBUG CHK_(ptr); } else goto handle_unusual; continue; @@ -5694,7 +5758,7 @@ #undef CHK_ } -::PROTOBUF_NAMESPACE_ID::uint8* ServiceDescriptorProto::InternalSerializeWithCachedSizesToArray( +::PROTOBUF_NAMESPACE_ID::uint8* ServiceDescriptorProto::_InternalSerialize( ::PROTOBUF_NAMESPACE_ID::uint8* target, ::PROTOBUF_NAMESPACE_ID::io::EpsCopyOutputStream* stream) const { // @@protoc_insertion_point(serialize_to_array_start:google.protobuf.ServiceDescriptorProto) ::PROTOBUF_NAMESPACE_ID::uint32 cached_has_bits = 0; @@ -5716,14 +5780,14 @@ n = static_cast<unsigned int>(this->_internal_method_size()); i < n; i++) { target = stream->EnsureSpace(target); target = ::PROTOBUF_NAMESPACE_ID::internal::WireFormatLite:: - InternalWriteMessageToArray(2, this->_internal_method(i), target, stream); + InternalWriteMessage(2, this->_internal_method(i), target, stream); } // optional .google.protobuf.ServiceOptions options = 3; if (cached_has_bits & 0x00000002u) { target = stream->EnsureSpace(target); target = ::PROTOBUF_NAMESPACE_ID::internal::WireFormatLite:: - InternalWriteMessageToArray( + InternalWriteMessage( 3, _Internal::options(this), target, stream); } @@ -5825,9 +5889,9 @@ } bool ServiceDescriptorProto::IsInitialized() const { - if (!::PROTOBUF_NAMESPACE_ID::internal::AllAreInitialized(this->method())) return false; - if (has_options()) { - if (!this->options_->IsInitialized()) return false; + if (!::PROTOBUF_NAMESPACE_ID::internal::AllAreInitialized(method_)) return false; + if (_internal_has_options()) { + if (!options_->IsInitialized()) return false; } return true; } @@ -6016,21 +6080,33 @@ // optional string name = 1; case 1: if (PROTOBUF_PREDICT_TRUE(static_cast<::PROTOBUF_NAMESPACE_ID::uint8>(tag) == 10)) { - ptr = ::PROTOBUF_NAMESPACE_ID::internal::InlineGreedyStringParserUTF8Verify(_internal_mutable_name(), ptr, ctx, "google.protobuf.MethodDescriptorProto.name"); + auto str = _internal_mutable_name(); + ptr = ::PROTOBUF_NAMESPACE_ID::internal::InlineGreedyStringParser(str, ptr, ctx); + #ifndef NDEBUG + ::PROTOBUF_NAMESPACE_ID::internal::VerifyUTF8(str, "google.protobuf.MethodDescriptorProto.name"); + #endif // !NDEBUG CHK_(ptr); } else goto handle_unusual; continue; // optional string input_type = 2; case 2: if (PROTOBUF_PREDICT_TRUE(static_cast<::PROTOBUF_NAMESPACE_ID::uint8>(tag) == 18)) { - ptr = ::PROTOBUF_NAMESPACE_ID::internal::InlineGreedyStringParserUTF8Verify(_internal_mutable_input_type(), ptr, ctx, "google.protobuf.MethodDescriptorProto.input_type"); + auto str = _internal_mutable_input_type(); + ptr = ::PROTOBUF_NAMESPACE_ID::internal::InlineGreedyStringParser(str, ptr, ctx); + #ifndef NDEBUG + ::PROTOBUF_NAMESPACE_ID::internal::VerifyUTF8(str, "google.protobuf.MethodDescriptorProto.input_type"); + #endif // !NDEBUG CHK_(ptr); } else goto handle_unusual; continue; // optional string output_type = 3; case 3: if (PROTOBUF_PREDICT_TRUE(static_cast<::PROTOBUF_NAMESPACE_ID::uint8>(tag) == 26)) { - ptr = ::PROTOBUF_NAMESPACE_ID::internal::InlineGreedyStringParserUTF8Verify(_internal_mutable_output_type(), ptr, ctx, "google.protobuf.MethodDescriptorProto.output_type"); + auto str = _internal_mutable_output_type(); + ptr = ::PROTOBUF_NAMESPACE_ID::internal::InlineGreedyStringParser(str, ptr, ctx); + #ifndef NDEBUG + ::PROTOBUF_NAMESPACE_ID::internal::VerifyUTF8(str, "google.protobuf.MethodDescriptorProto.output_type"); + #endif // !NDEBUG CHK_(ptr); } else goto handle_unusual; continue; @@ -6078,7 +6154,7 @@ #undef CHK_ } -::PROTOBUF_NAMESPACE_ID::uint8* MethodDescriptorProto::InternalSerializeWithCachedSizesToArray( +::PROTOBUF_NAMESPACE_ID::uint8* MethodDescriptorProto::_InternalSerialize( ::PROTOBUF_NAMESPACE_ID::uint8* target, ::PROTOBUF_NAMESPACE_ID::io::EpsCopyOutputStream* stream) const { // @@protoc_insertion_point(serialize_to_array_start:google.protobuf.MethodDescriptorProto) ::PROTOBUF_NAMESPACE_ID::uint32 cached_has_bits = 0; @@ -6119,7 +6195,7 @@ if (cached_has_bits & 0x00000008u) { target = stream->EnsureSpace(target); target = ::PROTOBUF_NAMESPACE_ID::internal::WireFormatLite:: - InternalWriteMessageToArray( + InternalWriteMessage( 4, _Internal::options(this), target, stream); } @@ -6262,8 +6338,8 @@ } bool MethodDescriptorProto::IsInitialized() const { - if (has_options()) { - if (!this->options_->IsInitialized()) return false; + if (_internal_has_options()) { + if (!options_->IsInitialized()) return false; } return true; } @@ -6556,14 +6632,22 @@ // optional string java_package = 1; case 1: if (PROTOBUF_PREDICT_TRUE(static_cast<::PROTOBUF_NAMESPACE_ID::uint8>(tag) == 10)) { - ptr = ::PROTOBUF_NAMESPACE_ID::internal::InlineGreedyStringParserUTF8Verify(_internal_mutable_java_package(), ptr, ctx, "google.protobuf.FileOptions.java_package"); + auto str = _internal_mutable_java_package(); + ptr = ::PROTOBUF_NAMESPACE_ID::internal::InlineGreedyStringParser(str, ptr, ctx); + #ifndef NDEBUG + ::PROTOBUF_NAMESPACE_ID::internal::VerifyUTF8(str, "google.protobuf.FileOptions.java_package"); + #endif // !NDEBUG CHK_(ptr); } else goto handle_unusual; continue; // optional string java_outer_classname = 8; case 8: if (PROTOBUF_PREDICT_TRUE(static_cast<::PROTOBUF_NAMESPACE_ID::uint8>(tag) == 66)) { - ptr = ::PROTOBUF_NAMESPACE_ID::internal::InlineGreedyStringParserUTF8Verify(_internal_mutable_java_outer_classname(), ptr, ctx, "google.protobuf.FileOptions.java_outer_classname"); + auto str = _internal_mutable_java_outer_classname(); + ptr = ::PROTOBUF_NAMESPACE_ID::internal::InlineGreedyStringParser(str, ptr, ctx); + #ifndef NDEBUG + ::PROTOBUF_NAMESPACE_ID::internal::VerifyUTF8(str, "google.protobuf.FileOptions.java_outer_classname"); + #endif // !NDEBUG CHK_(ptr); } else goto handle_unusual; continue; @@ -6590,7 +6674,11 @@ // optional string go_package = 11; case 11: if (PROTOBUF_PREDICT_TRUE(static_cast<::PROTOBUF_NAMESPACE_ID::uint8>(tag) == 90)) { - ptr = ::PROTOBUF_NAMESPACE_ID::internal::InlineGreedyStringParserUTF8Verify(_internal_mutable_go_package(), ptr, ctx, "google.protobuf.FileOptions.go_package"); + auto str = _internal_mutable_go_package(); + ptr = ::PROTOBUF_NAMESPACE_ID::internal::InlineGreedyStringParser(str, ptr, ctx); + #ifndef NDEBUG + ::PROTOBUF_NAMESPACE_ID::internal::VerifyUTF8(str, "google.protobuf.FileOptions.go_package"); + #endif // !NDEBUG CHK_(ptr); } else goto handle_unusual; continue; @@ -6653,35 +6741,55 @@ // optional string objc_class_prefix = 36; case 36: if (PROTOBUF_PREDICT_TRUE(static_cast<::PROTOBUF_NAMESPACE_ID::uint8>(tag) == 34)) { - ptr = ::PROTOBUF_NAMESPACE_ID::internal::InlineGreedyStringParserUTF8Verify(_internal_mutable_objc_class_prefix(), ptr, ctx, "google.protobuf.FileOptions.objc_class_prefix"); + auto str = _internal_mutable_objc_class_prefix(); + ptr = ::PROTOBUF_NAMESPACE_ID::internal::InlineGreedyStringParser(str, ptr, ctx); + #ifndef NDEBUG + ::PROTOBUF_NAMESPACE_ID::internal::VerifyUTF8(str, "google.protobuf.FileOptions.objc_class_prefix"); + #endif // !NDEBUG CHK_(ptr); } else goto handle_unusual; continue; // optional string csharp_namespace = 37; case 37: if (PROTOBUF_PREDICT_TRUE(static_cast<::PROTOBUF_NAMESPACE_ID::uint8>(tag) == 42)) { - ptr = ::PROTOBUF_NAMESPACE_ID::internal::InlineGreedyStringParserUTF8Verify(_internal_mutable_csharp_namespace(), ptr, ctx, "google.protobuf.FileOptions.csharp_namespace"); + auto str = _internal_mutable_csharp_namespace(); + ptr = ::PROTOBUF_NAMESPACE_ID::internal::InlineGreedyStringParser(str, ptr, ctx); + #ifndef NDEBUG + ::PROTOBUF_NAMESPACE_ID::internal::VerifyUTF8(str, "google.protobuf.FileOptions.csharp_namespace"); + #endif // !NDEBUG CHK_(ptr); } else goto handle_unusual; continue; // optional string swift_prefix = 39; case 39: if (PROTOBUF_PREDICT_TRUE(static_cast<::PROTOBUF_NAMESPACE_ID::uint8>(tag) == 58)) { - ptr = ::PROTOBUF_NAMESPACE_ID::internal::InlineGreedyStringParserUTF8Verify(_internal_mutable_swift_prefix(), ptr, ctx, "google.protobuf.FileOptions.swift_prefix"); + auto str = _internal_mutable_swift_prefix(); + ptr = ::PROTOBUF_NAMESPACE_ID::internal::InlineGreedyStringParser(str, ptr, ctx); + #ifndef NDEBUG + ::PROTOBUF_NAMESPACE_ID::internal::VerifyUTF8(str, "google.protobuf.FileOptions.swift_prefix"); + #endif // !NDEBUG CHK_(ptr); } else goto handle_unusual; continue; // optional string php_class_prefix = 40; case 40: if (PROTOBUF_PREDICT_TRUE(static_cast<::PROTOBUF_NAMESPACE_ID::uint8>(tag) == 66)) { - ptr = ::PROTOBUF_NAMESPACE_ID::internal::InlineGreedyStringParserUTF8Verify(_internal_mutable_php_class_prefix(), ptr, ctx, "google.protobuf.FileOptions.php_class_prefix"); + auto str = _internal_mutable_php_class_prefix(); + ptr = ::PROTOBUF_NAMESPACE_ID::internal::InlineGreedyStringParser(str, ptr, ctx); + #ifndef NDEBUG + ::PROTOBUF_NAMESPACE_ID::internal::VerifyUTF8(str, "google.protobuf.FileOptions.php_class_prefix"); + #endif // !NDEBUG CHK_(ptr); } else goto handle_unusual; continue; // optional string php_namespace = 41; case 41: if (PROTOBUF_PREDICT_TRUE(static_cast<::PROTOBUF_NAMESPACE_ID::uint8>(tag) == 74)) { - ptr = ::PROTOBUF_NAMESPACE_ID::internal::InlineGreedyStringParserUTF8Verify(_internal_mutable_php_namespace(), ptr, ctx, "google.protobuf.FileOptions.php_namespace"); + auto str = _internal_mutable_php_namespace(); + ptr = ::PROTOBUF_NAMESPACE_ID::internal::InlineGreedyStringParser(str, ptr, ctx); + #ifndef NDEBUG + ::PROTOBUF_NAMESPACE_ID::internal::VerifyUTF8(str, "google.protobuf.FileOptions.php_namespace"); + #endif // !NDEBUG CHK_(ptr); } else goto handle_unusual; continue; @@ -6696,14 +6804,22 @@ // optional string php_metadata_namespace = 44; case 44: if (PROTOBUF_PREDICT_TRUE(static_cast<::PROTOBUF_NAMESPACE_ID::uint8>(tag) == 98)) { - ptr = ::PROTOBUF_NAMESPACE_ID::internal::InlineGreedyStringParserUTF8Verify(_internal_mutable_php_metadata_namespace(), ptr, ctx, "google.protobuf.FileOptions.php_metadata_namespace"); + auto str = _internal_mutable_php_metadata_namespace(); + ptr = ::PROTOBUF_NAMESPACE_ID::internal::InlineGreedyStringParser(str, ptr, ctx); + #ifndef NDEBUG + ::PROTOBUF_NAMESPACE_ID::internal::VerifyUTF8(str, "google.protobuf.FileOptions.php_metadata_namespace"); + #endif // !NDEBUG CHK_(ptr); } else goto handle_unusual; continue; // optional string ruby_package = 45; case 45: if (PROTOBUF_PREDICT_TRUE(static_cast<::PROTOBUF_NAMESPACE_ID::uint8>(tag) == 106)) { - ptr = ::PROTOBUF_NAMESPACE_ID::internal::InlineGreedyStringParserUTF8Verify(_internal_mutable_ruby_package(), ptr, ctx, "google.protobuf.FileOptions.ruby_package"); + auto str = _internal_mutable_ruby_package(); + ptr = ::PROTOBUF_NAMESPACE_ID::internal::InlineGreedyStringParser(str, ptr, ctx); + #ifndef NDEBUG + ::PROTOBUF_NAMESPACE_ID::internal::VerifyUTF8(str, "google.protobuf.FileOptions.ruby_package"); + #endif // !NDEBUG CHK_(ptr); } else goto handle_unusual; continue; @@ -6746,7 +6862,7 @@ #undef CHK_ } -::PROTOBUF_NAMESPACE_ID::uint8* FileOptions::InternalSerializeWithCachedSizesToArray( +::PROTOBUF_NAMESPACE_ID::uint8* FileOptions::_InternalSerialize( ::PROTOBUF_NAMESPACE_ID::uint8* target, ::PROTOBUF_NAMESPACE_ID::io::EpsCopyOutputStream* stream) const { // @@protoc_insertion_point(serialize_to_array_start:google.protobuf.FileOptions) ::PROTOBUF_NAMESPACE_ID::uint32 cached_has_bits = 0; @@ -6919,11 +7035,11 @@ n = static_cast<unsigned int>(this->_internal_uninterpreted_option_size()); i < n; i++) { target = stream->EnsureSpace(target); target = ::PROTOBUF_NAMESPACE_ID::internal::WireFormatLite:: - InternalWriteMessageToArray(999, this->_internal_uninterpreted_option(i), target, stream); + InternalWriteMessage(999, this->_internal_uninterpreted_option(i), target, stream); } // Extension range [1000, 536870912) - target = _extensions_.InternalSerializeWithCachedSizesToArray( + target = _extensions_._InternalSerialize( 1000, 536870912, target, stream); if (PROTOBUF_PREDICT_FALSE(_internal_metadata_.have_unknown_fields())) { @@ -7202,7 +7318,7 @@ return false; } - if (!::PROTOBUF_NAMESPACE_ID::internal::AllAreInitialized(this->uninterpreted_option())) return false; + if (!::PROTOBUF_NAMESPACE_ID::internal::AllAreInitialized(uninterpreted_option_)) return false; return true; } @@ -7423,7 +7539,7 @@ #undef CHK_ } -::PROTOBUF_NAMESPACE_ID::uint8* MessageOptions::InternalSerializeWithCachedSizesToArray( +::PROTOBUF_NAMESPACE_ID::uint8* MessageOptions::_InternalSerialize( ::PROTOBUF_NAMESPACE_ID::uint8* target, ::PROTOBUF_NAMESPACE_ID::io::EpsCopyOutputStream* stream) const { // @@protoc_insertion_point(serialize_to_array_start:google.protobuf.MessageOptions) ::PROTOBUF_NAMESPACE_ID::uint32 cached_has_bits = 0; @@ -7459,11 +7575,11 @@ n = static_cast<unsigned int>(this->_internal_uninterpreted_option_size()); i < n; i++) { target = stream->EnsureSpace(target); target = ::PROTOBUF_NAMESPACE_ID::internal::WireFormatLite:: - InternalWriteMessageToArray(999, this->_internal_uninterpreted_option(i), target, stream); + InternalWriteMessage(999, this->_internal_uninterpreted_option(i), target, stream); } // Extension range [1000, 536870912) - target = _extensions_.InternalSerializeWithCachedSizesToArray( + target = _extensions_._InternalSerialize( 1000, 536870912, target, stream); if (PROTOBUF_PREDICT_FALSE(_internal_metadata_.have_unknown_fields())) { @@ -7584,7 +7700,7 @@ return false; } - if (!::PROTOBUF_NAMESPACE_ID::internal::AllAreInitialized(this->uninterpreted_option())) return false; + if (!::PROTOBUF_NAMESPACE_ID::internal::AllAreInitialized(uninterpreted_option_)) return false; return true; } @@ -7812,7 +7928,7 @@ #undef CHK_ } -::PROTOBUF_NAMESPACE_ID::uint8* FieldOptions::InternalSerializeWithCachedSizesToArray( +::PROTOBUF_NAMESPACE_ID::uint8* FieldOptions::_InternalSerialize( ::PROTOBUF_NAMESPACE_ID::uint8* target, ::PROTOBUF_NAMESPACE_ID::io::EpsCopyOutputStream* stream) const { // @@protoc_insertion_point(serialize_to_array_start:google.protobuf.FieldOptions) ::PROTOBUF_NAMESPACE_ID::uint32 cached_has_bits = 0; @@ -7862,11 +7978,11 @@ n = static_cast<unsigned int>(this->_internal_uninterpreted_option_size()); i < n; i++) { target = stream->EnsureSpace(target); target = ::PROTOBUF_NAMESPACE_ID::internal::WireFormatLite:: - InternalWriteMessageToArray(999, this->_internal_uninterpreted_option(i), target, stream); + InternalWriteMessage(999, this->_internal_uninterpreted_option(i), target, stream); } // Extension range [1000, 536870912) - target = _extensions_.InternalSerializeWithCachedSizesToArray( + target = _extensions_._InternalSerialize( 1000, 536870912, target, stream); if (PROTOBUF_PREDICT_FALSE(_internal_metadata_.have_unknown_fields())) { @@ -8005,7 +8121,7 @@ return false; } - if (!::PROTOBUF_NAMESPACE_ID::internal::AllAreInitialized(this->uninterpreted_option())) return false; + if (!::PROTOBUF_NAMESPACE_ID::internal::AllAreInitialized(uninterpreted_option_)) return false; return true; } @@ -8147,7 +8263,7 @@ #undef CHK_ } -::PROTOBUF_NAMESPACE_ID::uint8* OneofOptions::InternalSerializeWithCachedSizesToArray( +::PROTOBUF_NAMESPACE_ID::uint8* OneofOptions::_InternalSerialize( ::PROTOBUF_NAMESPACE_ID::uint8* target, ::PROTOBUF_NAMESPACE_ID::io::EpsCopyOutputStream* stream) const { // @@protoc_insertion_point(serialize_to_array_start:google.protobuf.OneofOptions) ::PROTOBUF_NAMESPACE_ID::uint32 cached_has_bits = 0; @@ -8158,11 +8274,11 @@ n = static_cast<unsigned int>(this->_internal_uninterpreted_option_size()); i < n; i++) { target = stream->EnsureSpace(target); target = ::PROTOBUF_NAMESPACE_ID::internal::WireFormatLite:: - InternalWriteMessageToArray(999, this->_internal_uninterpreted_option(i), target, stream); + InternalWriteMessage(999, this->_internal_uninterpreted_option(i), target, stream); } // Extension range [1000, 536870912) - target = _extensions_.InternalSerializeWithCachedSizesToArray( + target = _extensions_._InternalSerialize( 1000, 536870912, target, stream); if (PROTOBUF_PREDICT_FALSE(_internal_metadata_.have_unknown_fields())) { @@ -8244,7 +8360,7 @@ return false; } - if (!::PROTOBUF_NAMESPACE_ID::internal::AllAreInitialized(this->uninterpreted_option())) return false; + if (!::PROTOBUF_NAMESPACE_ID::internal::AllAreInitialized(uninterpreted_option_)) return false; return true; } @@ -8413,7 +8529,7 @@ #undef CHK_ } -::PROTOBUF_NAMESPACE_ID::uint8* EnumOptions::InternalSerializeWithCachedSizesToArray( +::PROTOBUF_NAMESPACE_ID::uint8* EnumOptions::_InternalSerialize( ::PROTOBUF_NAMESPACE_ID::uint8* target, ::PROTOBUF_NAMESPACE_ID::io::EpsCopyOutputStream* stream) const { // @@protoc_insertion_point(serialize_to_array_start:google.protobuf.EnumOptions) ::PROTOBUF_NAMESPACE_ID::uint32 cached_has_bits = 0; @@ -8437,11 +8553,11 @@ n = static_cast<unsigned int>(this->_internal_uninterpreted_option_size()); i < n; i++) { target = stream->EnsureSpace(target); target = ::PROTOBUF_NAMESPACE_ID::internal::WireFormatLite:: - InternalWriteMessageToArray(999, this->_internal_uninterpreted_option(i), target, stream); + InternalWriteMessage(999, this->_internal_uninterpreted_option(i), target, stream); } // Extension range [1000, 536870912) - target = _extensions_.InternalSerializeWithCachedSizesToArray( + target = _extensions_._InternalSerialize( 1000, 536870912, target, stream); if (PROTOBUF_PREDICT_FALSE(_internal_metadata_.have_unknown_fields())) { @@ -8546,7 +8662,7 @@ return false; } - if (!::PROTOBUF_NAMESPACE_ID::internal::AllAreInitialized(this->uninterpreted_option())) return false; + if (!::PROTOBUF_NAMESPACE_ID::internal::AllAreInitialized(uninterpreted_option_)) return false; return true; } @@ -8700,7 +8816,7 @@ #undef CHK_ } -::PROTOBUF_NAMESPACE_ID::uint8* EnumValueOptions::InternalSerializeWithCachedSizesToArray( +::PROTOBUF_NAMESPACE_ID::uint8* EnumValueOptions::_InternalSerialize( ::PROTOBUF_NAMESPACE_ID::uint8* target, ::PROTOBUF_NAMESPACE_ID::io::EpsCopyOutputStream* stream) const { // @@protoc_insertion_point(serialize_to_array_start:google.protobuf.EnumValueOptions) ::PROTOBUF_NAMESPACE_ID::uint32 cached_has_bits = 0; @@ -8718,11 +8834,11 @@ n = static_cast<unsigned int>(this->_internal_uninterpreted_option_size()); i < n; i++) { target = stream->EnsureSpace(target); target = ::PROTOBUF_NAMESPACE_ID::internal::WireFormatLite:: - InternalWriteMessageToArray(999, this->_internal_uninterpreted_option(i), target, stream); + InternalWriteMessage(999, this->_internal_uninterpreted_option(i), target, stream); } // Extension range [1000, 536870912) - target = _extensions_.InternalSerializeWithCachedSizesToArray( + target = _extensions_._InternalSerialize( 1000, 536870912, target, stream); if (PROTOBUF_PREDICT_FALSE(_internal_metadata_.have_unknown_fields())) { @@ -8813,7 +8929,7 @@ return false; } - if (!::PROTOBUF_NAMESPACE_ID::internal::AllAreInitialized(this->uninterpreted_option())) return false; + if (!::PROTOBUF_NAMESPACE_ID::internal::AllAreInitialized(uninterpreted_option_)) return false; return true; } @@ -8966,7 +9082,7 @@ #undef CHK_ } -::PROTOBUF_NAMESPACE_ID::uint8* ServiceOptions::InternalSerializeWithCachedSizesToArray( +::PROTOBUF_NAMESPACE_ID::uint8* ServiceOptions::_InternalSerialize( ::PROTOBUF_NAMESPACE_ID::uint8* target, ::PROTOBUF_NAMESPACE_ID::io::EpsCopyOutputStream* stream) const { // @@protoc_insertion_point(serialize_to_array_start:google.protobuf.ServiceOptions) ::PROTOBUF_NAMESPACE_ID::uint32 cached_has_bits = 0; @@ -8984,11 +9100,11 @@ n = static_cast<unsigned int>(this->_internal_uninterpreted_option_size()); i < n; i++) { target = stream->EnsureSpace(target); target = ::PROTOBUF_NAMESPACE_ID::internal::WireFormatLite:: - InternalWriteMessageToArray(999, this->_internal_uninterpreted_option(i), target, stream); + InternalWriteMessage(999, this->_internal_uninterpreted_option(i), target, stream); } // Extension range [1000, 536870912) - target = _extensions_.InternalSerializeWithCachedSizesToArray( + target = _extensions_._InternalSerialize( 1000, 536870912, target, stream); if (PROTOBUF_PREDICT_FALSE(_internal_metadata_.have_unknown_fields())) { @@ -9079,7 +9195,7 @@ return false; } - if (!::PROTOBUF_NAMESPACE_ID::internal::AllAreInitialized(this->uninterpreted_option())) return false; + if (!::PROTOBUF_NAMESPACE_ID::internal::AllAreInitialized(uninterpreted_option_)) return false; return true; } @@ -9256,7 +9372,7 @@ #undef CHK_ } -::PROTOBUF_NAMESPACE_ID::uint8* MethodOptions::InternalSerializeWithCachedSizesToArray( +::PROTOBUF_NAMESPACE_ID::uint8* MethodOptions::_InternalSerialize( ::PROTOBUF_NAMESPACE_ID::uint8* target, ::PROTOBUF_NAMESPACE_ID::io::EpsCopyOutputStream* stream) const { // @@protoc_insertion_point(serialize_to_array_start:google.protobuf.MethodOptions) ::PROTOBUF_NAMESPACE_ID::uint32 cached_has_bits = 0; @@ -9281,11 +9397,11 @@ n = static_cast<unsigned int>(this->_internal_uninterpreted_option_size()); i < n; i++) { target = stream->EnsureSpace(target); target = ::PROTOBUF_NAMESPACE_ID::internal::WireFormatLite:: - InternalWriteMessageToArray(999, this->_internal_uninterpreted_option(i), target, stream); + InternalWriteMessage(999, this->_internal_uninterpreted_option(i), target, stream); } // Extension range [1000, 536870912) - target = _extensions_.InternalSerializeWithCachedSizesToArray( + target = _extensions_._InternalSerialize( 1000, 536870912, target, stream); if (PROTOBUF_PREDICT_FALSE(_internal_metadata_.have_unknown_fields())) { @@ -9391,7 +9507,7 @@ return false; } - if (!::PROTOBUF_NAMESPACE_ID::internal::AllAreInitialized(this->uninterpreted_option())) return false; + if (!::PROTOBUF_NAMESPACE_ID::internal::AllAreInitialized(uninterpreted_option_)) return false; return true; } @@ -9509,7 +9625,11 @@ // required string name_part = 1; case 1: if (PROTOBUF_PREDICT_TRUE(static_cast<::PROTOBUF_NAMESPACE_ID::uint8>(tag) == 10)) { - ptr = ::PROTOBUF_NAMESPACE_ID::internal::InlineGreedyStringParserUTF8Verify(_internal_mutable_name_part(), ptr, ctx, "google.protobuf.UninterpretedOption.NamePart.name_part"); + auto str = _internal_mutable_name_part(); + ptr = ::PROTOBUF_NAMESPACE_ID::internal::InlineGreedyStringParser(str, ptr, ctx); + #ifndef NDEBUG + ::PROTOBUF_NAMESPACE_ID::internal::VerifyUTF8(str, "google.protobuf.UninterpretedOption.NamePart.name_part"); + #endif // !NDEBUG CHK_(ptr); } else goto handle_unusual; continue; @@ -9542,7 +9662,7 @@ #undef CHK_ } -::PROTOBUF_NAMESPACE_ID::uint8* UninterpretedOption_NamePart::InternalSerializeWithCachedSizesToArray( +::PROTOBUF_NAMESPACE_ID::uint8* UninterpretedOption_NamePart::_InternalSerialize( ::PROTOBUF_NAMESPACE_ID::uint8* target, ::PROTOBUF_NAMESPACE_ID::io::EpsCopyOutputStream* stream) const { // @@protoc_insertion_point(serialize_to_array_start:google.protobuf.UninterpretedOption.NamePart) ::PROTOBUF_NAMESPACE_ID::uint32 cached_has_bits = 0; @@ -9577,14 +9697,14 @@ // @@protoc_insertion_point(required_fields_byte_size_fallback_start:google.protobuf.UninterpretedOption.NamePart) size_t total_size = 0; - if (has_name_part()) { + if (_internal_has_name_part()) { // required string name_part = 1; total_size += 1 + ::PROTOBUF_NAMESPACE_ID::internal::WireFormatLite::StringSize( this->_internal_name_part()); } - if (has_is_extension()) { + if (_internal_has_is_extension()) { // required bool is_extension = 2; total_size += 1 + 1; } @@ -9843,7 +9963,11 @@ // optional string identifier_value = 3; case 3: if (PROTOBUF_PREDICT_TRUE(static_cast<::PROTOBUF_NAMESPACE_ID::uint8>(tag) == 26)) { - ptr = ::PROTOBUF_NAMESPACE_ID::internal::InlineGreedyStringParserUTF8Verify(_internal_mutable_identifier_value(), ptr, ctx, "google.protobuf.UninterpretedOption.identifier_value"); + auto str = _internal_mutable_identifier_value(); + ptr = ::PROTOBUF_NAMESPACE_ID::internal::InlineGreedyStringParser(str, ptr, ctx); + #ifndef NDEBUG + ::PROTOBUF_NAMESPACE_ID::internal::VerifyUTF8(str, "google.protobuf.UninterpretedOption.identifier_value"); + #endif // !NDEBUG CHK_(ptr); } else goto handle_unusual; continue; @@ -9874,14 +9998,19 @@ // optional bytes string_value = 7; case 7: if (PROTOBUF_PREDICT_TRUE(static_cast<::PROTOBUF_NAMESPACE_ID::uint8>(tag) == 58)) { - ptr = ::PROTOBUF_NAMESPACE_ID::internal::InlineGreedyStringParser(_internal_mutable_string_value(), ptr, ctx); + auto str = _internal_mutable_string_value(); + ptr = ::PROTOBUF_NAMESPACE_ID::internal::InlineGreedyStringParser(str, ptr, ctx); CHK_(ptr); } else goto handle_unusual; continue; // optional string aggregate_value = 8; case 8: if (PROTOBUF_PREDICT_TRUE(static_cast<::PROTOBUF_NAMESPACE_ID::uint8>(tag) == 66)) { - ptr = ::PROTOBUF_NAMESPACE_ID::internal::InlineGreedyStringParserUTF8Verify(_internal_mutable_aggregate_value(), ptr, ctx, "google.protobuf.UninterpretedOption.aggregate_value"); + auto str = _internal_mutable_aggregate_value(); + ptr = ::PROTOBUF_NAMESPACE_ID::internal::InlineGreedyStringParser(str, ptr, ctx); + #ifndef NDEBUG + ::PROTOBUF_NAMESPACE_ID::internal::VerifyUTF8(str, "google.protobuf.UninterpretedOption.aggregate_value"); + #endif // !NDEBUG CHK_(ptr); } else goto handle_unusual; continue; @@ -9906,7 +10035,7 @@ #undef CHK_ } -::PROTOBUF_NAMESPACE_ID::uint8* UninterpretedOption::InternalSerializeWithCachedSizesToArray( +::PROTOBUF_NAMESPACE_ID::uint8* UninterpretedOption::_InternalSerialize( ::PROTOBUF_NAMESPACE_ID::uint8* target, ::PROTOBUF_NAMESPACE_ID::io::EpsCopyOutputStream* stream) const { // @@protoc_insertion_point(serialize_to_array_start:google.protobuf.UninterpretedOption) ::PROTOBUF_NAMESPACE_ID::uint32 cached_has_bits = 0; @@ -9917,7 +10046,7 @@ n = static_cast<unsigned int>(this->_internal_name_size()); i < n; i++) { target = stream->EnsureSpace(target); target = ::PROTOBUF_NAMESPACE_ID::internal::WireFormatLite:: - InternalWriteMessageToArray(2, this->_internal_name(i), target, stream); + InternalWriteMessage(2, this->_internal_name(i), target, stream); } cached_has_bits = _has_bits_[0]; @@ -10102,7 +10231,7 @@ } bool UninterpretedOption::IsInitialized() const { - if (!::PROTOBUF_NAMESPACE_ID::internal::AllAreInitialized(this->name())) return false; + if (!::PROTOBUF_NAMESPACE_ID::internal::AllAreInitialized(name_)) return false; return true; } @@ -10264,14 +10393,22 @@ // optional string leading_comments = 3; case 3: if (PROTOBUF_PREDICT_TRUE(static_cast<::PROTOBUF_NAMESPACE_ID::uint8>(tag) == 26)) { - ptr = ::PROTOBUF_NAMESPACE_ID::internal::InlineGreedyStringParserUTF8Verify(_internal_mutable_leading_comments(), ptr, ctx, "google.protobuf.SourceCodeInfo.Location.leading_comments"); + auto str = _internal_mutable_leading_comments(); + ptr = ::PROTOBUF_NAMESPACE_ID::internal::InlineGreedyStringParser(str, ptr, ctx); + #ifndef NDEBUG + ::PROTOBUF_NAMESPACE_ID::internal::VerifyUTF8(str, "google.protobuf.SourceCodeInfo.Location.leading_comments"); + #endif // !NDEBUG CHK_(ptr); } else goto handle_unusual; continue; // optional string trailing_comments = 4; case 4: if (PROTOBUF_PREDICT_TRUE(static_cast<::PROTOBUF_NAMESPACE_ID::uint8>(tag) == 34)) { - ptr = ::PROTOBUF_NAMESPACE_ID::internal::InlineGreedyStringParserUTF8Verify(_internal_mutable_trailing_comments(), ptr, ctx, "google.protobuf.SourceCodeInfo.Location.trailing_comments"); + auto str = _internal_mutable_trailing_comments(); + ptr = ::PROTOBUF_NAMESPACE_ID::internal::InlineGreedyStringParser(str, ptr, ctx); + #ifndef NDEBUG + ::PROTOBUF_NAMESPACE_ID::internal::VerifyUTF8(str, "google.protobuf.SourceCodeInfo.Location.trailing_comments"); + #endif // !NDEBUG CHK_(ptr); } else goto handle_unusual; continue; @@ -10281,7 +10418,11 @@ ptr -= 1; do { ptr += 1; - ptr = ::PROTOBUF_NAMESPACE_ID::internal::InlineGreedyStringParserUTF8Verify(_internal_add_leading_detached_comments(), ptr, ctx, "google.protobuf.SourceCodeInfo.Location.leading_detached_comments"); + auto str = _internal_add_leading_detached_comments(); + ptr = ::PROTOBUF_NAMESPACE_ID::internal::InlineGreedyStringParser(str, ptr, ctx); + #ifndef NDEBUG + ::PROTOBUF_NAMESPACE_ID::internal::VerifyUTF8(str, "google.protobuf.SourceCodeInfo.Location.leading_detached_comments"); + #endif // !NDEBUG CHK_(ptr); if (!ctx->DataAvailable(ptr)) break; } while (::PROTOBUF_NAMESPACE_ID::internal::ExpectTag<50>(ptr)); @@ -10308,7 +10449,7 @@ #undef CHK_ } -::PROTOBUF_NAMESPACE_ID::uint8* SourceCodeInfo_Location::InternalSerializeWithCachedSizesToArray( +::PROTOBUF_NAMESPACE_ID::uint8* SourceCodeInfo_Location::_InternalSerialize( ::PROTOBUF_NAMESPACE_ID::uint8* target, ::PROTOBUF_NAMESPACE_ID::io::EpsCopyOutputStream* stream) const { // @@protoc_insertion_point(serialize_to_array_start:google.protobuf.SourceCodeInfo.Location) ::PROTOBUF_NAMESPACE_ID::uint32 cached_has_bits = 0; @@ -10625,7 +10766,7 @@ #undef CHK_ } -::PROTOBUF_NAMESPACE_ID::uint8* SourceCodeInfo::InternalSerializeWithCachedSizesToArray( +::PROTOBUF_NAMESPACE_ID::uint8* SourceCodeInfo::_InternalSerialize( ::PROTOBUF_NAMESPACE_ID::uint8* target, ::PROTOBUF_NAMESPACE_ID::io::EpsCopyOutputStream* stream) const { // @@protoc_insertion_point(serialize_to_array_start:google.protobuf.SourceCodeInfo) ::PROTOBUF_NAMESPACE_ID::uint32 cached_has_bits = 0; @@ -10636,7 +10777,7 @@ n = static_cast<unsigned int>(this->_internal_location_size()); i < n; i++) { target = stream->EnsureSpace(target); target = ::PROTOBUF_NAMESPACE_ID::internal::WireFormatLite:: - InternalWriteMessageToArray(1, this->_internal_location(i), target, stream); + InternalWriteMessage(1, this->_internal_location(i), target, stream); } if (PROTOBUF_PREDICT_FALSE(_internal_metadata_.have_unknown_fields())) { @@ -10849,7 +10990,11 @@ // optional string source_file = 2; case 2: if (PROTOBUF_PREDICT_TRUE(static_cast<::PROTOBUF_NAMESPACE_ID::uint8>(tag) == 18)) { - ptr = ::PROTOBUF_NAMESPACE_ID::internal::InlineGreedyStringParserUTF8Verify(_internal_mutable_source_file(), ptr, ctx, "google.protobuf.GeneratedCodeInfo.Annotation.source_file"); + auto str = _internal_mutable_source_file(); + ptr = ::PROTOBUF_NAMESPACE_ID::internal::InlineGreedyStringParser(str, ptr, ctx); + #ifndef NDEBUG + ::PROTOBUF_NAMESPACE_ID::internal::VerifyUTF8(str, "google.protobuf.GeneratedCodeInfo.Annotation.source_file"); + #endif // !NDEBUG CHK_(ptr); } else goto handle_unusual; continue; @@ -10890,7 +11035,7 @@ #undef CHK_ } -::PROTOBUF_NAMESPACE_ID::uint8* GeneratedCodeInfo_Annotation::InternalSerializeWithCachedSizesToArray( +::PROTOBUF_NAMESPACE_ID::uint8* GeneratedCodeInfo_Annotation::_InternalSerialize( ::PROTOBUF_NAMESPACE_ID::uint8* target, ::PROTOBUF_NAMESPACE_ID::io::EpsCopyOutputStream* stream) const { // @@protoc_insertion_point(serialize_to_array_start:google.protobuf.GeneratedCodeInfo.Annotation) ::PROTOBUF_NAMESPACE_ID::uint32 cached_has_bits = 0; @@ -11174,7 +11319,7 @@ #undef CHK_ } -::PROTOBUF_NAMESPACE_ID::uint8* GeneratedCodeInfo::InternalSerializeWithCachedSizesToArray( +::PROTOBUF_NAMESPACE_ID::uint8* GeneratedCodeInfo::_InternalSerialize( ::PROTOBUF_NAMESPACE_ID::uint8* target, ::PROTOBUF_NAMESPACE_ID::io::EpsCopyOutputStream* stream) const { // @@protoc_insertion_point(serialize_to_array_start:google.protobuf.GeneratedCodeInfo) ::PROTOBUF_NAMESPACE_ID::uint32 cached_has_bits = 0; @@ -11185,7 +11330,7 @@ n = static_cast<unsigned int>(this->_internal_annotation_size()); i < n; i++) { target = stream->EnsureSpace(target); target = ::PROTOBUF_NAMESPACE_ID::internal::WireFormatLite:: - InternalWriteMessageToArray(1, this->_internal_annotation(i), target, stream); + InternalWriteMessage(1, this->_internal_annotation(i), target, stream); } if (PROTOBUF_PREDICT_FALSE(_internal_metadata_.have_unknown_fields())) {
diff --git a/src/google/protobuf/descriptor.pb.h b/src/google/protobuf/descriptor.pb.h index 6941e2e..20912ff 100644 --- a/src/google/protobuf/descriptor.pb.h +++ b/src/google/protobuf/descriptor.pb.h
@@ -422,7 +422,7 @@ size_t ByteSizeLong() const final; const char* _InternalParse(const char* ptr, ::PROTOBUF_NAMESPACE_ID::internal::ParseContext* ctx) final; - ::PROTOBUF_NAMESPACE_ID::uint8* InternalSerializeWithCachedSizesToArray( + ::PROTOBUF_NAMESPACE_ID::uint8* _InternalSerialize( ::PROTOBUF_NAMESPACE_ID::uint8* target, ::PROTOBUF_NAMESPACE_ID::io::EpsCopyOutputStream* stream) const final; int GetCachedSize() const final { return _cached_size_.Get(); } @@ -590,7 +590,7 @@ size_t ByteSizeLong() const final; const char* _InternalParse(const char* ptr, ::PROTOBUF_NAMESPACE_ID::internal::ParseContext* ctx) final; - ::PROTOBUF_NAMESPACE_ID::uint8* InternalSerializeWithCachedSizesToArray( + ::PROTOBUF_NAMESPACE_ID::uint8* _InternalSerialize( ::PROTOBUF_NAMESPACE_ID::uint8* target, ::PROTOBUF_NAMESPACE_ID::io::EpsCopyOutputStream* stream) const final; int GetCachedSize() const final { return _cached_size_.Get(); } @@ -1025,7 +1025,7 @@ size_t ByteSizeLong() const final; const char* _InternalParse(const char* ptr, ::PROTOBUF_NAMESPACE_ID::internal::ParseContext* ctx) final; - ::PROTOBUF_NAMESPACE_ID::uint8* InternalSerializeWithCachedSizesToArray( + ::PROTOBUF_NAMESPACE_ID::uint8* _InternalSerialize( ::PROTOBUF_NAMESPACE_ID::uint8* target, ::PROTOBUF_NAMESPACE_ID::io::EpsCopyOutputStream* stream) const final; int GetCachedSize() const final { return _cached_size_.Get(); } @@ -1223,7 +1223,7 @@ size_t ByteSizeLong() const final; const char* _InternalParse(const char* ptr, ::PROTOBUF_NAMESPACE_ID::internal::ParseContext* ctx) final; - ::PROTOBUF_NAMESPACE_ID::uint8* InternalSerializeWithCachedSizesToArray( + ::PROTOBUF_NAMESPACE_ID::uint8* _InternalSerialize( ::PROTOBUF_NAMESPACE_ID::uint8* target, ::PROTOBUF_NAMESPACE_ID::io::EpsCopyOutputStream* stream) const final; int GetCachedSize() const final { return _cached_size_.Get(); } @@ -1401,7 +1401,7 @@ size_t ByteSizeLong() const final; const char* _InternalParse(const char* ptr, ::PROTOBUF_NAMESPACE_ID::internal::ParseContext* ctx) final; - ::PROTOBUF_NAMESPACE_ID::uint8* InternalSerializeWithCachedSizesToArray( + ::PROTOBUF_NAMESPACE_ID::uint8* _InternalSerialize( ::PROTOBUF_NAMESPACE_ID::uint8* target, ::PROTOBUF_NAMESPACE_ID::io::EpsCopyOutputStream* stream) const final; int GetCachedSize() const final { return _cached_size_.Get(); } @@ -1769,7 +1769,7 @@ size_t ByteSizeLong() const final; const char* _InternalParse(const char* ptr, ::PROTOBUF_NAMESPACE_ID::internal::ParseContext* ctx) final; - ::PROTOBUF_NAMESPACE_ID::uint8* InternalSerializeWithCachedSizesToArray( + ::PROTOBUF_NAMESPACE_ID::uint8* _InternalSerialize( ::PROTOBUF_NAMESPACE_ID::uint8* target, ::PROTOBUF_NAMESPACE_ID::io::EpsCopyOutputStream* stream) const final; int GetCachedSize() const final { return _cached_size_.Get(); } @@ -1940,7 +1940,7 @@ size_t ByteSizeLong() const final; const char* _InternalParse(const char* ptr, ::PROTOBUF_NAMESPACE_ID::internal::ParseContext* ctx) final; - ::PROTOBUF_NAMESPACE_ID::uint8* InternalSerializeWithCachedSizesToArray( + ::PROTOBUF_NAMESPACE_ID::uint8* _InternalSerialize( ::PROTOBUF_NAMESPACE_ID::uint8* target, ::PROTOBUF_NAMESPACE_ID::io::EpsCopyOutputStream* stream) const final; int GetCachedSize() const final { return _cached_size_.Get(); } @@ -2417,7 +2417,7 @@ size_t ByteSizeLong() const final; const char* _InternalParse(const char* ptr, ::PROTOBUF_NAMESPACE_ID::internal::ParseContext* ctx) final; - ::PROTOBUF_NAMESPACE_ID::uint8* InternalSerializeWithCachedSizesToArray( + ::PROTOBUF_NAMESPACE_ID::uint8* _InternalSerialize( ::PROTOBUF_NAMESPACE_ID::uint8* target, ::PROTOBUF_NAMESPACE_ID::io::EpsCopyOutputStream* stream) const final; int GetCachedSize() const final { return _cached_size_.Get(); } @@ -2616,7 +2616,7 @@ size_t ByteSizeLong() const final; const char* _InternalParse(const char* ptr, ::PROTOBUF_NAMESPACE_ID::internal::ParseContext* ctx) final; - ::PROTOBUF_NAMESPACE_ID::uint8* InternalSerializeWithCachedSizesToArray( + ::PROTOBUF_NAMESPACE_ID::uint8* _InternalSerialize( ::PROTOBUF_NAMESPACE_ID::uint8* target, ::PROTOBUF_NAMESPACE_ID::io::EpsCopyOutputStream* stream) const final; int GetCachedSize() const final { return _cached_size_.Get(); } @@ -2794,7 +2794,7 @@ size_t ByteSizeLong() const final; const char* _InternalParse(const char* ptr, ::PROTOBUF_NAMESPACE_ID::internal::ParseContext* ctx) final; - ::PROTOBUF_NAMESPACE_ID::uint8* InternalSerializeWithCachedSizesToArray( + ::PROTOBUF_NAMESPACE_ID::uint8* _InternalSerialize( ::PROTOBUF_NAMESPACE_ID::uint8* target, ::PROTOBUF_NAMESPACE_ID::io::EpsCopyOutputStream* stream) const final; int GetCachedSize() const final { return _cached_size_.Get(); } @@ -3061,7 +3061,7 @@ size_t ByteSizeLong() const final; const char* _InternalParse(const char* ptr, ::PROTOBUF_NAMESPACE_ID::internal::ParseContext* ctx) final; - ::PROTOBUF_NAMESPACE_ID::uint8* InternalSerializeWithCachedSizesToArray( + ::PROTOBUF_NAMESPACE_ID::uint8* _InternalSerialize( ::PROTOBUF_NAMESPACE_ID::uint8* target, ::PROTOBUF_NAMESPACE_ID::io::EpsCopyOutputStream* stream) const final; int GetCachedSize() const final { return _cached_size_.Get(); } @@ -3275,7 +3275,7 @@ size_t ByteSizeLong() const final; const char* _InternalParse(const char* ptr, ::PROTOBUF_NAMESPACE_ID::internal::ParseContext* ctx) final; - ::PROTOBUF_NAMESPACE_ID::uint8* InternalSerializeWithCachedSizesToArray( + ::PROTOBUF_NAMESPACE_ID::uint8* _InternalSerialize( ::PROTOBUF_NAMESPACE_ID::uint8* target, ::PROTOBUF_NAMESPACE_ID::io::EpsCopyOutputStream* stream) const final; int GetCachedSize() const final { return _cached_size_.Get(); } @@ -3494,7 +3494,7 @@ size_t ByteSizeLong() const final; const char* _InternalParse(const char* ptr, ::PROTOBUF_NAMESPACE_ID::internal::ParseContext* ctx) final; - ::PROTOBUF_NAMESPACE_ID::uint8* InternalSerializeWithCachedSizesToArray( + ::PROTOBUF_NAMESPACE_ID::uint8* _InternalSerialize( ::PROTOBUF_NAMESPACE_ID::uint8* target, ::PROTOBUF_NAMESPACE_ID::io::EpsCopyOutputStream* stream) const final; int GetCachedSize() const final { return _cached_size_.Get(); } @@ -3785,7 +3785,7 @@ size_t ByteSizeLong() const final; const char* _InternalParse(const char* ptr, ::PROTOBUF_NAMESPACE_ID::internal::ParseContext* ctx) final; - ::PROTOBUF_NAMESPACE_ID::uint8* InternalSerializeWithCachedSizesToArray( + ::PROTOBUF_NAMESPACE_ID::uint8* _InternalSerialize( ::PROTOBUF_NAMESPACE_ID::uint8* target, ::PROTOBUF_NAMESPACE_ID::io::EpsCopyOutputStream* stream) const final; int GetCachedSize() const final { return _cached_size_.Get(); } @@ -4448,7 +4448,7 @@ size_t ByteSizeLong() const final; const char* _InternalParse(const char* ptr, ::PROTOBUF_NAMESPACE_ID::internal::ParseContext* ctx) final; - ::PROTOBUF_NAMESPACE_ID::uint8* InternalSerializeWithCachedSizesToArray( + ::PROTOBUF_NAMESPACE_ID::uint8* _InternalSerialize( ::PROTOBUF_NAMESPACE_ID::uint8* target, ::PROTOBUF_NAMESPACE_ID::io::EpsCopyOutputStream* stream) const final; int GetCachedSize() const final { return _cached_size_.Get(); } @@ -4679,7 +4679,7 @@ size_t ByteSizeLong() const final; const char* _InternalParse(const char* ptr, ::PROTOBUF_NAMESPACE_ID::internal::ParseContext* ctx) final; - ::PROTOBUF_NAMESPACE_ID::uint8* InternalSerializeWithCachedSizesToArray( + ::PROTOBUF_NAMESPACE_ID::uint8* _InternalSerialize( ::PROTOBUF_NAMESPACE_ID::uint8* target, ::PROTOBUF_NAMESPACE_ID::io::EpsCopyOutputStream* stream) const final; int GetCachedSize() const final { return _cached_size_.Get(); } @@ -5004,7 +5004,7 @@ size_t ByteSizeLong() const final; const char* _InternalParse(const char* ptr, ::PROTOBUF_NAMESPACE_ID::internal::ParseContext* ctx) final; - ::PROTOBUF_NAMESPACE_ID::uint8* InternalSerializeWithCachedSizesToArray( + ::PROTOBUF_NAMESPACE_ID::uint8* _InternalSerialize( ::PROTOBUF_NAMESPACE_ID::uint8* target, ::PROTOBUF_NAMESPACE_ID::io::EpsCopyOutputStream* stream) const final; int GetCachedSize() const final { return _cached_size_.Get(); } @@ -5175,7 +5175,7 @@ size_t ByteSizeLong() const final; const char* _InternalParse(const char* ptr, ::PROTOBUF_NAMESPACE_ID::internal::ParseContext* ctx) final; - ::PROTOBUF_NAMESPACE_ID::uint8* InternalSerializeWithCachedSizesToArray( + ::PROTOBUF_NAMESPACE_ID::uint8* _InternalSerialize( ::PROTOBUF_NAMESPACE_ID::uint8* target, ::PROTOBUF_NAMESPACE_ID::io::EpsCopyOutputStream* stream) const final; int GetCachedSize() const final { return _cached_size_.Get(); } @@ -5376,7 +5376,7 @@ size_t ByteSizeLong() const final; const char* _InternalParse(const char* ptr, ::PROTOBUF_NAMESPACE_ID::internal::ParseContext* ctx) final; - ::PROTOBUF_NAMESPACE_ID::uint8* InternalSerializeWithCachedSizesToArray( + ::PROTOBUF_NAMESPACE_ID::uint8* _InternalSerialize( ::PROTOBUF_NAMESPACE_ID::uint8* target, ::PROTOBUF_NAMESPACE_ID::io::EpsCopyOutputStream* stream) const final; int GetCachedSize() const final { return _cached_size_.Get(); } @@ -5562,7 +5562,7 @@ size_t ByteSizeLong() const final; const char* _InternalParse(const char* ptr, ::PROTOBUF_NAMESPACE_ID::internal::ParseContext* ctx) final; - ::PROTOBUF_NAMESPACE_ID::uint8* InternalSerializeWithCachedSizesToArray( + ::PROTOBUF_NAMESPACE_ID::uint8* _InternalSerialize( ::PROTOBUF_NAMESPACE_ID::uint8* target, ::PROTOBUF_NAMESPACE_ID::io::EpsCopyOutputStream* stream) const final; int GetCachedSize() const final { return _cached_size_.Get(); } @@ -5748,7 +5748,7 @@ size_t ByteSizeLong() const final; const char* _InternalParse(const char* ptr, ::PROTOBUF_NAMESPACE_ID::internal::ParseContext* ctx) final; - ::PROTOBUF_NAMESPACE_ID::uint8* InternalSerializeWithCachedSizesToArray( + ::PROTOBUF_NAMESPACE_ID::uint8* _InternalSerialize( ::PROTOBUF_NAMESPACE_ID::uint8* target, ::PROTOBUF_NAMESPACE_ID::io::EpsCopyOutputStream* stream) const final; int GetCachedSize() const final { return _cached_size_.Get(); } @@ -5981,7 +5981,7 @@ size_t ByteSizeLong() const final; const char* _InternalParse(const char* ptr, ::PROTOBUF_NAMESPACE_ID::internal::ParseContext* ctx) final; - ::PROTOBUF_NAMESPACE_ID::uint8* InternalSerializeWithCachedSizesToArray( + ::PROTOBUF_NAMESPACE_ID::uint8* _InternalSerialize( ::PROTOBUF_NAMESPACE_ID::uint8* target, ::PROTOBUF_NAMESPACE_ID::io::EpsCopyOutputStream* stream) const final; int GetCachedSize() const final { return _cached_size_.Get(); } @@ -6178,7 +6178,7 @@ size_t ByteSizeLong() const final; const char* _InternalParse(const char* ptr, ::PROTOBUF_NAMESPACE_ID::internal::ParseContext* ctx) final; - ::PROTOBUF_NAMESPACE_ID::uint8* InternalSerializeWithCachedSizesToArray( + ::PROTOBUF_NAMESPACE_ID::uint8* _InternalSerialize( ::PROTOBUF_NAMESPACE_ID::uint8* target, ::PROTOBUF_NAMESPACE_ID::io::EpsCopyOutputStream* stream) const final; int GetCachedSize() const final { return _cached_size_.Get(); } @@ -6486,7 +6486,7 @@ size_t ByteSizeLong() const final; const char* _InternalParse(const char* ptr, ::PROTOBUF_NAMESPACE_ID::internal::ParseContext* ctx) final; - ::PROTOBUF_NAMESPACE_ID::uint8* InternalSerializeWithCachedSizesToArray( + ::PROTOBUF_NAMESPACE_ID::uint8* _InternalSerialize( ::PROTOBUF_NAMESPACE_ID::uint8* target, ::PROTOBUF_NAMESPACE_ID::io::EpsCopyOutputStream* stream) const final; int GetCachedSize() const final { return _cached_size_.Get(); } @@ -6772,7 +6772,7 @@ size_t ByteSizeLong() const final; const char* _InternalParse(const char* ptr, ::PROTOBUF_NAMESPACE_ID::internal::ParseContext* ctx) final; - ::PROTOBUF_NAMESPACE_ID::uint8* InternalSerializeWithCachedSizesToArray( + ::PROTOBUF_NAMESPACE_ID::uint8* _InternalSerialize( ::PROTOBUF_NAMESPACE_ID::uint8* target, ::PROTOBUF_NAMESPACE_ID::io::EpsCopyOutputStream* stream) const final; int GetCachedSize() const final { return _cached_size_.Get(); } @@ -6942,7 +6942,7 @@ size_t ByteSizeLong() const final; const char* _InternalParse(const char* ptr, ::PROTOBUF_NAMESPACE_ID::internal::ParseContext* ctx) final; - ::PROTOBUF_NAMESPACE_ID::uint8* InternalSerializeWithCachedSizesToArray( + ::PROTOBUF_NAMESPACE_ID::uint8* _InternalSerialize( ::PROTOBUF_NAMESPACE_ID::uint8* target, ::PROTOBUF_NAMESPACE_ID::io::EpsCopyOutputStream* stream) const final; int GetCachedSize() const final { return _cached_size_.Get(); } @@ -7176,7 +7176,7 @@ size_t ByteSizeLong() const final; const char* _InternalParse(const char* ptr, ::PROTOBUF_NAMESPACE_ID::internal::ParseContext* ctx) final; - ::PROTOBUF_NAMESPACE_ID::uint8* InternalSerializeWithCachedSizesToArray( + ::PROTOBUF_NAMESPACE_ID::uint8* _InternalSerialize( ::PROTOBUF_NAMESPACE_ID::uint8* target, ::PROTOBUF_NAMESPACE_ID::io::EpsCopyOutputStream* stream) const final; int GetCachedSize() const final { return _cached_size_.Get(); } @@ -7363,7 +7363,7 @@ } inline std::string* FileDescriptorProto::release_name() { // @@protoc_insertion_point(field_release:google.protobuf.FileDescriptorProto.name) - if (!has_name()) { + if (!_internal_has_name()) { return nullptr; } _has_bits_[0] &= ~0x00000001u; @@ -7456,7 +7456,7 @@ } inline std::string* FileDescriptorProto::release_package() { // @@protoc_insertion_point(field_release:google.protobuf.FileDescriptorProto.package) - if (!has_package()) { + if (!_internal_has_package()) { return nullptr; } _has_bits_[0] &= ~0x00000002u; @@ -8009,7 +8009,7 @@ } inline std::string* FileDescriptorProto::release_syntax() { // @@protoc_insertion_point(field_release:google.protobuf.FileDescriptorProto.syntax) - if (!has_syntax()) { + if (!_internal_has_syntax()) { return nullptr; } _has_bits_[0] &= ~0x00000004u; @@ -8294,7 +8294,7 @@ } inline std::string* DescriptorProto::release_name() { // @@protoc_insertion_point(field_release:google.protobuf.DescriptorProto.name) - if (!has_name()) { + if (!_internal_has_name()) { return nullptr; } _has_bits_[0] &= ~0x00000001u; @@ -8849,7 +8849,7 @@ } inline std::string* FieldDescriptorProto::release_name() { // @@protoc_insertion_point(field_release:google.protobuf.FieldDescriptorProto.name) - if (!has_name()) { + if (!_internal_has_name()) { return nullptr; } _has_bits_[0] &= ~0x00000001u; @@ -9028,7 +9028,7 @@ } inline std::string* FieldDescriptorProto::release_type_name() { // @@protoc_insertion_point(field_release:google.protobuf.FieldDescriptorProto.type_name) - if (!has_type_name()) { + if (!_internal_has_type_name()) { return nullptr; } _has_bits_[0] &= ~0x00000004u; @@ -9121,7 +9121,7 @@ } inline std::string* FieldDescriptorProto::release_extendee() { // @@protoc_insertion_point(field_release:google.protobuf.FieldDescriptorProto.extendee) - if (!has_extendee()) { + if (!_internal_has_extendee()) { return nullptr; } _has_bits_[0] &= ~0x00000002u; @@ -9214,7 +9214,7 @@ } inline std::string* FieldDescriptorProto::release_default_value() { // @@protoc_insertion_point(field_release:google.protobuf.FieldDescriptorProto.default_value) - if (!has_default_value()) { + if (!_internal_has_default_value()) { return nullptr; } _has_bits_[0] &= ~0x00000008u; @@ -9335,7 +9335,7 @@ } inline std::string* FieldDescriptorProto::release_json_name() { // @@protoc_insertion_point(field_release:google.protobuf.FieldDescriptorProto.json_name) - if (!has_json_name()) { + if (!_internal_has_json_name()) { return nullptr; } _has_bits_[0] &= ~0x00000010u; @@ -9500,7 +9500,7 @@ } inline std::string* OneofDescriptorProto::release_name() { // @@protoc_insertion_point(field_release:google.protobuf.OneofDescriptorProto.name) - if (!has_name()) { + if (!_internal_has_name()) { return nullptr; } _has_bits_[0] &= ~0x00000001u; @@ -9725,7 +9725,7 @@ } inline std::string* EnumDescriptorProto::release_name() { // @@protoc_insertion_point(field_release:google.protobuf.EnumDescriptorProto.name) - if (!has_name()) { + if (!_internal_has_name()) { return nullptr; } _has_bits_[0] &= ~0x00000001u; @@ -10042,7 +10042,7 @@ } inline std::string* EnumValueDescriptorProto::release_name() { // @@protoc_insertion_point(field_release:google.protobuf.EnumValueDescriptorProto.name) - if (!has_name()) { + if (!_internal_has_name()) { return nullptr; } _has_bits_[0] &= ~0x00000001u; @@ -10235,7 +10235,7 @@ } inline std::string* ServiceDescriptorProto::release_name() { // @@protoc_insertion_point(field_release:google.protobuf.ServiceDescriptorProto.name) - if (!has_name()) { + if (!_internal_has_name()) { return nullptr; } _has_bits_[0] &= ~0x00000001u; @@ -10439,7 +10439,7 @@ } inline std::string* MethodDescriptorProto::release_name() { // @@protoc_insertion_point(field_release:google.protobuf.MethodDescriptorProto.name) - if (!has_name()) { + if (!_internal_has_name()) { return nullptr; } _has_bits_[0] &= ~0x00000001u; @@ -10532,7 +10532,7 @@ } inline std::string* MethodDescriptorProto::release_input_type() { // @@protoc_insertion_point(field_release:google.protobuf.MethodDescriptorProto.input_type) - if (!has_input_type()) { + if (!_internal_has_input_type()) { return nullptr; } _has_bits_[0] &= ~0x00000002u; @@ -10625,7 +10625,7 @@ } inline std::string* MethodDescriptorProto::release_output_type() { // @@protoc_insertion_point(field_release:google.protobuf.MethodDescriptorProto.output_type) - if (!has_output_type()) { + if (!_internal_has_output_type()) { return nullptr; } _has_bits_[0] &= ~0x00000004u; @@ -10846,7 +10846,7 @@ } inline std::string* FileOptions::release_java_package() { // @@protoc_insertion_point(field_release:google.protobuf.FileOptions.java_package) - if (!has_java_package()) { + if (!_internal_has_java_package()) { return nullptr; } _has_bits_[0] &= ~0x00000001u; @@ -10939,7 +10939,7 @@ } inline std::string* FileOptions::release_java_outer_classname() { // @@protoc_insertion_point(field_release:google.protobuf.FileOptions.java_outer_classname) - if (!has_java_outer_classname()) { + if (!_internal_has_java_outer_classname()) { return nullptr; } _has_bits_[0] &= ~0x00000002u; @@ -11145,7 +11145,7 @@ } inline std::string* FileOptions::release_go_package() { // @@protoc_insertion_point(field_release:google.protobuf.FileOptions.go_package) - if (!has_go_package()) { + if (!_internal_has_go_package()) { return nullptr; } _has_bits_[0] &= ~0x00000004u; @@ -11406,7 +11406,7 @@ } inline std::string* FileOptions::release_objc_class_prefix() { // @@protoc_insertion_point(field_release:google.protobuf.FileOptions.objc_class_prefix) - if (!has_objc_class_prefix()) { + if (!_internal_has_objc_class_prefix()) { return nullptr; } _has_bits_[0] &= ~0x00000008u; @@ -11499,7 +11499,7 @@ } inline std::string* FileOptions::release_csharp_namespace() { // @@protoc_insertion_point(field_release:google.protobuf.FileOptions.csharp_namespace) - if (!has_csharp_namespace()) { + if (!_internal_has_csharp_namespace()) { return nullptr; } _has_bits_[0] &= ~0x00000010u; @@ -11592,7 +11592,7 @@ } inline std::string* FileOptions::release_swift_prefix() { // @@protoc_insertion_point(field_release:google.protobuf.FileOptions.swift_prefix) - if (!has_swift_prefix()) { + if (!_internal_has_swift_prefix()) { return nullptr; } _has_bits_[0] &= ~0x00000020u; @@ -11685,7 +11685,7 @@ } inline std::string* FileOptions::release_php_class_prefix() { // @@protoc_insertion_point(field_release:google.protobuf.FileOptions.php_class_prefix) - if (!has_php_class_prefix()) { + if (!_internal_has_php_class_prefix()) { return nullptr; } _has_bits_[0] &= ~0x00000040u; @@ -11778,7 +11778,7 @@ } inline std::string* FileOptions::release_php_namespace() { // @@protoc_insertion_point(field_release:google.protobuf.FileOptions.php_namespace) - if (!has_php_namespace()) { + if (!_internal_has_php_namespace()) { return nullptr; } _has_bits_[0] &= ~0x00000080u; @@ -11871,7 +11871,7 @@ } inline std::string* FileOptions::release_php_metadata_namespace() { // @@protoc_insertion_point(field_release:google.protobuf.FileOptions.php_metadata_namespace) - if (!has_php_metadata_namespace()) { + if (!_internal_has_php_metadata_namespace()) { return nullptr; } _has_bits_[0] &= ~0x00000100u; @@ -11964,7 +11964,7 @@ } inline std::string* FileOptions::release_ruby_package() { // @@protoc_insertion_point(field_release:google.protobuf.FileOptions.ruby_package) - if (!has_ruby_package()) { + if (!_internal_has_ruby_package()) { return nullptr; } _has_bits_[0] &= ~0x00000200u; @@ -12852,7 +12852,7 @@ } inline std::string* UninterpretedOption_NamePart::release_name_part() { // @@protoc_insertion_point(field_release:google.protobuf.UninterpretedOption.NamePart.name_part) - if (!has_name_part()) { + if (!_internal_has_name_part()) { return nullptr; } _has_bits_[0] &= ~0x00000001u; @@ -13016,7 +13016,7 @@ } inline std::string* UninterpretedOption::release_identifier_value() { // @@protoc_insertion_point(field_release:google.protobuf.UninterpretedOption.identifier_value) - if (!has_identifier_value()) { + if (!_internal_has_identifier_value()) { return nullptr; } _has_bits_[0] &= ~0x00000001u; @@ -13193,7 +13193,7 @@ } inline std::string* UninterpretedOption::release_string_value() { // @@protoc_insertion_point(field_release:google.protobuf.UninterpretedOption.string_value) - if (!has_string_value()) { + if (!_internal_has_string_value()) { return nullptr; } _has_bits_[0] &= ~0x00000002u; @@ -13286,7 +13286,7 @@ } inline std::string* UninterpretedOption::release_aggregate_value() { // @@protoc_insertion_point(field_release:google.protobuf.UninterpretedOption.aggregate_value) - if (!has_aggregate_value()) { + if (!_internal_has_aggregate_value()) { return nullptr; } _has_bits_[0] &= ~0x00000004u; @@ -13477,7 +13477,7 @@ } inline std::string* SourceCodeInfo_Location::release_leading_comments() { // @@protoc_insertion_point(field_release:google.protobuf.SourceCodeInfo.Location.leading_comments) - if (!has_leading_comments()) { + if (!_internal_has_leading_comments()) { return nullptr; } _has_bits_[0] &= ~0x00000001u; @@ -13570,7 +13570,7 @@ } inline std::string* SourceCodeInfo_Location::release_trailing_comments() { // @@protoc_insertion_point(field_release:google.protobuf.SourceCodeInfo.Location.trailing_comments) - if (!has_trailing_comments()) { + if (!_internal_has_trailing_comments()) { return nullptr; } _has_bits_[0] &= ~0x00000002u; @@ -13831,7 +13831,7 @@ } inline std::string* GeneratedCodeInfo_Annotation::release_source_file() { // @@protoc_insertion_point(field_release:google.protobuf.GeneratedCodeInfo.Annotation.source_file) - if (!has_source_file()) { + if (!_internal_has_source_file()) { return nullptr; } _has_bits_[0] &= ~0x00000001u;
diff --git a/src/google/protobuf/descriptor_unittest.cc b/src/google/protobuf/descriptor_unittest.cc index a2926e9..898c1da 100644 --- a/src/google/protobuf/descriptor_unittest.cc +++ b/src/google/protobuf/descriptor_unittest.cc
@@ -1902,7 +1902,7 @@ EXPECT_EQ(20, foo_->extension_range(0)->end); EXPECT_EQ(40, foo_->extension_range(1)->end); -}; +} TEST_F(ExtensionDescriptorTest, Extensions) { EXPECT_EQ(0, foo_->extension_count()); @@ -1947,7 +1947,7 @@ EXPECT_TRUE(foo_file_->extension(1)->extension_scope() == nullptr); EXPECT_EQ(bar_, bar_->extension(0)->extension_scope()); EXPECT_EQ(bar_, bar_->extension(1)->extension_scope()); -}; +} TEST_F(ExtensionDescriptorTest, IsExtensionNumber) { EXPECT_FALSE(foo_->IsExtensionNumber(9)); @@ -2095,7 +2095,7 @@ EXPECT_EQ(15, foo_->reserved_range(2)->start); EXPECT_EQ(16, foo_->reserved_range(2)->end); -}; +} TEST_F(ReservedDescriptorTest, IsReservedNumber) { EXPECT_FALSE(foo_->IsReservedNumber(1)); @@ -2110,20 +2110,20 @@ EXPECT_FALSE(foo_->IsReservedNumber(14)); EXPECT_TRUE(foo_->IsReservedNumber(15)); EXPECT_FALSE(foo_->IsReservedNumber(16)); -}; +} TEST_F(ReservedDescriptorTest, ReservedNames) { ASSERT_EQ(2, foo_->reserved_name_count()); EXPECT_EQ("foo", foo_->reserved_name(0)); EXPECT_EQ("bar", foo_->reserved_name(1)); -}; +} TEST_F(ReservedDescriptorTest, IsReservedName) { EXPECT_TRUE(foo_->IsReservedName("foo")); EXPECT_TRUE(foo_->IsReservedName("bar")); EXPECT_FALSE(foo_->IsReservedName("baz")); -}; +} // ===================================================================
diff --git a/src/google/protobuf/duration.pb.cc b/src/google/protobuf/duration.pb.cc index 4d13304..5677506 100644 --- a/src/google/protobuf/duration.pb.cc +++ b/src/google/protobuf/duration.pb.cc
@@ -195,7 +195,7 @@ #undef CHK_ } -::PROTOBUF_NAMESPACE_ID::uint8* Duration::InternalSerializeWithCachedSizesToArray( +::PROTOBUF_NAMESPACE_ID::uint8* Duration::_InternalSerialize( ::PROTOBUF_NAMESPACE_ID::uint8* target, ::PROTOBUF_NAMESPACE_ID::io::EpsCopyOutputStream* stream) const { // @@protoc_insertion_point(serialize_to_array_start:google.protobuf.Duration) ::PROTOBUF_NAMESPACE_ID::uint32 cached_has_bits = 0;
diff --git a/src/google/protobuf/duration.pb.h b/src/google/protobuf/duration.pb.h index 456d69f..804361d 100644 --- a/src/google/protobuf/duration.pb.h +++ b/src/google/protobuf/duration.pb.h
@@ -151,7 +151,7 @@ size_t ByteSizeLong() const final; const char* _InternalParse(const char* ptr, ::PROTOBUF_NAMESPACE_ID::internal::ParseContext* ctx) final; - ::PROTOBUF_NAMESPACE_ID::uint8* InternalSerializeWithCachedSizesToArray( + ::PROTOBUF_NAMESPACE_ID::uint8* _InternalSerialize( ::PROTOBUF_NAMESPACE_ID::uint8* target, ::PROTOBUF_NAMESPACE_ID::io::EpsCopyOutputStream* stream) const final; int GetCachedSize() const final { return _cached_size_.Get(); }
diff --git a/src/google/protobuf/dynamic_message.h b/src/google/protobuf/dynamic_message.h index a0de9f3..9bd609f 100644 --- a/src/google/protobuf/dynamic_message.h +++ b/src/google/protobuf/dynamic_message.h
@@ -44,7 +44,6 @@ #include <google/protobuf/stubs/common.h> #include <google/protobuf/message.h> -#include <google/protobuf/reflection.h> #include <google/protobuf/stubs/mutex.h> #include <google/protobuf/reflection.h> #include <google/protobuf/repeated_field.h>
diff --git a/src/google/protobuf/empty.pb.cc b/src/google/protobuf/empty.pb.cc index 2beb8b7..5fb1993 100644 --- a/src/google/protobuf/empty.pb.cc +++ b/src/google/protobuf/empty.pb.cc
@@ -148,8 +148,6 @@ ::PROTOBUF_NAMESPACE_ID::uint32 tag; ptr = ::PROTOBUF_NAMESPACE_ID::internal::ReadTag(ptr, &tag); CHK_(ptr); - switch (tag >> 3) { - default: { if ((tag & 7) == 4 || tag == 0) { ctx->SetLastTag(tag); goto success; @@ -157,8 +155,6 @@ ptr = UnknownFieldParse(tag, &_internal_metadata_, ptr, ctx); CHK_(ptr != nullptr); continue; - } - } // switch } // while success: return ptr; @@ -168,7 +164,7 @@ #undef CHK_ } -::PROTOBUF_NAMESPACE_ID::uint8* Empty::InternalSerializeWithCachedSizesToArray( +::PROTOBUF_NAMESPACE_ID::uint8* Empty::_InternalSerialize( ::PROTOBUF_NAMESPACE_ID::uint8* target, ::PROTOBUF_NAMESPACE_ID::io::EpsCopyOutputStream* stream) const { // @@protoc_insertion_point(serialize_to_array_start:google.protobuf.Empty) ::PROTOBUF_NAMESPACE_ID::uint32 cached_has_bits = 0;
diff --git a/src/google/protobuf/empty.pb.h b/src/google/protobuf/empty.pb.h index 6f0ff98..71d3d20 100644 --- a/src/google/protobuf/empty.pb.h +++ b/src/google/protobuf/empty.pb.h
@@ -151,7 +151,7 @@ size_t ByteSizeLong() const final; const char* _InternalParse(const char* ptr, ::PROTOBUF_NAMESPACE_ID::internal::ParseContext* ctx) final; - ::PROTOBUF_NAMESPACE_ID::uint8* InternalSerializeWithCachedSizesToArray( + ::PROTOBUF_NAMESPACE_ID::uint8* _InternalSerialize( ::PROTOBUF_NAMESPACE_ID::uint8* target, ::PROTOBUF_NAMESPACE_ID::io::EpsCopyOutputStream* stream) const final; int GetCachedSize() const final { return _cached_size_.Get(); }
diff --git a/src/google/protobuf/extension_set.cc b/src/google/protobuf/extension_set.cc index 6d404fc..b4eb6e1 100644 --- a/src/google/protobuf/extension_set.cc +++ b/src/google/protobuf/extension_set.cc
@@ -1462,9 +1462,9 @@ return ParseMessageSetLite(input, &finder, &skipper); } -uint8* ExtensionSet::InternalSerializeWithCachedSizesToArray( - int start_field_number, int end_field_number, uint8* target, - io::EpsCopyOutputStream* stream) const { +uint8* ExtensionSet::_InternalSerialize(int start_field_number, + int end_field_number, uint8* target, + io::EpsCopyOutputStream* stream) const { if (PROTOBUF_PREDICT_FALSE(is_large())) { const auto& end = map_.large->end(); for (auto it = map_.large->lower_bound(start_field_number); @@ -2010,7 +2010,7 @@ case WireFormatLite::TYPE_##UPPERCASE: \ for (int i = 0; i < repeated_##LOWERCASE##_value->size(); i++) { \ target = stream->EnsureSpace(target); \ - target = WireFormatLite::InternalWrite##CAMELCASE##ToArray( \ + target = WireFormatLite::InternalWrite##CAMELCASE( \ number, repeated_##LOWERCASE##_value->Get(i), target, stream); \ } \ break @@ -2053,8 +2053,8 @@ #undef HANDLE_TYPE case WireFormatLite::TYPE_GROUP: target = stream->EnsureSpace(target); - target = WireFormatLite::InternalWriteGroupToArray( - number, *message_value, target, stream); + target = WireFormatLite::InternalWriteGroup(number, *message_value, + target, stream); break; case WireFormatLite::TYPE_MESSAGE: if (is_lazy) { @@ -2062,8 +2062,8 @@ lazymessage_value->WriteMessageToArray(number, target, stream); } else { target = stream->EnsureSpace(target); - target = WireFormatLite::InternalWriteMessageToArray( - number, *message_value, target, stream); + target = WireFormatLite::InternalWriteMessage(number, *message_value, + target, stream); } break; } @@ -2094,7 +2094,7 @@ target = lazymessage_value->WriteMessageToArray( WireFormatLite::kMessageSetMessageNumber, target, stream); } else { - target = WireFormatLite::InternalWriteMessageToArray( + target = WireFormatLite::InternalWriteMessage( WireFormatLite::kMessageSetMessageNumber, *message_value, target, stream); }
diff --git a/src/google/protobuf/extension_set.h b/src/google/protobuf/extension_set.h index b704147..222f6db 100644 --- a/src/google/protobuf/extension_set.h +++ b/src/google/protobuf/extension_set.h
@@ -458,9 +458,8 @@ // last called. Note that the range bounds are inclusive-exclusive. void SerializeWithCachedSizes(int start_field_number, int end_field_number, io::CodedOutputStream* output) const { - output->SetCur(InternalSerializeWithCachedSizesToArray( - start_field_number, end_field_number, output->Cur(), - output->EpsCopy())); + output->SetCur(_InternalSerialize(start_field_number, end_field_number, + output->Cur(), output->EpsCopy())); } // Same as SerializeWithCachedSizes, but without any bounds checking. @@ -468,9 +467,9 @@ // serialized extensions. // // Returns a pointer past the last written byte. - uint8* InternalSerializeWithCachedSizesToArray( - int start_field_number, int end_field_number, uint8* target, - io::EpsCopyOutputStream* stream) const; + uint8* _InternalSerialize(int start_field_number, int end_field_number, + uint8* target, + io::EpsCopyOutputStream* stream) const; // Like above but serializes in MessageSet format. void SerializeMessageSetWithCachedSizes(io::CodedOutputStream* output) const {
diff --git a/src/google/protobuf/field_mask.pb.cc b/src/google/protobuf/field_mask.pb.cc index 81c9ec4..78c343f 100644 --- a/src/google/protobuf/field_mask.pb.cc +++ b/src/google/protobuf/field_mask.pb.cc
@@ -161,7 +161,9 @@ ptr -= 1; do { ptr += 1; - ptr = ::PROTOBUF_NAMESPACE_ID::internal::InlineGreedyStringParserUTF8(_internal_add_paths(), ptr, ctx, "google.protobuf.FieldMask.paths"); + auto str = _internal_add_paths(); + ptr = ::PROTOBUF_NAMESPACE_ID::internal::InlineGreedyStringParser(str, ptr, ctx); + CHK_(::PROTOBUF_NAMESPACE_ID::internal::VerifyUTF8(str, "google.protobuf.FieldMask.paths")); CHK_(ptr); if (!ctx->DataAvailable(ptr)) break; } while (::PROTOBUF_NAMESPACE_ID::internal::ExpectTag<10>(ptr)); @@ -187,7 +189,7 @@ #undef CHK_ } -::PROTOBUF_NAMESPACE_ID::uint8* FieldMask::InternalSerializeWithCachedSizesToArray( +::PROTOBUF_NAMESPACE_ID::uint8* FieldMask::_InternalSerialize( ::PROTOBUF_NAMESPACE_ID::uint8* target, ::PROTOBUF_NAMESPACE_ID::io::EpsCopyOutputStream* stream) const { // @@protoc_insertion_point(serialize_to_array_start:google.protobuf.FieldMask) ::PROTOBUF_NAMESPACE_ID::uint32 cached_has_bits = 0;
diff --git a/src/google/protobuf/field_mask.pb.h b/src/google/protobuf/field_mask.pb.h index d38333b..cce1e1b 100644 --- a/src/google/protobuf/field_mask.pb.h +++ b/src/google/protobuf/field_mask.pb.h
@@ -151,7 +151,7 @@ size_t ByteSizeLong() const final; const char* _InternalParse(const char* ptr, ::PROTOBUF_NAMESPACE_ID::internal::ParseContext* ctx) final; - ::PROTOBUF_NAMESPACE_ID::uint8* InternalSerializeWithCachedSizesToArray( + ::PROTOBUF_NAMESPACE_ID::uint8* _InternalSerialize( ::PROTOBUF_NAMESPACE_ID::uint8* target, ::PROTOBUF_NAMESPACE_ID::io::EpsCopyOutputStream* stream) const final; int GetCachedSize() const final { return _cached_size_.Get(); }
diff --git a/src/google/protobuf/field_mask.proto b/src/google/protobuf/field_mask.proto index 4015b1a..baac874 100644 --- a/src/google/protobuf/field_mask.proto +++ b/src/google/protobuf/field_mask.proto
@@ -238,7 +238,7 @@ // // The implementation of any API method which has a FieldMask type field in the // request should verify the included field paths, and return an -// `INVALID_ARGUMENT` error if any path is duplicated or unmappable. +// `INVALID_ARGUMENT` error if any path is unmappable. message FieldMask { // The set of field mask paths. repeated string paths = 1;
diff --git a/src/google/protobuf/generated_message_reflection.cc b/src/google/protobuf/generated_message_reflection.cc index b169bf1..9641ebd 100644 --- a/src/google/protobuf/generated_message_reflection.cc +++ b/src/google/protobuf/generated_message_reflection.cc
@@ -2079,19 +2079,19 @@ } } -#define HANDLE_TYPE(TYPE, CPPTYPE, CTYPE) \ - template <> \ - const RepeatedField<TYPE>& Reflection::GetRepeatedField<TYPE>( \ - const Message& message, const FieldDescriptor* field) const { \ - return *static_cast<RepeatedField<TYPE>*>(MutableRawRepeatedField( \ - const_cast<Message*>(&message), field, CPPTYPE, CTYPE, NULL)); \ - } \ - \ - template <> \ - RepeatedField<TYPE>* Reflection::MutableRepeatedField<TYPE>( \ - Message * message, const FieldDescriptor* field) const { \ - return static_cast<RepeatedField<TYPE>*>( \ - MutableRawRepeatedField(message, field, CPPTYPE, CTYPE, NULL)); \ +#define HANDLE_TYPE(TYPE, CPPTYPE, CTYPE) \ + template <> \ + const RepeatedField<TYPE>& Reflection::GetRepeatedFieldInternal<TYPE>( \ + const Message& message, const FieldDescriptor* field) const { \ + return *static_cast<RepeatedField<TYPE>*>(MutableRawRepeatedField( \ + const_cast<Message*>(&message), field, CPPTYPE, CTYPE, NULL)); \ + } \ + \ + template <> \ + RepeatedField<TYPE>* Reflection::MutableRepeatedFieldInternal<TYPE>( \ + Message * message, const FieldDescriptor* field) const { \ + return static_cast<RepeatedField<TYPE>*>( \ + MutableRawRepeatedField(message, field, CPPTYPE, CTYPE, NULL)); \ } HANDLE_TYPE(int32, FieldDescriptor::CPPTYPE_INT32, -1);
diff --git a/src/google/protobuf/generated_message_util.h b/src/google/protobuf/generated_message_util.h index ecb8c0a..9754675 100644 --- a/src/google/protobuf/generated_message_util.h +++ b/src/google/protobuf/generated_message_util.h
@@ -39,17 +39,20 @@ #define GOOGLE_PROTOBUF_GENERATED_MESSAGE_UTIL_H__ #include <assert.h> + #include <atomic> #include <climits> #include <string> #include <vector> #include <google/protobuf/stubs/common.h> +#include <google/protobuf/any.h> #include <google/protobuf/has_bits.h> #include <google/protobuf/implicit_weak_message.h> #include <google/protobuf/message_lite.h> #include <google/protobuf/stubs/once.h> // Add direct dep on port for pb.cc #include <google/protobuf/port.h> +#include <google/protobuf/repeated_field.h> #include <google/protobuf/wire_format_lite.h> #include <google/protobuf/stubs/strutil.h> #include <google/protobuf/stubs/casts.h> @@ -95,8 +98,8 @@ // helper here to keep the protobuf compiler from ever having to emit loops in // IsInitialized() methods. We want the C++ compiler to inline this or not // as it sees fit. -template <class Type> -bool AllAreInitialized(const Type& t) { +template <typename Msg> +bool AllAreInitialized(const RepeatedPtrField<Msg>& t) { for (int i = t.size(); --i >= 0;) { if (!t.Get(i).IsInitialized()) return false; }
diff --git a/src/google/protobuf/implicit_weak_message.h b/src/google/protobuf/implicit_weak_message.h index e8f1959..a3348da 100644 --- a/src/google/protobuf/implicit_weak_message.h +++ b/src/google/protobuf/implicit_weak_message.h
@@ -82,8 +82,8 @@ size_t ByteSizeLong() const override { return data_.size(); } - uint8* InternalSerializeWithCachedSizesToArray( - uint8* target, io::EpsCopyOutputStream* stream) const final { + uint8* _InternalSerialize(uint8* target, + io::EpsCopyOutputStream* stream) const final { return stream->WriteRaw(data_.data(), static_cast<int>(data_.size()), target); }
diff --git a/src/google/protobuf/io/strtod.cc b/src/google/protobuf/io/strtod.cc index 01164441..03acb5b 100644 --- a/src/google/protobuf/io/strtod.cc +++ b/src/google/protobuf/io/strtod.cc
@@ -38,81 +38,16 @@ #include <google/protobuf/stubs/logging.h> #include <google/protobuf/stubs/common.h> +#include <google/protobuf/stubs/strutil.h> + namespace google { namespace protobuf { namespace io { -// ---------------------------------------------------------------------- -// NoLocaleStrtod() -// This code will make you cry. -// ---------------------------------------------------------------------- - -namespace { - // This approximately 0x1.ffffffp127, but we don't use 0x1.ffffffp127 because // it won't compile in MSVC. const double MAX_FLOAT_AS_DOUBLE_ROUNDED = 3.4028235677973366e+38; -// Returns a string identical to *input except that the character pointed to -// by radix_pos (which should be '.') is replaced with the locale-specific -// radix character. -std::string LocalizeRadix(const char* input, const char* radix_pos) { - // Determine the locale-specific radix character by calling sprintf() to - // print the number 1.5, then stripping off the digits. As far as I can - // tell, this is the only portable, thread-safe way to get the C library - // to divuldge the locale's radix character. No, localeconv() is NOT - // thread-safe. - char temp[16]; - int size = sprintf(temp, "%.1f", 1.5); - GOOGLE_CHECK_EQ(temp[0], '1'); - GOOGLE_CHECK_EQ(temp[size - 1], '5'); - GOOGLE_CHECK_LE(size, 6); - - // Now replace the '.' in the input with it. - std::string result; - result.reserve(strlen(input) + size - 3); - result.append(input, radix_pos); - result.append(temp + 1, size - 2); - result.append(radix_pos + 1); - return result; -} - -} // namespace - -double NoLocaleStrtod(const char* text, char** original_endptr) { - // We cannot simply set the locale to "C" temporarily with setlocale() - // as this is not thread-safe. Instead, we try to parse in the current - // locale first. If parsing stops at a '.' character, then this is a - // pretty good hint that we're actually in some other locale in which - // '.' is not the radix character. - - char* temp_endptr; - double result = strtod(text, &temp_endptr); - if (original_endptr != NULL) *original_endptr = temp_endptr; - if (*temp_endptr != '.') return result; - - // Parsing halted on a '.'. Perhaps we're in a different locale? Let's - // try to replace the '.' with a locale-specific radix character and - // try again. - std::string localized = LocalizeRadix(text, temp_endptr); - const char* localized_cstr = localized.c_str(); - char* localized_endptr; - result = strtod(localized_cstr, &localized_endptr); - if ((localized_endptr - localized_cstr) > (temp_endptr - text)) { - // This attempt got further, so replacing the decimal must have helped. - // Update original_endptr to point at the right location. - if (original_endptr != NULL) { - // size_diff is non-zero if the localized radix has multiple bytes. - int size_diff = localized.size() - strlen(text); - // const_cast is necessary to match the strtod() interface. - *original_endptr = const_cast<char*>( - text + (localized_endptr - localized_cstr - size_diff)); - } - } - - return result; -} - float SafeDoubleToFloat(double value) { // static_cast<float> on a number larger than float can result in illegal // instruction error, so we need to manually convert it to infinity or max. @@ -138,6 +73,10 @@ } } +double NoLocaleStrtod(const char* str, char** endptr) { + return google::protobuf::internal::NoLocaleStrtod(str, endptr); +} + } // namespace io } // namespace protobuf } // namespace google
diff --git a/src/google/protobuf/map_entry_lite.h b/src/google/protobuf/map_entry_lite.h index fbc57a4..d35b98c 100644 --- a/src/google/protobuf/map_entry_lite.h +++ b/src/google/protobuf/map_entry_lite.h
@@ -128,7 +128,8 @@ // Tags for key and value will both be one byte (field numbers 1 and 2). size_t inner_length = 2 + KeyTypeHandler::ByteSize(key) + ValueTypeHandler::ByteSize(value); - return inner_length + io::CodedOutputStream::VarintSize32(static_cast<uint32>(inner_length)); + return inner_length + io::CodedOutputStream::VarintSize32( + static_cast<uint32>(inner_length)); } static int GetCachedSize(const Key& key, const Value& value) { @@ -275,8 +276,8 @@ return size; } - ::google::protobuf::uint8* InternalSerializeWithCachedSizesToArray( - ::google::protobuf::uint8* ptr, io::EpsCopyOutputStream* stream) const override { + ::google::protobuf::uint8* _InternalSerialize(::google::protobuf::uint8* ptr, + io::EpsCopyOutputStream* stream) const override { ptr = KeyTypeHandler::Write(kKeyFieldNumber, key(), ptr, stream); return ValueTypeHandler::Write(kValueFieldNumber, value(), ptr, stream); }
diff --git a/src/google/protobuf/map_field.h b/src/google/protobuf/map_field.h index 091a0b7..38bf26a 100644 --- a/src/google/protobuf/map_field.h +++ b/src/google/protobuf/map_field.h
@@ -36,6 +36,7 @@ #include <google/protobuf/arena.h> #include <google/protobuf/descriptor.h> #include <google/protobuf/generated_message_reflection.h> +#include <google/protobuf/generated_message_util.h> #include <google/protobuf/map_entry.h> #include <google/protobuf/map_field_lite.h> #include <google/protobuf/map_type_handler.h> @@ -311,6 +312,20 @@ GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(MapField); }; +template <typename Derived, typename Key, typename T, + WireFormatLite::FieldType key_wire_type, + WireFormatLite::FieldType value_wire_type, int default_enum_value> +bool AllAreInitialized( + const MapField<Derived, Key, T, key_wire_type, value_wire_type, + default_enum_value>& field) { + const auto& t = field.GetMap(); + for (typename Map<Key, T>::const_iterator it = t.begin(); it != t.end(); + ++it) { + if (!it->second.IsInitialized()) return false; + } + return true; +} + template <typename T, typename Key, typename Value, WireFormatLite::FieldType kKeyFieldType, WireFormatLite::FieldType kValueFieldType, int default_enum_value>
diff --git a/src/google/protobuf/map_field_lite.h b/src/google/protobuf/map_field_lite.h index 91b098d..3f2f632 100644 --- a/src/google/protobuf/map_field_lite.h +++ b/src/google/protobuf/map_field_lite.h
@@ -153,8 +153,13 @@ // expected to be message. It's useful to have this helper here to keep the // protobuf compiler from ever having to emit loops in IsInitialized() methods. // We want the C++ compiler to inline this or not as it sees fit. -template <typename Key, typename T> -bool AllAreInitialized(const Map<Key, T>& t) { +template <typename Derived, typename Key, typename T, + WireFormatLite::FieldType key_wire_type, + WireFormatLite::FieldType value_wire_type, int default_enum_value> +bool AllAreInitialized( + const MapFieldLite<Derived, Key, T, key_wire_type, value_wire_type, + default_enum_value>& field) { + const auto& t = field.GetMap(); for (typename Map<Key, T>::const_iterator it = t.begin(); it != t.end(); ++it) { if (!it->second.IsInitialized()) return false;
diff --git a/src/google/protobuf/map_type_handler.h b/src/google/protobuf/map_type_handler.h index f1d8d04..d63a10c 100644 --- a/src/google/protobuf/map_type_handler.h +++ b/src/google/protobuf/map_type_handler.h
@@ -363,7 +363,7 @@ int field, const MapEntryAccessorType& value, uint8* ptr, io::EpsCopyOutputStream* stream) { ptr = stream->EnsureSpace(ptr); - return WireFormatLite::InternalWriteMessageToArray(field, value, ptr, stream); + return WireFormatLite::InternalWriteMessage(field, value, ptr, stream); } #define WRITE_METHOD(FieldType, DeclaredType) \
diff --git a/src/google/protobuf/message.cc b/src/google/protobuf/message.cc index 09446ee..5d768b9 100644 --- a/src/google/protobuf/message.cc +++ b/src/google/protobuf/message.cc
@@ -241,10 +241,11 @@ const Reflection* reflection, const char* ptr, internal::ParseContext* ctx) { switch (field->type()) { -#define HANDLE_PACKED_TYPE(TYPE, CPPTYPE, METHOD_NAME) \ - case FieldDescriptor::TYPE_##TYPE: \ - return internal::Packed##METHOD_NAME##Parser( \ - reflection->MutableRepeatedField<CPPTYPE>(msg, field), ptr, ctx) +#define HANDLE_PACKED_TYPE(TYPE, CPPTYPE, METHOD_NAME) \ + case FieldDescriptor::TYPE_##TYPE: \ + return internal::Packed##METHOD_NAME##Parser( \ + reflection->MutableRepeatedFieldInternal<CPPTYPE>(msg, field), ptr, \ + ctx) HANDLE_PACKED_TYPE(INT32, int32, Int32); HANDLE_PACKED_TYPE(INT64, int64, Int64); HANDLE_PACKED_TYPE(SINT32, int32, SInt32); @@ -291,17 +292,13 @@ const char* field_name = nullptr; auto parse_string = [ptr, ctx, &utf8_level, &field_name](std::string* s) -> const char* { - switch (utf8_level) { - case kNone: - return internal::InlineGreedyStringParser(s, ptr, ctx); - case kVerify: - return internal::InlineGreedyStringParserUTF8Verify(s, ptr, ctx, - field_name); - case kStrict: - return internal::InlineGreedyStringParserUTF8(s, ptr, ctx, field_name); + auto res = internal::InlineGreedyStringParser(s, ptr, ctx); + if (utf8_level != kNone) { + if (!internal::VerifyUTF8(s, field_name) && utf8_level == kStrict) { + return nullptr; + } } - GOOGLE_LOG(FATAL) << "Should not reach here"; - return nullptr; // Make compiler happy + return res; }; switch (field->type()) { case FieldDescriptor::TYPE_STRING: { @@ -324,12 +321,14 @@ if (field->options().ctype() == FieldOptions::STRING || field->is_extension()) { auto object = - reflection->MutableRepeatedPtrField<std::string>(msg, field) + reflection + ->MutableRepeatedPtrFieldInternal<std::string>(msg, field) ->Mutable(index); return parse_string(object); } else { auto object = - reflection->MutableRepeatedPtrField<std::string>(msg, field) + reflection + ->MutableRepeatedPtrFieldInternal<std::string>(msg, field) ->Mutable(index); return parse_string(object); } @@ -490,7 +489,7 @@ // If that failed, check if the field is an extension. if (field == nullptr && descriptor_->IsExtensionNumber(num)) { const DescriptorPool* pool = ctx_->data().pool; - if (pool == NULL) { + if (pool == nullptr) { field = reflection_->FindKnownExtensionByNumber(num); } else { field = pool->FindExtensionByNumber(descriptor_, num); @@ -521,10 +520,9 @@ return internal::WireFormatParser(field_parser, ptr, ctx); } -uint8* Message::InternalSerializeWithCachedSizesToArray( - uint8* target, io::EpsCopyOutputStream* stream) const { - return WireFormat::InternalSerializeWithCachedSizesToArray(*this, target, - stream); +uint8* Message::_InternalSerialize(uint8* target, + io::EpsCopyOutputStream* stream) const { + return WireFormat::_InternalSerialize(*this, target, stream); } size_t Message::ByteSizeLong() const {
diff --git a/src/google/protobuf/message.h b/src/google/protobuf/message.h index 92aa1f1..237ba73 100644 --- a/src/google/protobuf/message.h +++ b/src/google/protobuf/message.h
@@ -304,8 +304,8 @@ const char* _InternalParse(const char* ptr, internal::ParseContext* ctx) override; size_t ByteSizeLong() const override; - uint8* InternalSerializeWithCachedSizesToArray( - uint8* target, io::EpsCopyOutputStream* stream) const override; + uint8* _InternalSerialize(uint8* target, + io::EpsCopyOutputStream* stream) const override; private: // This is called only by the default implementation of ByteSize(), to @@ -747,16 +747,20 @@ // for T = Cord and all protobuf scalar types except enums. template <typename T> PROTOBUF_DEPRECATED_MSG("Please use GetRepeatedFieldRef() instead") - const RepeatedField<T>& GetRepeatedField(const Message&, - const FieldDescriptor*) const; + const RepeatedField<T>& GetRepeatedField(const Message& msg, + const FieldDescriptor* d) const { + return GetRepeatedFieldInternal<T>(msg, d); + } // DEPRECATED. Please use GetMutableRepeatedFieldRef(). // // for T = Cord and all protobuf scalar types except enums. template <typename T> PROTOBUF_DEPRECATED_MSG("Please use GetMutableRepeatedFieldRef() instead") - RepeatedField<T>* MutableRepeatedField(Message*, - const FieldDescriptor*) const; + RepeatedField<T>* MutableRepeatedField(Message* msg, + const FieldDescriptor* d) const { + return MutableRepeatedFieldInternal<T>(msg, d); + } // DEPRECATED. Please use GetRepeatedFieldRef(). // @@ -764,8 +768,10 @@ // google::protobuf::Message & descendants. template <typename T> PROTOBUF_DEPRECATED_MSG("Please use GetRepeatedFieldRef() instead") - const RepeatedPtrField<T>& GetRepeatedPtrField(const Message&, - const FieldDescriptor*) const; + const RepeatedPtrField<T>& GetRepeatedPtrField( + const Message& msg, const FieldDescriptor* d) const { + return GetRepeatedPtrFieldInternal<T>(msg, d); + } // DEPRECATED. Please use GetMutableRepeatedFieldRef(). // @@ -773,22 +779,20 @@ // google::protobuf::Message & descendants. template <typename T> PROTOBUF_DEPRECATED_MSG("Please use GetMutableRepeatedFieldRef() instead") - RepeatedPtrField<T>* MutableRepeatedPtrField(Message*, - const FieldDescriptor*) const; + RepeatedPtrField<T>* MutableRepeatedPtrField(Message* msg, + const FieldDescriptor* d) const { + return MutableRepeatedPtrFieldInternal<T>(msg, d); + } // Extensions ---------------------------------------------------------------- // Try to find an extension of this message type by fully-qualified field // name. Returns nullptr if no extension is known for this name or number. - PROTOBUF_DEPRECATED_MSG( - "Please use DescriptorPool::FindExtensionByPrintableName instead") const FieldDescriptor* FindKnownExtensionByName( const std::string& name) const; // Try to find an extension of this message type by field number. // Returns nullptr if no extension is known for this name or number. - PROTOBUF_DEPRECATED_MSG( - "Please use DescriptorPool::FindExtensionByNumber instead") const FieldDescriptor* FindKnownExtensionByNumber(int number) const; // Feature Flags ------------------------------------------------------------- @@ -835,6 +839,18 @@ MessageFactory* GetMessageFactory() const; private: + template <typename T> + const RepeatedField<T>& GetRepeatedFieldInternal( + const Message& message, const FieldDescriptor* field) const; + template <typename T> + RepeatedField<T>* MutableRepeatedFieldInternal( + Message* message, const FieldDescriptor* field) const; + template <typename T> + const RepeatedPtrField<T>& GetRepeatedPtrFieldInternal( + const Message& message, const FieldDescriptor* field) const; + template <typename T> + RepeatedPtrField<T>* MutableRepeatedPtrFieldInternal( + Message* message, const FieldDescriptor* field) const; // Obtain a pointer to a Repeated Field Structure and do some type checking: // on field->cpp_type(), // on field->field_option().ctype() (if ctype >= 0) @@ -1059,6 +1075,17 @@ friend inline // inline so nobody can call this function. void RegisterAllTypesInternal(const Metadata* file_level_metadata, int size); + friend inline const char* ParseLenDelim(int field_number, + const FieldDescriptor* field, + Message* msg, + const Reflection* reflection, + const char* ptr, + internal::ParseContext* ctx); + friend inline const char* ParsePackedField(const FieldDescriptor* field, + Message* msg, + const Reflection* reflection, + const char* ptr, + internal::ParseContext* ctx); GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(Reflection); }; @@ -1127,14 +1154,15 @@ GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(MessageFactory); }; -#define DECLARE_GET_REPEATED_FIELD(TYPE) \ - template <> \ - PROTOBUF_EXPORT const RepeatedField<TYPE>& \ - Reflection::GetRepeatedField<TYPE>(const Message& message, \ - const FieldDescriptor* field) const; \ - \ - template <> \ - PROTOBUF_EXPORT RepeatedField<TYPE>* Reflection::MutableRepeatedField<TYPE>( \ +#define DECLARE_GET_REPEATED_FIELD(TYPE) \ + template <> \ + PROTOBUF_EXPORT const RepeatedField<TYPE>& \ + Reflection::GetRepeatedFieldInternal<TYPE>( \ + const Message& message, const FieldDescriptor* field) const; \ + \ + template <> \ + PROTOBUF_EXPORT RepeatedField<TYPE>* \ + Reflection::MutableRepeatedFieldInternal<TYPE>( \ Message * message, const FieldDescriptor* field) const; DECLARE_GET_REPEATED_FIELD(int32) @@ -1213,7 +1241,7 @@ template <> inline const RepeatedPtrField<std::string>& -Reflection::GetRepeatedPtrField<std::string>( +Reflection::GetRepeatedPtrFieldInternal<std::string>( const Message& message, const FieldDescriptor* field) const { return *static_cast<RepeatedPtrField<std::string>*>( MutableRawRepeatedString(const_cast<Message*>(&message), field, true)); @@ -1221,7 +1249,7 @@ template <> inline RepeatedPtrField<std::string>* -Reflection::MutableRepeatedPtrField<std::string>( +Reflection::MutableRepeatedPtrFieldInternal<std::string>( Message* message, const FieldDescriptor* field) const { return static_cast<RepeatedPtrField<std::string>*>( MutableRawRepeatedString(message, field, true)); @@ -1231,21 +1259,21 @@ // ----- template <> -inline const RepeatedPtrField<Message>& Reflection::GetRepeatedPtrField( +inline const RepeatedPtrField<Message>& Reflection::GetRepeatedPtrFieldInternal( const Message& message, const FieldDescriptor* field) const { return *static_cast<const RepeatedPtrField<Message>*>(GetRawRepeatedField( message, field, FieldDescriptor::CPPTYPE_MESSAGE, -1, nullptr)); } template <> -inline RepeatedPtrField<Message>* Reflection::MutableRepeatedPtrField( +inline RepeatedPtrField<Message>* Reflection::MutableRepeatedPtrFieldInternal( Message* message, const FieldDescriptor* field) const { return static_cast<RepeatedPtrField<Message>*>(MutableRawRepeatedField( message, field, FieldDescriptor::CPPTYPE_MESSAGE, -1, nullptr)); } template <typename PB> -inline const RepeatedPtrField<PB>& Reflection::GetRepeatedPtrField( +inline const RepeatedPtrField<PB>& Reflection::GetRepeatedPtrFieldInternal( const Message& message, const FieldDescriptor* field) const { return *static_cast<const RepeatedPtrField<PB>*>( GetRawRepeatedField(message, field, FieldDescriptor::CPPTYPE_MESSAGE, -1, @@ -1253,7 +1281,7 @@ } template <typename PB> -inline RepeatedPtrField<PB>* Reflection::MutableRepeatedPtrField( +inline RepeatedPtrField<PB>* Reflection::MutableRepeatedPtrFieldInternal( Message* message, const FieldDescriptor* field) const { return static_cast<RepeatedPtrField<PB>*>( MutableRawRepeatedField(message, field, FieldDescriptor::CPPTYPE_MESSAGE,
diff --git a/src/google/protobuf/message_lite.cc b/src/google/protobuf/message_lite.cc index 9a892c6..4f5cc5f 100644 --- a/src/google/protobuf/message_lite.cc +++ b/src/google/protobuf/message_lite.cc
@@ -53,6 +53,7 @@ #include <google/protobuf/repeated_field.h> #include <google/protobuf/stubs/strutil.h> #include <google/protobuf/stubs/stl_util.h> +#include <google/protobuf/stubs/mutex.h> #include <google/protobuf/port_def.inc> @@ -316,7 +317,7 @@ io::EpsCopyOutputStream out( &stream, io::CodedOutputStream::IsDefaultSerializationDeterministic(), &ptr); - ptr = msg.InternalSerializeWithCachedSizesToArray(ptr, &out); + ptr = msg._InternalSerialize(ptr, &out); out.Trim(ptr); GOOGLE_DCHECK(!out.HadError() && stream.ByteCount() == size); return target + size; @@ -324,7 +325,7 @@ io::EpsCopyOutputStream out( target, size, io::CodedOutputStream::IsDefaultSerializationDeterministic()); - auto res = msg.InternalSerializeWithCachedSizesToArray(target, &out); + auto res = msg._InternalSerialize(target, &out); GOOGLE_DCHECK(target + size == res); return res; } @@ -384,7 +385,7 @@ io::EpsCopyOutputStream stream( output, io::CodedOutputStream::IsDefaultSerializationDeterministic(), &target); - target = InternalSerializeWithCachedSizesToArray(target, &stream); + target = _InternalSerialize(target, &stream); stream.Trim(target); if (stream.HadError()) return false; return true; @@ -499,5 +500,53 @@ } // namespace internal + +// =================================================================== +// Shutdown support. + +namespace internal { + +struct ShutdownData { + ~ShutdownData() { + std::reverse(functions.begin(), functions.end()); + for (auto pair : functions) pair.first(pair.second); + } + + static ShutdownData* get() { + static auto* data = new ShutdownData; + return data; + } + + std::vector<std::pair<void (*)(const void*), const void*>> functions; + Mutex mutex; +}; + +static void RunZeroArgFunc(const void* arg) { + void (*func)() = reinterpret_cast<void (*)()>(const_cast<void*>(arg)); + func(); +} + +void OnShutdown(void (*func)()) { + OnShutdownRun(RunZeroArgFunc, reinterpret_cast<void*>(func)); +} + +void OnShutdownRun(void (*f)(const void*), const void* arg) { + auto shutdown_data = ShutdownData::get(); + MutexLock lock(&shutdown_data->mutex); + shutdown_data->functions.push_back(std::make_pair(f, arg)); +} + +} // namespace internal + +void ShutdownProtobufLibrary() { + // This function should be called only once, but accepts multiple calls. + static bool is_shutdown = false; + if (!is_shutdown) { + delete internal::ShutdownData::get(); + is_shutdown = true; + } +} + + } // namespace protobuf } // namespace google
diff --git a/src/google/protobuf/message_lite.h b/src/google/protobuf/message_lite.h index 0b718a0..31746f3 100644 --- a/src/google/protobuf/message_lite.h +++ b/src/google/protobuf/message_lite.h
@@ -405,8 +405,7 @@ // have changed since the last call to ByteSize(), and the value returned by // ByteSize must be non-negative. Otherwise the results are undefined. void SerializeWithCachedSizes(io::CodedOutputStream* output) const { - output->SetCur(InternalSerializeWithCachedSizesToArray(output->Cur(), - output->EpsCopy())); + output->SetCur(_InternalSerialize(output->Cur(), output->EpsCopy())); } // Functions below here are not part of the public interface. It isn't @@ -461,9 +460,9 @@ bool ParseFrom(const T& input); // Fast path when conditions match (ie. non-deterministic) - // uint8* InternalSerializeWithCachedSizesToArray(uint8* ptr) const; - virtual uint8* InternalSerializeWithCachedSizesToArray( - uint8* ptr, io::EpsCopyOutputStream* stream) const = 0; + // uint8* _InternalSerialize(uint8* ptr) const; + virtual uint8* _InternalSerialize(uint8* ptr, + io::EpsCopyOutputStream* stream) const = 0; private: // TODO(gerbens) make this a pure abstract function @@ -530,6 +529,40 @@ return res && ((flags & kMergePartial) || IsInitializedWithErrors()); } +// =================================================================== +// Shutdown support. + + +// Shut down the entire protocol buffers library, deleting all static-duration +// objects allocated by the library or by generated .pb.cc files. +// +// There are two reasons you might want to call this: +// * You use a draconian definition of "memory leak" in which you expect +// every single malloc() to have a corresponding free(), even for objects +// which live until program exit. +// * You are writing a dynamically-loaded library which needs to clean up +// after itself when the library is unloaded. +// +// It is safe to call this multiple times. However, it is not safe to use +// any other part of the protocol buffers library after +// ShutdownProtobufLibrary() has been called. Furthermore this call is not +// thread safe, user needs to synchronize multiple calls. +PROTOBUF_EXPORT void ShutdownProtobufLibrary(); + +namespace internal { + +// Register a function to be called when ShutdownProtocolBuffers() is called. +PROTOBUF_EXPORT void OnShutdown(void (*func)()); +// Run an arbitrary function on an arg +PROTOBUF_EXPORT void OnShutdownRun(void (*f)(const void*), const void* arg); + +template <typename T> +T* OnShutdownDelete(T* p) { + OnShutdownRun([](const void* pp) { delete static_cast<const T*>(pp); }, p); + return p; +} + +} // namespace internal } // namespace protobuf } // namespace google
diff --git a/src/google/protobuf/parse_context.cc b/src/google/protobuf/parse_context.cc index 1d78ee6..76b0f3b 100644 --- a/src/google/protobuf/parse_context.cc +++ b/src/google/protobuf/parse_context.cc
@@ -424,14 +424,6 @@ return ctx->ReadString(ptr, size, s); } -const char* InlineGreedyStringParserUTF8(std::string* s, const char* ptr, - ParseContext* ctx, - const char* field_name) { - auto p = InlineGreedyStringParser(s, ptr, ctx); - GOOGLE_PROTOBUF_PARSER_ASSERT(VerifyUTF8(*s, field_name)); - return p; -} - template <typename T, bool sign> const char* VarintParser(void* object, const char* ptr, ParseContext* ctx) {
diff --git a/src/google/protobuf/parse_context.h b/src/google/protobuf/parse_context.h index fb634f4..921ea51 100644 --- a/src/google/protobuf/parse_context.h +++ b/src/google/protobuf/parse_context.h
@@ -37,6 +37,7 @@ #include <google/protobuf/io/coded_stream.h> #include <google/protobuf/io/zero_copy_stream.h> +#include <google/protobuf/arena.h> #include <google/protobuf/arenastring.h> #include <google/protobuf/implicit_weak_message.h> #include <google/protobuf/metadata_lite.h> @@ -627,26 +628,14 @@ PROTOBUF_EXPORT bool VerifyUTF8(StringPiece s, const char* field_name); +inline bool VerifyUTF8(const std::string* s, const char* field_name) { + return VerifyUTF8(*s, field_name); +} + // All the string parsers with or without UTF checking and for all CTypes. PROTOBUF_EXPORT PROTOBUF_MUST_USE_RESULT const char* InlineGreedyStringParser( std::string* s, const char* ptr, ParseContext* ctx); -PROTOBUF_EXPORT PROTOBUF_MUST_USE_RESULT const char* -InlineGreedyStringParserUTF8(std::string* s, const char* ptr, ParseContext* ctx, - const char* field_name); -// Inline because we don't want to pay the price of field_name in opt mode. -inline PROTOBUF_MUST_USE_RESULT const char* InlineGreedyStringParserUTF8Verify( - std::string* s, const char* ptr, ParseContext* ctx, - const char* field_name) { - auto p = InlineGreedyStringParser(s, ptr, ctx); -#ifndef NDEBUG - VerifyUTF8(*s, field_name); -#else // !NDEBUG - (void)field_name; -#endif // !NDEBUG - return p; -} - // Add any of the following lines to debug which parse function is failing.
diff --git a/src/google/protobuf/port_def.inc b/src/google/protobuf/port_def.inc index b6e5626..39cb6bd 100644 --- a/src/google/protobuf/port_def.inc +++ b/src/google/protobuf/port_def.inc
@@ -149,9 +149,11 @@ #if defined(__GNUC__) || defined(__clang__) #define PROTOBUF_DEPRECATED __attribute__((deprecated)) +#define PROTOBUF_DEPRECATED_ENUM __attribute__((deprecated)) #define PROTOBUF_DEPRECATED_MSG(msg) __attribute__((deprecated(msg))) #elif defined(_MSC_VER) #define PROTOBUF_DEPRECATED __declspec(deprecated) +#define PROTOBUF_DEPRECATED_ENUM #define PROTOBUF_DEPRECATED_MSG(msg) __declspec(deprecated(msg)) #endif @@ -341,28 +343,20 @@ #if defined(PROTOBUF_USE_DLLS) #if defined(_MSC_VER) #ifdef LIBPROTOBUF_EXPORTS - #define PROTOBUF_EXPORT __declspec(dllexport) - #define PROTOBUF_EXPORT_TEMPLATE_DECLARE - #define PROTOBUF_EXPORT_TEMPLATE_DEFINE __declspec(dllexport) + #define PROTOBUF_EXPORT __declspec(dllexport) #else - #define PROTOBUF_EXPORT __declspec(dllimport) - #define PROTOBUF_EXPORT_TEMPLATE_DECLARE - #define PROTOBUF_EXPORT_TEMPLATE_DEFINE __declspec(dllimport) + #define PROTOBUF_EXPORT __declspec(dllimport) #endif #ifdef LIBPROTOC_EXPORTS - #define PROTOC_EXPORT __declspec(dllexport) + #define PROTOC_EXPORT __declspec(dllexport) #else - #define PROTOC_EXPORT __declspec(dllimport) + #define PROTOC_EXPORT __declspec(dllimport) #endif #else // defined(_MSC_VER) #ifdef LIBPROTOBUF_EXPORTS #define PROTOBUF_EXPORT __attribute__((visibility("default"))) - #define PROTOBUF_EXPORT_TEMPLATE_DECLARE __attribute__((visibility("default"))) - #define PROTOBUF_EXPORT_TEMPLATE_DEFINE #else #define PROTOBUF_EXPORT - #define PROTOBUF_EXPORT_TEMPLATE_DECLARE - #define PROTOBUF_EXPORT_TEMPLATE_DEFINE #endif #ifdef LIBPROTOC_EXPORTS #define PROTOC_EXPORT __attribute__((visibility("default"))) @@ -373,10 +367,168 @@ #else // defined(PROTOBUF_USE_DLLS) #define PROTOBUF_EXPORT #define PROTOC_EXPORT - #define PROTOBUF_EXPORT_TEMPLATE_DECLARE - #define PROTOBUF_EXPORT_TEMPLATE_DEFINE #endif + +// This portion provides macros for using FOO_EXPORT macros with explicit +// template instantiation declarations and definitions. +// Generally, the FOO_EXPORT macros are used at declarations, +// and GCC requires them to be used at explicit instantiation declarations, +// but MSVC requires __declspec(dllexport) to be used at the explicit +// instantiation definitions instead. + +// Usage +// +// In a header file, write: +// +// extern template class PROTOBUF_EXPORT_TEMPLATE_DECLARE(FOO_EXPORT) foo<bar>; +// +// In a source file, write: +// +// template class PROTOBUF_EXPORT_TEMPLATE_DEFINE(FOO_EXPORT) foo<bar>; +// +// Where FOO_EXPORT is either PROTOBUF_EXPORT or PROTOC_EXPORT + +// Implementation notes +// +// The implementation of these macros uses some subtle macro semantics to +// detect what the provided FOO_EXPORT value was defined as and then +// to dispatch to appropriate macro definitions. Unfortunately, +// MSVC's C preprocessor is rather non-compliant and requires special +// care to make it work. +// +// Issue 1. +// +// #define F(x) +// F() +// +// MSVC emits warning C4003 ("not enough actual parameters for macro +// 'F'), even though it's a valid macro invocation. This affects the +// macros below that take just an "export" parameter, because export +// may be empty. +// +// As a workaround, we can add a dummy parameter and arguments: +// +// #define F(x,_) +// F(,) +// +// Issue 2. +// +// #define F(x) G##x +// #define Gj() ok +// F(j()) +// +// The correct replacement for "F(j())" is "ok", but MSVC replaces it +// with "Gj()". As a workaround, we can pass the result to an +// identity macro to force MSVC to look for replacements again. (This +// is why PROTOBUF_EXPORT_TEMPLATE_STYLE_3 exists.) + +#define PROTOBUF_EXPORT_TEMPLATE_DECLARE(export) \ + PROTOBUF_EXPORT_TEMPLATE_INVOKE( \ + DECLARE, PROTOBUF_EXPORT_TEMPLATE_STYLE(export, ), export) +#define PROTOBUF_EXPORT_TEMPLATE_DEFINE(export) \ + PROTOBUF_EXPORT_TEMPLATE_INVOKE( \ + DEFINE, PROTOBUF_EXPORT_TEMPLATE_STYLE(export, ), export) + +// INVOKE is an internal helper macro to perform parameter replacements +// and token pasting to chain invoke another macro. E.g., +// PROTOBUF_EXPORT_TEMPLATE_INVOKE(DECLARE, DEFAULT, FOO_EXPORT) +// will export to call +// PROTOBUF_EXPORT_TEMPLATE_DECLARE_DEFAULT(FOO_EXPORT, ) +// (but with FOO_EXPORT expanded too). +#define PROTOBUF_EXPORT_TEMPLATE_INVOKE(which, style, export) \ + PROTOBUF_EXPORT_TEMPLATE_INVOKE_2(which, style, export) +#define PROTOBUF_EXPORT_TEMPLATE_INVOKE_2(which, style, export) \ + PROTOBUF_EXPORT_TEMPLATE_##which##_##style(export, ) + +// Default style is to apply the FOO_EXPORT macro at declaration sites. +#define PROTOBUF_EXPORT_TEMPLATE_DECLARE_DEFAULT(export, _) export +#define PROTOBUF_EXPORT_TEMPLATE_DEFINE_DEFAULT(export, _) + +// The "MSVC hack" style is used when FOO_EXPORT is defined +// as __declspec(dllexport), which MSVC requires to be used at +// definition sites instead. +#define PROTOBUF_EXPORT_TEMPLATE_DECLARE_MSVC_HACK(export, _) +#define PROTOBUF_EXPORT_TEMPLATE_DEFINE_MSVC_HACK(export, _) export + +// PROTOBUF_EXPORT_TEMPLATE_STYLE is an internal helper macro that identifies +// which export style needs to be used for the provided FOO_EXPORT macro +// definition. "", "__attribute__(...)", and "__declspec(dllimport)" are +// mapped to "DEFAULT"; while "__declspec(dllexport)" is mapped to "MSVC_HACK". +// +// It's implemented with token pasting to transform the __attribute__ and +// __declspec annotations into macro invocations. E.g., if FOO_EXPORT is +// defined as "__declspec(dllimport)", it undergoes the following sequence of +// macro substitutions: +// PROTOBUF_EXPORT_TEMPLATE_STYLE(FOO_EXPORT, ) +// PROTOBUF_EXPORT_TEMPLATE_STYLE_2(__declspec(dllimport), ) +// PROTOBUF_EXPORT_TEMPLATE_STYLE_3( +// PROTOBUF_EXPORT_TEMPLATE_STYLE_MATCH__declspec(dllimport)) +// PROTOBUF_EXPORT_TEMPLATE_STYLE_MATCH__declspec(dllimport) +// PROTOBUF_EXPORT_TEMPLATE_STYLE_MATCH_DECLSPEC_dllimport +// DEFAULT +#define PROTOBUF_EXPORT_TEMPLATE_STYLE(export, _) \ + PROTOBUF_EXPORT_TEMPLATE_STYLE_2(export, ) +#define PROTOBUF_EXPORT_TEMPLATE_STYLE_2(export, _) \ + PROTOBUF_EXPORT_TEMPLATE_STYLE_3( \ + PROTOBUF_EXPORT_TEMPLATE_STYLE_MATCH_foj3FJo5StF0OvIzl7oMxA##export) +#define PROTOBUF_EXPORT_TEMPLATE_STYLE_3(style) style + +// Internal helper macros for PROTOBUF_EXPORT_TEMPLATE_STYLE. +// +// XXX: C++ reserves all identifiers containing "__" for the implementation, +// but "__attribute__" and "__declspec" already contain "__" and the token-paste +// operator can only add characters; not remove them. To minimize the risk of +// conflict with implementations, we include "foj3FJo5StF0OvIzl7oMxA" (a random +// 128-bit string, encoded in Base64) in the macro name. +#define PROTOBUF_EXPORT_TEMPLATE_STYLE_MATCH_foj3FJo5StF0OvIzl7oMxA DEFAULT +#define PROTOBUF_EXPORT_TEMPLATE_STYLE_MATCH_foj3FJo5StF0OvIzl7oMxA__attribute__(...) \ + DEFAULT +#define PROTOBUF_EXPORT_TEMPLATE_STYLE_MATCH_foj3FJo5StF0OvIzl7oMxA__declspec(arg) \ + PROTOBUF_EXPORT_TEMPLATE_STYLE_MATCH_DECLSPEC_##arg + +// Internal helper macros for PROTOBUF_EXPORT_TEMPLATE_STYLE. +#define PROTOBUF_EXPORT_TEMPLATE_STYLE_MATCH_DECLSPEC_dllexport MSVC_HACK +#define PROTOBUF_EXPORT_TEMPLATE_STYLE_MATCH_DECLSPEC_dllimport DEFAULT + +// Sanity checks. +// +// PROTOBUF_EXPORT_TEMPLATE_TEST uses the same macro invocation pattern as +// PROTOBUF_EXPORT_TEMPLATE_DECLARE and PROTOBUF_EXPORT_TEMPLATE_DEFINE do to +// check that they're working correctly. When they're working correctly, the +// sequence of macro replacements should go something like: +// +// PROTOBUF_EXPORT_TEMPLATE_TEST(DEFAULT, __declspec(dllimport)); +// +// static_assert(PROTOBUF_EXPORT_TEMPLATE_INVOKE(TEST_DEFAULT, +// PROTOBUF_EXPORT_TEMPLATE_STYLE(__declspec(dllimport), ), +// __declspec(dllimport)), "__declspec(dllimport)"); +// +// static_assert(PROTOBUF_EXPORT_TEMPLATE_INVOKE(TEST_DEFAULT, +// DEFAULT, __declspec(dllimport)), "__declspec(dllimport)"); +// +// static_assert(PROTOBUF_EXPORT_TEMPLATE_TEST_DEFAULT_DEFAULT( +// __declspec(dllimport)), "__declspec(dllimport)"); +// +// static_assert(true, "__declspec(dllimport)"); +// +// When they're not working correctly, a syntax error should occur instead. +#define PROTOBUF_EXPORT_TEMPLATE_TEST(want, export) \ + static_assert(PROTOBUF_EXPORT_TEMPLATE_INVOKE( \ + TEST_##want, PROTOBUF_EXPORT_TEMPLATE_STYLE(export, ), \ + export), #export) +#define PROTOBUF_EXPORT_TEMPLATE_TEST_DEFAULT_DEFAULT(...) true +#define PROTOBUF_EXPORT_TEMPLATE_TEST_MSVC_HACK_MSVC_HACK(...) true + +PROTOBUF_EXPORT_TEMPLATE_TEST(DEFAULT, ); +PROTOBUF_EXPORT_TEMPLATE_TEST(DEFAULT, __attribute__((visibility("default")))); +PROTOBUF_EXPORT_TEMPLATE_TEST(MSVC_HACK, __declspec(dllexport)); +PROTOBUF_EXPORT_TEMPLATE_TEST(DEFAULT, __declspec(dllimport)); + +#undef PROTOBUF_EXPORT_TEMPLATE_TEST +#undef PROTOBUF_EXPORT_TEMPLATE_TEST_DEFAULT_DEFAULT +#undef PROTOBUF_EXPORT_TEMPLATE_TEST_MSVC_HACK_MSVC_HACK + // Windows declares several inconvenient macro names. We #undef them and then // restore them in port_undef.inc. #ifdef _MSC_VER
diff --git a/src/google/protobuf/port_undef.inc b/src/google/protobuf/port_undef.inc index bfa620e..e1b4f1b 100644 --- a/src/google/protobuf/port_undef.inc +++ b/src/google/protobuf/port_undef.inc
@@ -41,6 +41,7 @@ #undef PROTOBUF_NOINLINE #undef PROTOBUF_SECTION_VARIABLE #undef PROTOBUF_DEPRECATED +#undef PROTOBUF_DEPRECATED_ENUM #undef PROTOBUF_DEPRECATED_MSG #undef PROTOBUF_FUNC_ALIGN #undef PROTOBUF_RETURNS_NONNULL @@ -67,6 +68,20 @@ #undef PROTOBUF_ASSUME #undef PROTOBUF_EXPORT_TEMPLATE_DECLARE #undef PROTOBUF_EXPORT_TEMPLATE_DEFINE +#undef PROTOBUF_EXPORT_TEMPLATE_INVOKE +#undef PROTOBUF_EXPORT_TEMPLATE_INVOKE_2 +#undef PROTOBUF_EXPORT_TEMPLATE_DECLARE_DEFAULT +#undef PROTOBUF_EXPORT_TEMPLATE_DEFINE_DEFAULT +#undef PROTOBUF_EXPORT_TEMPLATE_DECLARE_MSVC_HACK +#undef PROTOBUF_EXPORT_TEMPLATE_DEFINE_MSVC_HACK +#undef PROTOBUF_EXPORT_TEMPLATE_STYLE +#undef PROTOBUF_EXPORT_TEMPLATE_STYLE_2 +#undef PROTOBUF_EXPORT_TEMPLATE_STYLE_3 +#undef PROTOBUF_EXPORT_TEMPLATE_STYLE_MATCH_foj3FJo5StF0OvIzl7oMxA +#undef PROTOBUF_EXPORT_TEMPLATE_STYLE_MATCH_foj3FJo5StF0OvIzl7oMxA__attribute__ +#undef PROTOBUF_EXPORT_TEMPLATE_STYLE_MATCH_foj3FJo5StF0OvIzl7oMxA__declspec +#undef PROTOBUF_EXPORT_TEMPLATE_STYLE_MATCH_DECLSPEC_dllexport +#undef PROTOBUF_EXPORT_TEMPLATE_STYLE_MATCH_DECLSPEC_dllimport // Restore macro that may have been #undef'd in port_def.inc. #ifdef _MSC_VER
diff --git a/src/google/protobuf/repeated_field.cc b/src/google/protobuf/repeated_field.cc index fc73917..1c43c56 100644 --- a/src/google/protobuf/repeated_field.cc +++ b/src/google/protobuf/repeated_field.cc
@@ -123,14 +123,22 @@ } // namespace internal -template class PROTOBUF_EXPORT_TEMPLATE_DEFINE RepeatedField<bool>; -template class PROTOBUF_EXPORT_TEMPLATE_DEFINE RepeatedField<int32>; -template class PROTOBUF_EXPORT_TEMPLATE_DEFINE RepeatedField<uint32>; -template class PROTOBUF_EXPORT_TEMPLATE_DEFINE RepeatedField<int64>; -template class PROTOBUF_EXPORT_TEMPLATE_DEFINE RepeatedField<uint64>; -template class PROTOBUF_EXPORT_TEMPLATE_DEFINE RepeatedField<float>; -template class PROTOBUF_EXPORT_TEMPLATE_DEFINE RepeatedField<double>; -template class PROTOBUF_EXPORT_TEMPLATE_DEFINE RepeatedPtrField<std::string>; +template class PROTOBUF_EXPORT_TEMPLATE_DEFINE(PROTOBUF_EXPORT) + RepeatedField<bool>; +template class PROTOBUF_EXPORT_TEMPLATE_DEFINE(PROTOBUF_EXPORT) + RepeatedField<int32>; +template class PROTOBUF_EXPORT_TEMPLATE_DEFINE(PROTOBUF_EXPORT) + RepeatedField<uint32>; +template class PROTOBUF_EXPORT_TEMPLATE_DEFINE(PROTOBUF_EXPORT) + RepeatedField<int64>; +template class PROTOBUF_EXPORT_TEMPLATE_DEFINE(PROTOBUF_EXPORT) + RepeatedField<uint64>; +template class PROTOBUF_EXPORT_TEMPLATE_DEFINE(PROTOBUF_EXPORT) + RepeatedField<float>; +template class PROTOBUF_EXPORT_TEMPLATE_DEFINE(PROTOBUF_EXPORT) + RepeatedField<double>; +template class PROTOBUF_EXPORT_TEMPLATE_DEFINE(PROTOBUF_EXPORT) + RepeatedPtrField<std::string>; } // namespace protobuf } // namespace google
diff --git a/src/google/protobuf/repeated_field.h b/src/google/protobuf/repeated_field.h index 280e0ef..cce1e4e 100644 --- a/src/google/protobuf/repeated_field.h +++ b/src/google/protobuf/repeated_field.h
@@ -2653,14 +2653,21 @@ } // Extern declarations of common instantiations to reduce libray bloat. -extern template class PROTOBUF_EXPORT_TEMPLATE_DECLARE RepeatedField<bool>; -extern template class PROTOBUF_EXPORT_TEMPLATE_DECLARE RepeatedField<int32>; -extern template class PROTOBUF_EXPORT_TEMPLATE_DECLARE RepeatedField<uint32>; -extern template class PROTOBUF_EXPORT_TEMPLATE_DECLARE RepeatedField<int64>; -extern template class PROTOBUF_EXPORT_TEMPLATE_DECLARE RepeatedField<uint64>; -extern template class PROTOBUF_EXPORT_TEMPLATE_DECLARE RepeatedField<float>; -extern template class PROTOBUF_EXPORT_TEMPLATE_DECLARE RepeatedField<double>; -extern template class PROTOBUF_EXPORT_TEMPLATE_DECLARE +extern template class PROTOBUF_EXPORT_TEMPLATE_DECLARE(PROTOBUF_EXPORT) + RepeatedField<bool>; +extern template class PROTOBUF_EXPORT_TEMPLATE_DECLARE(PROTOBUF_EXPORT) + RepeatedField<int32>; +extern template class PROTOBUF_EXPORT_TEMPLATE_DECLARE(PROTOBUF_EXPORT) + RepeatedField<uint32>; +extern template class PROTOBUF_EXPORT_TEMPLATE_DECLARE(PROTOBUF_EXPORT) + RepeatedField<int64>; +extern template class PROTOBUF_EXPORT_TEMPLATE_DECLARE(PROTOBUF_EXPORT) + RepeatedField<uint64>; +extern template class PROTOBUF_EXPORT_TEMPLATE_DECLARE(PROTOBUF_EXPORT) + RepeatedField<float>; +extern template class PROTOBUF_EXPORT_TEMPLATE_DECLARE(PROTOBUF_EXPORT) + RepeatedField<double>; +extern template class PROTOBUF_EXPORT_TEMPLATE_DECLARE(PROTOBUF_EXPORT) RepeatedPtrField<std::string>; } // namespace protobuf
diff --git a/src/google/protobuf/source_context.pb.cc b/src/google/protobuf/source_context.pb.cc index bb6e8a9..7ae9445 100644 --- a/src/google/protobuf/source_context.pb.cc +++ b/src/google/protobuf/source_context.pb.cc
@@ -148,7 +148,9 @@ // string file_name = 1; case 1: if (PROTOBUF_PREDICT_TRUE(static_cast<::PROTOBUF_NAMESPACE_ID::uint8>(tag) == 10)) { - ptr = ::PROTOBUF_NAMESPACE_ID::internal::InlineGreedyStringParserUTF8(_internal_mutable_file_name(), ptr, ctx, "google.protobuf.SourceContext.file_name"); + auto str = _internal_mutable_file_name(); + ptr = ::PROTOBUF_NAMESPACE_ID::internal::InlineGreedyStringParser(str, ptr, ctx); + CHK_(::PROTOBUF_NAMESPACE_ID::internal::VerifyUTF8(str, "google.protobuf.SourceContext.file_name")); CHK_(ptr); } else goto handle_unusual; continue; @@ -172,7 +174,7 @@ #undef CHK_ } -::PROTOBUF_NAMESPACE_ID::uint8* SourceContext::InternalSerializeWithCachedSizesToArray( +::PROTOBUF_NAMESPACE_ID::uint8* SourceContext::_InternalSerialize( ::PROTOBUF_NAMESPACE_ID::uint8* target, ::PROTOBUF_NAMESPACE_ID::io::EpsCopyOutputStream* stream) const { // @@protoc_insertion_point(serialize_to_array_start:google.protobuf.SourceContext) ::PROTOBUF_NAMESPACE_ID::uint32 cached_has_bits = 0;
diff --git a/src/google/protobuf/source_context.pb.h b/src/google/protobuf/source_context.pb.h index 4aad4e2..8a49008 100644 --- a/src/google/protobuf/source_context.pb.h +++ b/src/google/protobuf/source_context.pb.h
@@ -136,7 +136,7 @@ size_t ByteSizeLong() const final; const char* _InternalParse(const char* ptr, ::PROTOBUF_NAMESPACE_ID::internal::ParseContext* ctx) final; - ::PROTOBUF_NAMESPACE_ID::uint8* InternalSerializeWithCachedSizesToArray( + ::PROTOBUF_NAMESPACE_ID::uint8* _InternalSerialize( ::PROTOBUF_NAMESPACE_ID::uint8* target, ::PROTOBUF_NAMESPACE_ID::io::EpsCopyOutputStream* stream) const final; int GetCachedSize() const final { return _cached_size_.Get(); }
diff --git a/src/google/protobuf/struct.pb.cc b/src/google/protobuf/struct.pb.cc index 770ed30..15a889b 100644 --- a/src/google/protobuf/struct.pb.cc +++ b/src/google/protobuf/struct.pb.cc
@@ -297,7 +297,7 @@ #undef CHK_ } -::PROTOBUF_NAMESPACE_ID::uint8* Struct::InternalSerializeWithCachedSizesToArray( +::PROTOBUF_NAMESPACE_ID::uint8* Struct::_InternalSerialize( ::PROTOBUF_NAMESPACE_ID::uint8* target, ::PROTOBUF_NAMESPACE_ID::io::EpsCopyOutputStream* stream) const { // @@protoc_insertion_point(serialize_to_array_start:google.protobuf.Struct) ::PROTOBUF_NAMESPACE_ID::uint32 cached_has_bits = 0; @@ -646,7 +646,9 @@ // string string_value = 3; case 3: if (PROTOBUF_PREDICT_TRUE(static_cast<::PROTOBUF_NAMESPACE_ID::uint8>(tag) == 26)) { - ptr = ::PROTOBUF_NAMESPACE_ID::internal::InlineGreedyStringParserUTF8(_internal_mutable_string_value(), ptr, ctx, "google.protobuf.Value.string_value"); + auto str = _internal_mutable_string_value(); + ptr = ::PROTOBUF_NAMESPACE_ID::internal::InlineGreedyStringParser(str, ptr, ctx); + CHK_(::PROTOBUF_NAMESPACE_ID::internal::VerifyUTF8(str, "google.protobuf.Value.string_value")); CHK_(ptr); } else goto handle_unusual; continue; @@ -691,7 +693,7 @@ #undef CHK_ } -::PROTOBUF_NAMESPACE_ID::uint8* Value::InternalSerializeWithCachedSizesToArray( +::PROTOBUF_NAMESPACE_ID::uint8* Value::_InternalSerialize( ::PROTOBUF_NAMESPACE_ID::uint8* target, ::PROTOBUF_NAMESPACE_ID::io::EpsCopyOutputStream* stream) const { // @@protoc_insertion_point(serialize_to_array_start:google.protobuf.Value) ::PROTOBUF_NAMESPACE_ID::uint32 cached_has_bits = 0; @@ -730,7 +732,7 @@ if (_internal_has_struct_value()) { target = stream->EnsureSpace(target); target = ::PROTOBUF_NAMESPACE_ID::internal::WireFormatLite:: - InternalWriteMessageToArray( + InternalWriteMessage( 5, _Internal::struct_value(this), target, stream); } @@ -738,7 +740,7 @@ if (_internal_has_list_value()) { target = stream->EnsureSpace(target); target = ::PROTOBUF_NAMESPACE_ID::internal::WireFormatLite:: - InternalWriteMessageToArray( + InternalWriteMessage( 6, _Internal::list_value(this), target, stream); } @@ -999,7 +1001,7 @@ #undef CHK_ } -::PROTOBUF_NAMESPACE_ID::uint8* ListValue::InternalSerializeWithCachedSizesToArray( +::PROTOBUF_NAMESPACE_ID::uint8* ListValue::_InternalSerialize( ::PROTOBUF_NAMESPACE_ID::uint8* target, ::PROTOBUF_NAMESPACE_ID::io::EpsCopyOutputStream* stream) const { // @@protoc_insertion_point(serialize_to_array_start:google.protobuf.ListValue) ::PROTOBUF_NAMESPACE_ID::uint32 cached_has_bits = 0; @@ -1010,7 +1012,7 @@ n = static_cast<unsigned int>(this->_internal_values_size()); i < n; i++) { target = stream->EnsureSpace(target); target = ::PROTOBUF_NAMESPACE_ID::internal::WireFormatLite:: - InternalWriteMessageToArray(1, this->_internal_values(i), target, stream); + InternalWriteMessage(1, this->_internal_values(i), target, stream); } if (PROTOBUF_PREDICT_FALSE(_internal_metadata_.have_unknown_fields())) {
diff --git a/src/google/protobuf/struct.pb.h b/src/google/protobuf/struct.pb.h index 4b399c0..05a5f74 100644 --- a/src/google/protobuf/struct.pb.h +++ b/src/google/protobuf/struct.pb.h
@@ -122,7 +122,7 @@ void MergeFrom(const Struct_FieldsEntry_DoNotUse& other); static const Struct_FieldsEntry_DoNotUse* internal_default_instance() { return reinterpret_cast<const Struct_FieldsEntry_DoNotUse*>(&_Struct_FieldsEntry_DoNotUse_default_instance_); } static bool ValidateKey(std::string* s) { - return ::PROTOBUF_NAMESPACE_ID::internal::WireFormatLite::VerifyUtf8String(s->data(), s->size(), ::PROTOBUF_NAMESPACE_ID::internal::WireFormatLite::PARSE, "google.protobuf.Struct.FieldsEntry.key"); + return ::PROTOBUF_NAMESPACE_ID::internal::WireFormatLite::VerifyUtf8String(s->data(), static_cast<int>(s->size()), ::PROTOBUF_NAMESPACE_ID::internal::WireFormatLite::PARSE, "google.protobuf.Struct.FieldsEntry.key"); } static bool ValidateValue(void*) { return true; } void MergeFrom(const ::PROTOBUF_NAMESPACE_ID::Message& other) final; @@ -223,7 +223,7 @@ size_t ByteSizeLong() const final; const char* _InternalParse(const char* ptr, ::PROTOBUF_NAMESPACE_ID::internal::ParseContext* ctx) final; - ::PROTOBUF_NAMESPACE_ID::uint8* InternalSerializeWithCachedSizesToArray( + ::PROTOBUF_NAMESPACE_ID::uint8* _InternalSerialize( ::PROTOBUF_NAMESPACE_ID::uint8* target, ::PROTOBUF_NAMESPACE_ID::io::EpsCopyOutputStream* stream) const final; int GetCachedSize() const final { return _cached_size_.Get(); } @@ -398,7 +398,7 @@ size_t ByteSizeLong() const final; const char* _InternalParse(const char* ptr, ::PROTOBUF_NAMESPACE_ID::internal::ParseContext* ctx) final; - ::PROTOBUF_NAMESPACE_ID::uint8* InternalSerializeWithCachedSizesToArray( + ::PROTOBUF_NAMESPACE_ID::uint8* _InternalSerialize( ::PROTOBUF_NAMESPACE_ID::uint8* target, ::PROTOBUF_NAMESPACE_ID::io::EpsCopyOutputStream* stream) const final; int GetCachedSize() const final { return _cached_size_.Get(); } @@ -666,7 +666,7 @@ size_t ByteSizeLong() const final; const char* _InternalParse(const char* ptr, ::PROTOBUF_NAMESPACE_ID::internal::ParseContext* ctx) final; - ::PROTOBUF_NAMESPACE_ID::uint8* InternalSerializeWithCachedSizesToArray( + ::PROTOBUF_NAMESPACE_ID::uint8* _InternalSerialize( ::PROTOBUF_NAMESPACE_ID::uint8* target, ::PROTOBUF_NAMESPACE_ID::io::EpsCopyOutputStream* stream) const final; int GetCachedSize() const final { return _cached_size_.Get(); } @@ -1039,7 +1039,7 @@ } inline PROTOBUF_NAMESPACE_ID::Struct* Value::release_struct_value() { // @@protoc_insertion_point(field_release:google.protobuf.Value.struct_value) - if (has_struct_value()) { + if (_internal_has_struct_value()) { clear_has_kind(); PROTOBUF_NAMESPACE_ID::Struct* temp = kind_.struct_value_; if (GetArenaNoVirtual() != nullptr) { @@ -1062,7 +1062,7 @@ } inline PROTOBUF_NAMESPACE_ID::Struct* Value::unsafe_arena_release_struct_value() { // @@protoc_insertion_point(field_unsafe_arena_release:google.protobuf.Value.struct_value) - if (has_struct_value()) { + if (_internal_has_struct_value()) { clear_has_kind(); PROTOBUF_NAMESPACE_ID::Struct* temp = kind_.struct_value_; kind_.struct_value_ = nullptr; @@ -1113,7 +1113,7 @@ } inline PROTOBUF_NAMESPACE_ID::ListValue* Value::release_list_value() { // @@protoc_insertion_point(field_release:google.protobuf.Value.list_value) - if (has_list_value()) { + if (_internal_has_list_value()) { clear_has_kind(); PROTOBUF_NAMESPACE_ID::ListValue* temp = kind_.list_value_; if (GetArenaNoVirtual() != nullptr) { @@ -1136,7 +1136,7 @@ } inline PROTOBUF_NAMESPACE_ID::ListValue* Value::unsafe_arena_release_list_value() { // @@protoc_insertion_point(field_unsafe_arena_release:google.protobuf.Value.list_value) - if (has_list_value()) { + if (_internal_has_list_value()) { clear_has_kind(); PROTOBUF_NAMESPACE_ID::ListValue* temp = kind_.list_value_; kind_.list_value_ = nullptr;
diff --git a/src/google/protobuf/stubs/bytestream.h b/src/google/protobuf/stubs/bytestream.h index 23d33e4..0840386 100644 --- a/src/google/protobuf/stubs/bytestream.h +++ b/src/google/protobuf/stubs/bytestream.h
@@ -274,7 +274,7 @@ class PROTOBUF_EXPORT NullByteSink : public ByteSink { public: NullByteSink() {} - virtual void Append(const char* /*data*/, size_t /*n*/) override {} + void Append(const char* /*data*/, size_t /*n*/) override {} private: GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(NullByteSink);
diff --git a/src/google/protobuf/stubs/common.cc b/src/google/protobuf/stubs/common.cc index db60393..4db493b 100644 --- a/src/google/protobuf/stubs/common.cc +++ b/src/google/protobuf/stubs/common.cc
@@ -55,7 +55,6 @@ #include <google/protobuf/stubs/callback.h> #include <google/protobuf/stubs/logging.h> -#include <google/protobuf/stubs/mutex.h> #include <google/protobuf/stubs/once.h> #include <google/protobuf/stubs/status.h> #include <google/protobuf/stubs/stringpiece.h> @@ -318,52 +317,6 @@ return result; } -// =================================================================== -// Shutdown support. - -namespace internal { - -struct ShutdownData { - ~ShutdownData() { - std::reverse(functions.begin(), functions.end()); - for (auto pair : functions) pair.first(pair.second); - } - - static ShutdownData* get() { - static auto* data = new ShutdownData; - return data; - } - - std::vector<std::pair<void (*)(const void*), const void*>> functions; - Mutex mutex; -}; - -static void RunZeroArgFunc(const void* arg) { - void (*func)() = reinterpret_cast<void (*)()>(const_cast<void*>(arg)); - func(); -} - -void OnShutdown(void (*func)()) { - OnShutdownRun(RunZeroArgFunc, reinterpret_cast<void*>(func)); -} - -void OnShutdownRun(void (*f)(const void*), const void* arg) { - auto shutdown_data = ShutdownData::get(); - MutexLock lock(&shutdown_data->mutex); - shutdown_data->functions.push_back(std::make_pair(f, arg)); -} - -} // namespace internal - -void ShutdownProtobufLibrary() { - // This function should be called only once, but accepts multiple calls. - static bool is_shutdown = false; - if (!is_shutdown) { - delete internal::ShutdownData::get(); - is_shutdown = true; - } -} - #if PROTOBUF_USE_EXCEPTIONS FatalException::~FatalException() throw() {}
diff --git a/src/google/protobuf/stubs/common.h b/src/google/protobuf/stubs/common.h index 4e11880..2ee72f5 100644 --- a/src/google/protobuf/stubs/common.h +++ b/src/google/protobuf/stubs/common.h
@@ -154,39 +154,12 @@ } // namespace internal - -// =================================================================== -// Shutdown support. - -// Shut down the entire protocol buffers library, deleting all static-duration -// objects allocated by the library or by generated .pb.cc files. -// -// There are two reasons you might want to call this: -// * You use a draconian definition of "memory leak" in which you expect -// every single malloc() to have a corresponding free(), even for objects -// which live until program exit. -// * You are writing a dynamically-loaded library which needs to clean up -// after itself when the library is unloaded. -// -// It is safe to call this multiple times. However, it is not safe to use -// any other part of the protocol buffers library after -// ShutdownProtobufLibrary() has been called. Furthermore this call is not -// thread safe, user needs to synchronize multiple calls. +// This lives in message_lite.h now, but we leave this here for any users that +// #include common.h and not message_lite.h. PROTOBUF_EXPORT void ShutdownProtobufLibrary(); namespace internal { -// Register a function to be called when ShutdownProtocolBuffers() is called. -PROTOBUF_EXPORT void OnShutdown(void (*func)()); -// Run an arbitrary function on an arg -PROTOBUF_EXPORT void OnShutdownRun(void (*f)(const void*), const void* arg); - -template <typename T> -T* OnShutdownDelete(T* p) { - OnShutdownRun([](const void* pp) { delete static_cast<const T*>(pp); }, p); - return p; -} - // Strongly references the given variable such that the linker will be forced // to pull in this variable's translation unit. template <typename T>
diff --git a/src/google/protobuf/stubs/mathlimits.cc b/src/google/protobuf/stubs/mathlimits.cc deleted file mode 100644 index 7a335bd..0000000 --- a/src/google/protobuf/stubs/mathlimits.cc +++ /dev/null
@@ -1,89 +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. - -// All Rights Reserved. -// -// Author: Maxim Lifantsev -// - -#include <google/protobuf/stubs/mathlimits.h> - -#include <google/protobuf/stubs/common.h> - -namespace google { -namespace protobuf { - -// http://en.wikipedia.org/wiki/Quadruple_precision_floating-point_format#Double-double_arithmetic -// With some compilers (gcc 4.6.x) on some platforms (powerpc64), -// "long double" is implemented as a pair of double: "double double" format. -// This causes a problem with epsilon (eps). -// eps is the smallest positive number such that 1.0 + eps > 1.0 -// -// Normal format: 1.0 + e = 1.0...01 // N-1 zeros for N fraction bits -// D-D format: 1.0 + e = 1.000...0001 // epsilon can be very small -// -// In the normal format, 1.0 + e has to fit in one stretch of bits. -// The maximum rounding error is half of eps. -// -// In the double-double format, 1.0 + e splits across two doubles: -// 1.0 in the high double, e in the low double, and they do not have to -// be contiguous. The maximum rounding error on a value close to 1.0 is -// much larger than eps. -// -// Some code checks for errors by comparing a computed value to a golden -// value +/- some multiple of the maximum rounding error. The maximum -// rounding error is not available so we use eps as an approximation -// instead. That fails when long double is in the double-double format. -// Therefore, we define kStdError as a multiple of -// max(DBL_EPSILON * DBL_EPSILON, kEpsilon) rather than a multiple of kEpsilon. - -#define DEF_FP_LIMITS(Type, PREFIX) \ -const Type MathLimits<Type>::kPosMin = PREFIX##_MIN; \ -const Type MathLimits<Type>::kPosMax = PREFIX##_MAX; \ -const Type MathLimits<Type>::kMin = -MathLimits<Type>::kPosMax; \ -const Type MathLimits<Type>::kMax = MathLimits<Type>::kPosMax; \ -const Type MathLimits<Type>::kNegMin = -MathLimits<Type>::kPosMin; \ -const Type MathLimits<Type>::kNegMax = -MathLimits<Type>::kPosMax; \ -const Type MathLimits<Type>::kEpsilon = PREFIX##_EPSILON; \ -/* 32 is 5 bits of mantissa error; should be adequate for common errors */ \ -const Type MathLimits<Type>::kStdError = \ - 32 * (DBL_EPSILON * DBL_EPSILON > MathLimits<Type>::kEpsilon \ - ? DBL_EPSILON * DBL_EPSILON : MathLimits<Type>::kEpsilon); \ -const Type MathLimits<Type>::kNaN = HUGE_VAL - HUGE_VAL; \ -const Type MathLimits<Type>::kPosInf = HUGE_VAL; \ -const Type MathLimits<Type>::kNegInf = -HUGE_VAL; - -DEF_FP_LIMITS(float, FLT) -DEF_FP_LIMITS(double, DBL) -DEF_FP_LIMITS(long double, LDBL); - -#undef DEF_FP_LIMITS -} // namespace protobuf -} // namespace google
diff --git a/src/google/protobuf/stubs/mathlimits.h b/src/google/protobuf/stubs/mathlimits.h deleted file mode 100644 index 0e84432..0000000 --- a/src/google/protobuf/stubs/mathlimits.h +++ /dev/null
@@ -1,307 +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. - -// All Rights Reserved. -// -// Author: Maxim Lifantsev -// -// Useful integer and floating point limits and type traits. -// -// This partially replaces/duplictes numeric_limits<> from <limits>. -// We get a Google-style class that we have a greater control over -// and thus can add new features to it or fix whatever happens to be broken in -// numeric_limits for the compilers we use. -// - -#ifndef UTIL_MATH_MATHLIMITS_H__ -#define UTIL_MATH_MATHLIMITS_H__ - -// Note that for Windows we do something different because it does not support -// the plain isinf and isnan. -#if __cplusplus >= 201103L -// GCC 4.9 has a bug that makes isinf and isnan ambigious when both <math.h> -// and <cmath> get pulled into the same translation unit. We use the ones in -// std:: namespace explicitly for C++11 -#include <cmath> -#define GOOGLE_PROTOBUF_USE_STD_CMATH -#elif _GLIBCXX_USE_C99_MATH && !_GLIBCXX_USE_C99_FP_MACROS_DYNAMIC -// libstdc++ <cmath> header undefines the global macros and put functions in -// std:: namespace even before C++11. Use the ones in std:: instead too. -#include <cmath> -#define GOOGLE_PROTOBUF_USE_STD_CMATH -#else -#include <math.h> -#endif - -#include <string.h> - -#include <cfloat> - -#include <google/protobuf/stubs/common.h> - -#include <google/protobuf/port_def.inc> - -// ========================================================================= // - -// Useful integer and floating point limits and type traits. -// This is just for the documentation; -// real members are defined in our specializations below. -namespace google { -namespace protobuf { -template<typename T> struct MathLimits { - // Type name. - typedef T Type; - // Unsigned version of the Type with the same byte size. - // Same as Type for floating point and unsigned types. - typedef T UnsignedType; - // If the type supports negative values. - static const bool kIsSigned; - // If the type supports only integer values. - static const bool kIsInteger; - // Magnitude-wise smallest representable positive value. - static const Type kPosMin; - // Magnitude-wise largest representable positive value. - static const Type kPosMax; - // Smallest representable value. - static const Type kMin; - // Largest representable value. - static const Type kMax; - // Magnitude-wise smallest representable negative value. - // Present only if kIsSigned. - static const Type kNegMin; - // Magnitude-wise largest representable negative value. - // Present only if kIsSigned. - static const Type kNegMax; - // Smallest integer x such that 10^x is representable. - static const int kMin10Exp; - // Largest integer x such that 10^x is representable. - static const int kMax10Exp; - // Smallest positive value such that Type(1) + kEpsilon != Type(1) - static const Type kEpsilon; - // Typical rounding error that is enough to cover - // a few simple floating-point operations. - // Slightly larger than kEpsilon to account for a few rounding errors. - // Is zero if kIsInteger. - static const Type kStdError; - // Number of decimal digits of mantissa precision. - // Present only if !kIsInteger. - static const int kPrecisionDigits; - // Not a number, i.e. result of 0/0. - // Present only if !kIsInteger. - static const Type kNaN; - // Positive infinity, i.e. result of 1/0. - // Present only if !kIsInteger. - static const Type kPosInf; - // Negative infinity, i.e. result of -1/0. - // Present only if !kIsInteger. - static const Type kNegInf; - - // NOTE: Special floating point values behave - // in a special (but mathematically-logical) way - // in terms of (in)equalty comparison and mathematical operations - // -- see out unittest for examples. - - // Special floating point value testers. - // Present in integer types for convenience. - static bool IsFinite(const Type x); - static bool IsNaN(const Type x); - static bool IsInf(const Type x); - static bool IsPosInf(const Type x); - static bool IsNegInf(const Type x); -}; - -// ========================================================================= // - -// All #define-s below are simply to refactor the declarations of -// MathLimits template specializations. -// They are all #undef-ined below. - -// The hoop-jumping in *_INT_(MAX|MIN) below is so that the compiler does not -// get an overflow while computing the constants. - -#define SIGNED_INT_MAX(Type) \ - (((Type(1) << (sizeof(Type)*8 - 2)) - 1) + (Type(1) << (sizeof(Type)*8 - 2))) - -#define SIGNED_INT_MIN(Type) \ - (-(Type(1) << (sizeof(Type)*8 - 2)) - (Type(1) << (sizeof(Type)*8 - 2))) - -#define UNSIGNED_INT_MAX(Type) \ - (((Type(1) << (sizeof(Type)*8 - 1)) - 1) + (Type(1) << (sizeof(Type)*8 - 1))) - -// Compile-time selected log10-related constants for integer types. -#define SIGNED_MAX_10_EXP(Type) \ - (sizeof(Type) == 1 ? 2 : ( \ - sizeof(Type) == 2 ? 4 : ( \ - sizeof(Type) == 4 ? 9 : ( \ - sizeof(Type) == 8 ? 18 : -1)))) - -#define UNSIGNED_MAX_10_EXP(Type) \ - (sizeof(Type) == 1 ? 2 : ( \ - sizeof(Type) == 2 ? 4 : ( \ - sizeof(Type) == 4 ? 9 : ( \ - sizeof(Type) == 8 ? 19 : -1)))) - -#define DECL_INT_LIMIT_FUNCS \ - static bool IsFinite(const Type /*x*/) { return true; } \ - static bool IsNaN(const Type /*x*/) { return false; } \ - static bool IsInf(const Type /*x*/) { return false; } \ - static bool IsPosInf(const Type /*x*/) { return false; } \ - static bool IsNegInf(const Type /*x*/) { return false; } - -#define DECL_SIGNED_INT_LIMITS(IntType, UnsignedIntType) \ - template <> \ - struct PROTOBUF_EXPORT MathLimits<IntType> { \ - typedef IntType Type; \ - typedef UnsignedIntType UnsignedType; \ - static const bool kIsSigned = true; \ - static const bool kIsInteger = true; \ - static const Type kPosMin = 1; \ - static const Type kPosMax = SIGNED_INT_MAX(Type); \ - static const Type kMin = SIGNED_INT_MIN(Type); \ - static const Type kMax = kPosMax; \ - static const Type kNegMin = -1; \ - static const Type kNegMax = kMin; \ - static const int kMin10Exp = 0; \ - static const int kMax10Exp = SIGNED_MAX_10_EXP(Type); \ - static const Type kEpsilon = 1; \ - static const Type kStdError = 0; \ - DECL_INT_LIMIT_FUNCS \ - }; - -#define DECL_UNSIGNED_INT_LIMITS(IntType) \ - template <> \ - struct PROTOBUF_EXPORT MathLimits<IntType> { \ - typedef IntType Type; \ - typedef IntType UnsignedType; \ - static const bool kIsSigned = false; \ - static const bool kIsInteger = true; \ - static const Type kPosMin = 1; \ - static const Type kPosMax = UNSIGNED_INT_MAX(Type); \ - static const Type kMin = 0; \ - static const Type kMax = kPosMax; \ - static const int kMin10Exp = 0; \ - static const int kMax10Exp = UNSIGNED_MAX_10_EXP(Type); \ - static const Type kEpsilon = 1; \ - static const Type kStdError = 0; \ - DECL_INT_LIMIT_FUNCS \ - }; - -DECL_SIGNED_INT_LIMITS(signed char, unsigned char) -DECL_SIGNED_INT_LIMITS(signed short int, unsigned short int) -DECL_SIGNED_INT_LIMITS(signed int, unsigned int) -DECL_SIGNED_INT_LIMITS(signed long int, unsigned long int) -DECL_SIGNED_INT_LIMITS(signed long long int, unsigned long long int) -DECL_UNSIGNED_INT_LIMITS(unsigned char) -DECL_UNSIGNED_INT_LIMITS(unsigned short int) -DECL_UNSIGNED_INT_LIMITS(unsigned int) -DECL_UNSIGNED_INT_LIMITS(unsigned long int) -DECL_UNSIGNED_INT_LIMITS(unsigned long long int) - -#undef DECL_SIGNED_INT_LIMITS -#undef DECL_UNSIGNED_INT_LIMITS -#undef SIGNED_INT_MAX -#undef SIGNED_INT_MIN -#undef UNSIGNED_INT_MAX -#undef SIGNED_MAX_10_EXP -#undef UNSIGNED_MAX_10_EXP -#undef DECL_INT_LIMIT_FUNCS - -// For non-Windows builds we use the std:: versions of isinf and isnan if they -// are available; see the comment about <cmath> at the top of this file for the -// details on why we need to do this. -#ifdef GOOGLE_PROTOBUF_USE_STD_CMATH -#define ISINF std::isinf -#define ISNAN std::isnan -#else -#define ISINF isinf -#define ISNAN isnan -#endif - -// ========================================================================= // -#if defined(_WIN32) && !defined(__MINGW32__) // Lacks built-in isnan() and isinf() -#define DECL_FP_LIMIT_FUNCS \ - static bool IsFinite(const Type x) { return _finite(x); } \ - static bool IsNaN(const Type x) { return _isnan(x); } \ - static bool IsInf(const Type x) { return (_fpclass(x) & (_FPCLASS_NINF | _FPCLASS_PINF)) != 0; } \ - static bool IsPosInf(const Type x) { return _fpclass(x) == _FPCLASS_PINF; } \ - static bool IsNegInf(const Type x) { return _fpclass(x) == _FPCLASS_NINF; } -#else -#define DECL_FP_LIMIT_FUNCS \ - static bool IsFinite(const Type x) { return !ISINF(x) && !ISNAN(x); } \ - static bool IsNaN(const Type x) { return ISNAN(x); } \ - static bool IsInf(const Type x) { return ISINF(x); } \ - static bool IsPosInf(const Type x) { return ISINF(x) && x > 0; } \ - static bool IsNegInf(const Type x) { return ISINF(x) && x < 0; } -#endif - -// We can't put floating-point constant values in the header here because -// such constants are not considered to be primitive-type constants by gcc. -// CAVEAT: Hence, they are going to be initialized only during -// the global objects construction time. -#define DECL_FP_LIMITS(FP_Type, PREFIX) \ - template <> \ - struct PROTOBUF_EXPORT MathLimits<FP_Type> { \ - typedef FP_Type Type; \ - typedef FP_Type UnsignedType; \ - static const bool kIsSigned = true; \ - static const bool kIsInteger = false; \ - static const Type kPosMin; \ - static const Type kPosMax; \ - static const Type kMin; \ - static const Type kMax; \ - static const Type kNegMin; \ - static const Type kNegMax; \ - static const int kMin10Exp = PREFIX##_MIN_10_EXP; \ - static const int kMax10Exp = PREFIX##_MAX_10_EXP; \ - static const Type kEpsilon; \ - static const Type kStdError; \ - static const int kPrecisionDigits = PREFIX##_DIG; \ - static const Type kNaN; \ - static const Type kPosInf; \ - static const Type kNegInf; \ - DECL_FP_LIMIT_FUNCS \ - }; - -DECL_FP_LIMITS(float, FLT) -DECL_FP_LIMITS(double, DBL) -DECL_FP_LIMITS(long double, LDBL) - -#undef ISINF -#undef ISNAN -#undef DECL_FP_LIMITS -#undef DECL_FP_LIMIT_FUNCS - -// ========================================================================= // -} // namespace protobuf -} // namespace google - -#include <google/protobuf/port_undef.inc> - -#endif // UTIL_MATH_MATHLIMITS_H__
diff --git a/src/google/protobuf/stubs/mathutil.h b/src/google/protobuf/stubs/mathutil.h index 479032d..7116d2d 100644 --- a/src/google/protobuf/stubs/mathutil.h +++ b/src/google/protobuf/stubs/mathutil.h
@@ -30,16 +30,37 @@ #ifndef GOOGLE_PROTOBUF_STUBS_MATHUTIL_H_ #define GOOGLE_PROTOBUF_STUBS_MATHUTIL_H_ +#include <cmath> #include <float.h> -#include <math.h> +#include <limits> #include <google/protobuf/stubs/common.h> #include <google/protobuf/stubs/logging.h> -#include <google/protobuf/stubs/mathlimits.h> namespace google { namespace protobuf { namespace internal { + +// Like std::make_unsigned_t except floating point types map to themselves. +template <typename T> +using MakeUnsignedT = + typename std::conditional<std::is_integral<T>::value, std::make_unsigned<T>, + std::common_type<T>>::type::type; + +// Like std::isnan() except a template function that is defined for all numeric +// types. +template <typename T, + typename std::enable_if<std::is_integral<T>::value, int>::type = 0> +bool IsNan(T val) { + return false; +} + +template <typename T, typename std::enable_if<std::is_floating_point<T>::value, + int>::type = 0> +bool IsNan(T val) { + return std::isnan(val); +} + template<typename T> bool AlmostEquals(T a, T b) { return a == b; @@ -53,19 +74,20 @@ inline bool AlmostEquals(double a, double b) { return fabs(a - b) < 32 * DBL_EPSILON; } + } // namespace internal class MathUtil { public: - template<typename T> + template <typename T> static T Sign(T value) { - if (value == T(0) || MathLimits<T>::IsNaN(value)) { + if (value == T(0) || internal::IsNan(value)) { return value; } return value > T(0) ? 1 : -1; } - template<typename T> + template <typename T> static bool AlmostEquals(T a, T b) { return internal::AlmostEquals(a, b); } @@ -76,9 +98,9 @@ // which should be OK because, although they (can) have different // bit representation, they are observably the same when examined // with arithmetic and (in)equality operators. - template<typename T> + template <typename T> static T Max(const T x, const T y) { - return MathLimits<T>::IsNaN(x) || x > y ? x : y; + return internal::IsNan(x) || x > y ? x : y; } // Absolute value of x @@ -93,10 +115,10 @@ // Absolute value of the difference between two numbers. // Works correctly for signed types and special floating point values. - template<typename T> - static typename MathLimits<T>::UnsignedType AbsDiff(const T x, const T y) { + template <typename T> + static typename internal::MakeUnsignedT<T> AbsDiff(const T x, const T y) { // Carries out arithmetic as unsigned to avoid overflow. - typedef typename MathLimits<T>::UnsignedType R; + typedef typename internal::MakeUnsignedT<T> R; return x > y ? R(x) - R(y) : R(y) - R(x); } @@ -123,10 +145,10 @@ // which will cause the compiler to generate code for either the "if" part // or the "then" part. In this way we avoid a compiler warning // about a potential integer overflow in crosstool v12 (gcc 4.3.1). - if (MathLimits<T>::kIsInteger) { + if (std::numeric_limits<T>::is_integer) { return x == y; } else { - if (!MathLimits<T>::IsFinite(x) || !MathLimits<T>::IsFinite(y)) { + if (!std::isfinite(x) || !std::isfinite(y)) { return false; } T relative_margin = static_cast<T>(fraction * Max(Abs(x), Abs(y)));
diff --git a/src/google/protobuf/stubs/port.h b/src/google/protobuf/stubs/port.h index 2903775..31d2a10 100644 --- a/src/google/protobuf/stubs/port.h +++ b/src/google/protobuf/stubs/port.h
@@ -32,17 +32,11 @@ #define GOOGLE_PROTOBUF_STUBS_PORT_H_ #include <assert.h> +#include <cstdint> #include <stdlib.h> #include <cstddef> #include <string> #include <string.h> -#if defined(__osf__) -// Tru64 lacks stdint.h, but has inttypes.h which defines a superset of -// what stdint.h would define. -#include <inttypes.h> -#elif !defined(_MSC_VER) -#include <stdint.h> -#endif #include <google/protobuf/stubs/platform_macros.h> @@ -105,7 +99,7 @@ #define PROTOBUF_RUNTIME_DEPRECATED(message) PROTOBUF_DEPRECATED_MSG(message) #define GOOGLE_PROTOBUF_RUNTIME_DEPRECATED(message) \ - PROTOBUF_DEPRECATED_MSG(message) + PROTOBUF_DEPRECATED_MSG(message) // =================================================================== // from google3/base/port.h @@ -116,18 +110,8 @@ // undefined otherwise. Do NOT define it to 0 -- that causes // '#ifdef LANG_CXX11' to behave differently from '#if LANG_CXX11'. #define LANG_CXX11 1 -#endif - -#if LANG_CXX11 && !defined(__NVCC__) -#define PROTOBUF_CXX11 1 #else -#define PROTOBUF_CXX11 0 -#endif - -#if PROTOBUF_CXX11 -#define PROTOBUF_FINAL final -#else -#define PROTOBUF_FINAL +#error "Protobuf requires at least C++11." #endif namespace google { @@ -135,17 +119,6 @@ typedef unsigned int uint; -#ifdef _MSC_VER -typedef signed __int8 int8; -typedef __int16 int16; -typedef __int32 int32; -typedef __int64 int64; - -typedef unsigned __int8 uint8; -typedef unsigned __int16 uint16; -typedef unsigned __int32 uint32; -typedef unsigned __int64 uint64; -#else typedef int8_t int8; typedef int16_t int16; typedef int32_t int32; @@ -155,7 +128,6 @@ typedef uint16_t uint16; typedef uint32_t uint32; typedef uint64_t uint64; -#endif static const int32 kint32max = 0x7FFFFFFF; static const int32 kint32min = -kint32max - 1;
diff --git a/src/google/protobuf/stubs/status.h b/src/google/protobuf/stubs/status.h index 440a0ed..04ecc63 100644 --- a/src/google/protobuf/stubs/status.h +++ b/src/google/protobuf/stubs/status.h
@@ -116,8 +116,6 @@ // Prints a human-readable representation of 'x' to 'os'. PROTOBUF_EXPORT std::ostream& operator<<(std::ostream& os, const Status& x); -#define EXPECT_OK(value) EXPECT_TRUE((value).ok()) - } // namespace util } // namespace protobuf } // namespace google
diff --git a/src/google/protobuf/stubs/strutil.cc b/src/google/protobuf/stubs/strutil.cc index 06250b1..62b3f0a 100644 --- a/src/google/protobuf/stubs/strutil.cc +++ b/src/google/protobuf/stubs/strutil.cc
@@ -42,7 +42,6 @@ #include <google/protobuf/stubs/logging.h> #include <google/protobuf/stubs/stl_util.h> -#include <google/protobuf/io/strtod.h> #ifdef _WIN32 // MSVC has only _snprintf, not snprintf. @@ -1277,7 +1276,7 @@ // of a double. This long double may have extra bits that make it compare // unequal to "value" even though it would be exactly equal if it were // truncated to a double. - volatile double parsed_value = io::NoLocaleStrtod(buffer, nullptr); + volatile double parsed_value = internal::NoLocaleStrtod(buffer, nullptr); if (parsed_value != value) { int snprintf_result = snprintf(buffer, kDoubleToBufferSize, "%.*g", DBL_DIG+2, value); @@ -1329,7 +1328,7 @@ char* endptr; errno = 0; // errno only gets set on errors #if defined(_WIN32) || defined (__hpux) // has no strtof() - *value = io::NoLocaleStrtod(str, &endptr); + *value = internal::NoLocaleStrtod(str, &endptr); #else *value = strtof(str, &endptr); #endif @@ -1338,7 +1337,7 @@ bool safe_strtod(const char* str, double* value) { char* endptr; - *value = io::NoLocaleStrtod(str, &endptr); + *value = internal::NoLocaleStrtod(str, &endptr); if (endptr != str) { while (ascii_isspace(*endptr)) ++endptr; } @@ -2397,5 +2396,76 @@ } } +namespace internal { + +// ---------------------------------------------------------------------- +// NoLocaleStrtod() +// This code will make you cry. +// ---------------------------------------------------------------------- + +namespace { + +// Returns a string identical to *input except that the character pointed to +// by radix_pos (which should be '.') is replaced with the locale-specific +// radix character. +std::string LocalizeRadix(const char *input, const char *radix_pos) { + // Determine the locale-specific radix character by calling sprintf() to + // print the number 1.5, then stripping off the digits. As far as I can + // tell, this is the only portable, thread-safe way to get the C library + // to divuldge the locale's radix character. No, localeconv() is NOT + // thread-safe. + char temp[16]; + int size = snprintf(temp, sizeof(temp), "%.1f", 1.5); + GOOGLE_CHECK_EQ(temp[0], '1'); + GOOGLE_CHECK_EQ(temp[size - 1], '5'); + GOOGLE_CHECK_LE(size, 6); + + // Now replace the '.' in the input with it. + std::string result; + result.reserve(strlen(input) + size - 3); + result.append(input, radix_pos); + result.append(temp + 1, size - 2); + result.append(radix_pos + 1); + return result; +} + +} // namespace + +double NoLocaleStrtod(const char *str, char **endptr) { + // We cannot simply set the locale to "C" temporarily with setlocale() + // as this is not thread-safe. Instead, we try to parse in the current + // locale first. If parsing stops at a '.' character, then this is a + // pretty good hint that we're actually in some other locale in which + // '.' is not the radix character. + + char *temp_endptr; + double result = strtod(str, &temp_endptr); + if (endptr != NULL) *endptr = temp_endptr; + if (*temp_endptr != '.') return result; + + // Parsing halted on a '.'. Perhaps we're in a different locale? Let's + // try to replace the '.' with a locale-specific radix character and + // try again. + std::string localized = LocalizeRadix(str, temp_endptr); + const char *localized_cstr = localized.c_str(); + char *localized_endptr; + result = strtod(localized_cstr, &localized_endptr); + if ((localized_endptr - localized_cstr) > (temp_endptr - str)) { + // This attempt got further, so replacing the decimal must have helped. + // Update endptr to point at the right location. + if (endptr != NULL) { + // size_diff is non-zero if the localized radix has multiple bytes. + int size_diff = localized.size() - strlen(str); + // const_cast is necessary to match the strtod() interface. + *endptr = const_cast<char *>( + str + (localized_endptr - localized_cstr - size_diff)); + } + } + + return result; +} + +} // namespace internal + } // namespace protobuf } // namespace google
diff --git a/src/google/protobuf/stubs/strutil.h b/src/google/protobuf/stubs/strutil.h index e28d22e..e688c8e 100644 --- a/src/google/protobuf/stubs/strutil.h +++ b/src/google/protobuf/stubs/strutil.h
@@ -930,6 +930,14 @@ } } // namespace strings +namespace internal { + +// A locale-independent version of the standard strtod(), which always +// uses a dot as the decimal separator. +double NoLocaleStrtod(const char* str, char** endptr); + +} // namespace internal + } // namespace protobuf } // namespace google
diff --git a/src/google/protobuf/stubs/strutil_unittest.cc b/src/google/protobuf/stubs/strutil_unittest.cc index 07d16ef..141d263 100644 --- a/src/google/protobuf/stubs/strutil_unittest.cc +++ b/src/google/protobuf/stubs/strutil_unittest.cc
@@ -836,49 +836,59 @@ EXPECT_EQ(answer, "130"); } -class ReplaceChars : public ::testing::TestWithParam<std::tuple<string, string, const char*, char>> { -}; +class ReplaceChars : public ::testing::TestWithParam< + std::tuple<string, string, const char*, char>> {}; TEST_P(ReplaceChars, ReplacesAllOccurencesOfAnyCharInReplaceWithAReplaceChar) { - string expected = std::get<0>(GetParam()); - string string_to_replace_in = std::get<1>(GetParam()); - const char* what_to_replace = std::get<2>(GetParam()); - char replacement = std::get<3>(GetParam()); - ReplaceCharacters(&string_to_replace_in, what_to_replace, replacement); - ASSERT_EQ(expected, string_to_replace_in); + string expected = std::get<0>(GetParam()); + string string_to_replace_in = std::get<1>(GetParam()); + const char* what_to_replace = std::get<2>(GetParam()); + char replacement = std::get<3>(GetParam()); + ReplaceCharacters(&string_to_replace_in, what_to_replace, replacement); + ASSERT_EQ(expected, string_to_replace_in); } -INSTANTIATE_TEST_CASE_P(Replace, - ReplaceChars, +INSTANTIATE_TEST_CASE_P( + Replace, ReplaceChars, ::testing::Values( - std::make_tuple("", "", "", '_'), // empty string should remain empty - std::make_tuple(" ", " ", "", '_'), // no replacement string - std::make_tuple(" ", " ", "_-abcedf", '*'), // replacement character not in string - std::make_tuple("replace", "Replace", "R", 'r'), // replace one character - std::make_tuple("not_spaces__", "not\nspaces\t ", " \t\r\n", '_'), // replace some special characters - std::make_tuple("c++", "cxx", "x", '+'), // same character multiple times - std::make_tuple("qvvvvvng v T", "queueing a T", "aeiou", 'v'))); // replace all voewls + std::make_tuple("", "", "", '_'), // empty string should remain empty + std::make_tuple(" ", " ", "", '_'), // no replacement string + std::make_tuple(" ", " ", "_-abcedf", + '*'), // replacement character not in string + std::make_tuple("replace", "Replace", "R", + 'r'), // replace one character + std::make_tuple("not_spaces__", "not\nspaces\t ", " \t\r\n", + '_'), // replace some special characters + std::make_tuple("c++", "cxx", "x", + '+'), // same character multiple times + std::make_tuple("qvvvvvng v T", "queueing a T", "aeiou", + 'v'))); // replace all voewls -class StripWs: public ::testing::TestWithParam<std::tuple<string, string>> { -}; +class StripWs : public ::testing::TestWithParam<std::tuple<string, string>> {}; TEST_P(StripWs, AlwaysStripsLeadingAndTrailingWhitespace) { - string expected = std::get<0>(GetParam()); - string string_to_strip = std::get<1>(GetParam()); - StripWhitespace(&string_to_strip); - ASSERT_EQ(expected, string_to_strip); + string expected = std::get<0>(GetParam()); + string string_to_strip = std::get<1>(GetParam()); + StripWhitespace(&string_to_strip); + ASSERT_EQ(expected, string_to_strip); } -INSTANTIATE_TEST_CASE_P(Strip, - StripWs, +INSTANTIATE_TEST_CASE_P( + Strip, StripWs, ::testing::Values( - std::make_tuple("", ""), // empty string should remain empty - std::make_tuple("", " "), // only ws should become empty - std::make_tuple("no whitespace", " no whitespace"), // leading ws removed - std::make_tuple("no whitespace", "no whitespace "), // trailing ws removed - std::make_tuple("no whitespace", " no whitespace "), // same nb. of leading and trailing - std::make_tuple("no whitespace", " no whitespace "), // different nb. of leading/trailing - std::make_tuple("no whitespace", " no whitespace "))); // more trailing than leading + std::make_tuple("", ""), // empty string should remain empty + std::make_tuple("", " "), // only ws should become empty + std::make_tuple("no whitespace", + " no whitespace"), // leading ws removed + std::make_tuple("no whitespace", + "no whitespace "), // trailing ws removed + std::make_tuple("no whitespace", + " no whitespace "), // same nb. of leading and trailing + std::make_tuple( + "no whitespace", + " no whitespace "), // different nb. of leading/trailing + std::make_tuple("no whitespace", + " no whitespace "))); // more trailing than leading } // anonymous namespace } // namespace protobuf
diff --git a/src/google/protobuf/test_messages_proto2.proto b/src/google/protobuf/test_messages_proto2.proto index 1d0c33f..f820743 100644 --- a/src/google/protobuf/test_messages_proto2.proto +++ b/src/google/protobuf/test_messages_proto2.proto
@@ -27,6 +27,36 @@ // 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. + +// 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. // // Test schema for proto2 messages. This test schema is used by: //
diff --git a/src/google/protobuf/test_messages_proto3.proto b/src/google/protobuf/test_messages_proto3.proto index a10f44d..803e2c3 100644 --- a/src/google/protobuf/test_messages_proto3.proto +++ b/src/google/protobuf/test_messages_proto3.proto
@@ -27,6 +27,36 @@ // 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. + +// 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. // // Test schema for proto3 messages. This test schema is used by: //
diff --git a/src/google/protobuf/text_format.cc b/src/google/protobuf/text_format.cc index be8231d..6b33088 100644 --- a/src/google/protobuf/text_format.cc +++ b/src/google/protobuf/text_format.cc
@@ -35,11 +35,11 @@ #include <google/protobuf/text_format.h> #include <float.h> -#include <cmath> #include <stdio.h> #include <algorithm> #include <climits> +#include <cmath> #include <limits> #include <vector> @@ -2093,7 +2093,7 @@ if (base.IsRepeatedFieldValid()) { const RepeatedPtrField<Message>& map_field = - reflection->GetRepeatedPtrField<Message>(message, field); + reflection->GetRepeatedPtrFieldInternal<Message>(message, field); for (int i = 0; i < map_field.size(); ++i) { sorted_map_field->push_back( const_cast<RepeatedPtrField<Message>*>(&map_field)->Mutable(i)); @@ -2367,8 +2367,7 @@ // it is possible for the user to force an unknown integer value. So we // simply use the integer value itself as the enum value name in this // case. - printer->PrintEnum(enum_value, StringPrintf("%d", enum_value), - generator); + printer->PrintEnum(enum_value, StrCat(enum_value), generator); } break; }
diff --git a/src/google/protobuf/text_format_unittest.cc b/src/google/protobuf/text_format_unittest.cc index dd507da..3bb20b7 100644 --- a/src/google/protobuf/text_format_unittest.cc +++ b/src/google/protobuf/text_format_unittest.cc
@@ -58,7 +58,6 @@ #include <google/protobuf/stubs/substitute.h> #include <google/protobuf/testing/googletest.h> #include <gtest/gtest.h> -#include <google/protobuf/stubs/mathlimits.h> #include <google/protobuf/port_def.inc> @@ -1203,8 +1202,8 @@ -std::numeric_limits<double>::infinity()); EXPECT_EQ(message.repeated_double(10), -std::numeric_limits<double>::infinity()); - EXPECT_TRUE(MathLimits<double>::IsNaN(message.repeated_double(11))); - EXPECT_TRUE(MathLimits<double>::IsNaN(message.repeated_double(12))); + EXPECT_TRUE(std::isnan(message.repeated_double(11))); + EXPECT_TRUE(std::isnan(message.repeated_double(12))); // Note: Since these string literals have \0's in them, we must explicitly // pass their sizes to string's constructor.
diff --git a/src/google/protobuf/timestamp.pb.cc b/src/google/protobuf/timestamp.pb.cc index d079916..24a299e 100644 --- a/src/google/protobuf/timestamp.pb.cc +++ b/src/google/protobuf/timestamp.pb.cc
@@ -195,7 +195,7 @@ #undef CHK_ } -::PROTOBUF_NAMESPACE_ID::uint8* Timestamp::InternalSerializeWithCachedSizesToArray( +::PROTOBUF_NAMESPACE_ID::uint8* Timestamp::_InternalSerialize( ::PROTOBUF_NAMESPACE_ID::uint8* target, ::PROTOBUF_NAMESPACE_ID::io::EpsCopyOutputStream* stream) const { // @@protoc_insertion_point(serialize_to_array_start:google.protobuf.Timestamp) ::PROTOBUF_NAMESPACE_ID::uint32 cached_has_bits = 0;
diff --git a/src/google/protobuf/timestamp.pb.h b/src/google/protobuf/timestamp.pb.h index ec8a709..497db63 100644 --- a/src/google/protobuf/timestamp.pb.h +++ b/src/google/protobuf/timestamp.pb.h
@@ -151,7 +151,7 @@ size_t ByteSizeLong() const final; const char* _InternalParse(const char* ptr, ::PROTOBUF_NAMESPACE_ID::internal::ParseContext* ctx) final; - ::PROTOBUF_NAMESPACE_ID::uint8* InternalSerializeWithCachedSizesToArray( + ::PROTOBUF_NAMESPACE_ID::uint8* _InternalSerialize( ::PROTOBUF_NAMESPACE_ID::uint8* target, ::PROTOBUF_NAMESPACE_ID::io::EpsCopyOutputStream* stream) const final; int GetCachedSize() const final { return _cached_size_.Get(); }
diff --git a/src/google/protobuf/type.pb.cc b/src/google/protobuf/type.pb.cc index b6d9390..0db802c 100644 --- a/src/google/protobuf/type.pb.cc +++ b/src/google/protobuf/type.pb.cc
@@ -486,7 +486,9 @@ // string name = 1; case 1: if (PROTOBUF_PREDICT_TRUE(static_cast<::PROTOBUF_NAMESPACE_ID::uint8>(tag) == 10)) { - ptr = ::PROTOBUF_NAMESPACE_ID::internal::InlineGreedyStringParserUTF8(_internal_mutable_name(), ptr, ctx, "google.protobuf.Type.name"); + auto str = _internal_mutable_name(); + ptr = ::PROTOBUF_NAMESPACE_ID::internal::InlineGreedyStringParser(str, ptr, ctx); + CHK_(::PROTOBUF_NAMESPACE_ID::internal::VerifyUTF8(str, "google.protobuf.Type.name")); CHK_(ptr); } else goto handle_unusual; continue; @@ -508,7 +510,9 @@ ptr -= 1; do { ptr += 1; - ptr = ::PROTOBUF_NAMESPACE_ID::internal::InlineGreedyStringParserUTF8(_internal_add_oneofs(), ptr, ctx, "google.protobuf.Type.oneofs"); + auto str = _internal_add_oneofs(); + ptr = ::PROTOBUF_NAMESPACE_ID::internal::InlineGreedyStringParser(str, ptr, ctx); + CHK_(::PROTOBUF_NAMESPACE_ID::internal::VerifyUTF8(str, "google.protobuf.Type.oneofs")); CHK_(ptr); if (!ctx->DataAvailable(ptr)) break; } while (::PROTOBUF_NAMESPACE_ID::internal::ExpectTag<26>(ptr)); @@ -561,7 +565,7 @@ #undef CHK_ } -::PROTOBUF_NAMESPACE_ID::uint8* Type::InternalSerializeWithCachedSizesToArray( +::PROTOBUF_NAMESPACE_ID::uint8* Type::_InternalSerialize( ::PROTOBUF_NAMESPACE_ID::uint8* target, ::PROTOBUF_NAMESPACE_ID::io::EpsCopyOutputStream* stream) const { // @@protoc_insertion_point(serialize_to_array_start:google.protobuf.Type) ::PROTOBUF_NAMESPACE_ID::uint32 cached_has_bits = 0; @@ -582,7 +586,7 @@ n = static_cast<unsigned int>(this->_internal_fields_size()); i < n; i++) { target = stream->EnsureSpace(target); target = ::PROTOBUF_NAMESPACE_ID::internal::WireFormatLite:: - InternalWriteMessageToArray(2, this->_internal_fields(i), target, stream); + InternalWriteMessage(2, this->_internal_fields(i), target, stream); } // repeated string oneofs = 3; @@ -600,14 +604,14 @@ n = static_cast<unsigned int>(this->_internal_options_size()); i < n; i++) { target = stream->EnsureSpace(target); target = ::PROTOBUF_NAMESPACE_ID::internal::WireFormatLite:: - InternalWriteMessageToArray(4, this->_internal_options(i), target, stream); + InternalWriteMessage(4, this->_internal_options(i), target, stream); } // .google.protobuf.SourceContext source_context = 5; if (this->has_source_context()) { target = stream->EnsureSpace(target); target = ::PROTOBUF_NAMESPACE_ID::internal::WireFormatLite:: - InternalWriteMessageToArray( + InternalWriteMessage( 5, _Internal::source_context(this), target, stream); } @@ -898,14 +902,18 @@ // string name = 4; case 4: if (PROTOBUF_PREDICT_TRUE(static_cast<::PROTOBUF_NAMESPACE_ID::uint8>(tag) == 34)) { - ptr = ::PROTOBUF_NAMESPACE_ID::internal::InlineGreedyStringParserUTF8(_internal_mutable_name(), ptr, ctx, "google.protobuf.Field.name"); + auto str = _internal_mutable_name(); + ptr = ::PROTOBUF_NAMESPACE_ID::internal::InlineGreedyStringParser(str, ptr, ctx); + CHK_(::PROTOBUF_NAMESPACE_ID::internal::VerifyUTF8(str, "google.protobuf.Field.name")); CHK_(ptr); } else goto handle_unusual; continue; // string type_url = 6; case 6: if (PROTOBUF_PREDICT_TRUE(static_cast<::PROTOBUF_NAMESPACE_ID::uint8>(tag) == 50)) { - ptr = ::PROTOBUF_NAMESPACE_ID::internal::InlineGreedyStringParserUTF8(_internal_mutable_type_url(), ptr, ctx, "google.protobuf.Field.type_url"); + auto str = _internal_mutable_type_url(); + ptr = ::PROTOBUF_NAMESPACE_ID::internal::InlineGreedyStringParser(str, ptr, ctx); + CHK_(::PROTOBUF_NAMESPACE_ID::internal::VerifyUTF8(str, "google.protobuf.Field.type_url")); CHK_(ptr); } else goto handle_unusual; continue; @@ -938,14 +946,18 @@ // string json_name = 10; case 10: if (PROTOBUF_PREDICT_TRUE(static_cast<::PROTOBUF_NAMESPACE_ID::uint8>(tag) == 82)) { - ptr = ::PROTOBUF_NAMESPACE_ID::internal::InlineGreedyStringParserUTF8(_internal_mutable_json_name(), ptr, ctx, "google.protobuf.Field.json_name"); + auto str = _internal_mutable_json_name(); + ptr = ::PROTOBUF_NAMESPACE_ID::internal::InlineGreedyStringParser(str, ptr, ctx); + CHK_(::PROTOBUF_NAMESPACE_ID::internal::VerifyUTF8(str, "google.protobuf.Field.json_name")); CHK_(ptr); } else goto handle_unusual; continue; // string default_value = 11; case 11: if (PROTOBUF_PREDICT_TRUE(static_cast<::PROTOBUF_NAMESPACE_ID::uint8>(tag) == 90)) { - ptr = ::PROTOBUF_NAMESPACE_ID::internal::InlineGreedyStringParserUTF8(_internal_mutable_default_value(), ptr, ctx, "google.protobuf.Field.default_value"); + auto str = _internal_mutable_default_value(); + ptr = ::PROTOBUF_NAMESPACE_ID::internal::InlineGreedyStringParser(str, ptr, ctx); + CHK_(::PROTOBUF_NAMESPACE_ID::internal::VerifyUTF8(str, "google.protobuf.Field.default_value")); CHK_(ptr); } else goto handle_unusual; continue; @@ -969,7 +981,7 @@ #undef CHK_ } -::PROTOBUF_NAMESPACE_ID::uint8* Field::InternalSerializeWithCachedSizesToArray( +::PROTOBUF_NAMESPACE_ID::uint8* Field::_InternalSerialize( ::PROTOBUF_NAMESPACE_ID::uint8* target, ::PROTOBUF_NAMESPACE_ID::io::EpsCopyOutputStream* stream) const { // @@protoc_insertion_point(serialize_to_array_start:google.protobuf.Field) ::PROTOBUF_NAMESPACE_ID::uint32 cached_has_bits = 0; @@ -1032,7 +1044,7 @@ n = static_cast<unsigned int>(this->_internal_options_size()); i < n; i++) { target = stream->EnsureSpace(target); target = ::PROTOBUF_NAMESPACE_ID::internal::WireFormatLite:: - InternalWriteMessageToArray(9, this->_internal_options(i), target, stream); + InternalWriteMessage(9, this->_internal_options(i), target, stream); } // string json_name = 10; @@ -1370,7 +1382,9 @@ // string name = 1; case 1: if (PROTOBUF_PREDICT_TRUE(static_cast<::PROTOBUF_NAMESPACE_ID::uint8>(tag) == 10)) { - ptr = ::PROTOBUF_NAMESPACE_ID::internal::InlineGreedyStringParserUTF8(_internal_mutable_name(), ptr, ctx, "google.protobuf.Enum.name"); + auto str = _internal_mutable_name(); + ptr = ::PROTOBUF_NAMESPACE_ID::internal::InlineGreedyStringParser(str, ptr, ctx); + CHK_(::PROTOBUF_NAMESPACE_ID::internal::VerifyUTF8(str, "google.protobuf.Enum.name")); CHK_(ptr); } else goto handle_unusual; continue; @@ -1433,7 +1447,7 @@ #undef CHK_ } -::PROTOBUF_NAMESPACE_ID::uint8* Enum::InternalSerializeWithCachedSizesToArray( +::PROTOBUF_NAMESPACE_ID::uint8* Enum::_InternalSerialize( ::PROTOBUF_NAMESPACE_ID::uint8* target, ::PROTOBUF_NAMESPACE_ID::io::EpsCopyOutputStream* stream) const { // @@protoc_insertion_point(serialize_to_array_start:google.protobuf.Enum) ::PROTOBUF_NAMESPACE_ID::uint32 cached_has_bits = 0; @@ -1454,7 +1468,7 @@ n = static_cast<unsigned int>(this->_internal_enumvalue_size()); i < n; i++) { target = stream->EnsureSpace(target); target = ::PROTOBUF_NAMESPACE_ID::internal::WireFormatLite:: - InternalWriteMessageToArray(2, this->_internal_enumvalue(i), target, stream); + InternalWriteMessage(2, this->_internal_enumvalue(i), target, stream); } // repeated .google.protobuf.Option options = 3; @@ -1462,14 +1476,14 @@ n = static_cast<unsigned int>(this->_internal_options_size()); i < n; i++) { target = stream->EnsureSpace(target); target = ::PROTOBUF_NAMESPACE_ID::internal::WireFormatLite:: - InternalWriteMessageToArray(3, this->_internal_options(i), target, stream); + InternalWriteMessage(3, this->_internal_options(i), target, stream); } // .google.protobuf.SourceContext source_context = 4; if (this->has_source_context()) { target = stream->EnsureSpace(target); target = ::PROTOBUF_NAMESPACE_ID::internal::WireFormatLite:: - InternalWriteMessageToArray( + InternalWriteMessage( 4, _Internal::source_context(this), target, stream); } @@ -1697,7 +1711,9 @@ // string name = 1; case 1: if (PROTOBUF_PREDICT_TRUE(static_cast<::PROTOBUF_NAMESPACE_ID::uint8>(tag) == 10)) { - ptr = ::PROTOBUF_NAMESPACE_ID::internal::InlineGreedyStringParserUTF8(_internal_mutable_name(), ptr, ctx, "google.protobuf.EnumValue.name"); + auto str = _internal_mutable_name(); + ptr = ::PROTOBUF_NAMESPACE_ID::internal::InlineGreedyStringParser(str, ptr, ctx); + CHK_(::PROTOBUF_NAMESPACE_ID::internal::VerifyUTF8(str, "google.protobuf.EnumValue.name")); CHK_(ptr); } else goto handle_unusual; continue; @@ -1740,7 +1756,7 @@ #undef CHK_ } -::PROTOBUF_NAMESPACE_ID::uint8* EnumValue::InternalSerializeWithCachedSizesToArray( +::PROTOBUF_NAMESPACE_ID::uint8* EnumValue::_InternalSerialize( ::PROTOBUF_NAMESPACE_ID::uint8* target, ::PROTOBUF_NAMESPACE_ID::io::EpsCopyOutputStream* stream) const { // @@protoc_insertion_point(serialize_to_array_start:google.protobuf.EnumValue) ::PROTOBUF_NAMESPACE_ID::uint32 cached_has_bits = 0; @@ -1767,7 +1783,7 @@ n = static_cast<unsigned int>(this->_internal_options_size()); i < n; i++) { target = stream->EnsureSpace(target); target = ::PROTOBUF_NAMESPACE_ID::internal::WireFormatLite:: - InternalWriteMessageToArray(3, this->_internal_options(i), target, stream); + InternalWriteMessage(3, this->_internal_options(i), target, stream); } if (PROTOBUF_PREDICT_FALSE(_internal_metadata_.have_unknown_fields())) { @@ -1999,7 +2015,9 @@ // string name = 1; case 1: if (PROTOBUF_PREDICT_TRUE(static_cast<::PROTOBUF_NAMESPACE_ID::uint8>(tag) == 10)) { - ptr = ::PROTOBUF_NAMESPACE_ID::internal::InlineGreedyStringParserUTF8(_internal_mutable_name(), ptr, ctx, "google.protobuf.Option.name"); + auto str = _internal_mutable_name(); + ptr = ::PROTOBUF_NAMESPACE_ID::internal::InlineGreedyStringParser(str, ptr, ctx); + CHK_(::PROTOBUF_NAMESPACE_ID::internal::VerifyUTF8(str, "google.protobuf.Option.name")); CHK_(ptr); } else goto handle_unusual; continue; @@ -2030,7 +2048,7 @@ #undef CHK_ } -::PROTOBUF_NAMESPACE_ID::uint8* Option::InternalSerializeWithCachedSizesToArray( +::PROTOBUF_NAMESPACE_ID::uint8* Option::_InternalSerialize( ::PROTOBUF_NAMESPACE_ID::uint8* target, ::PROTOBUF_NAMESPACE_ID::io::EpsCopyOutputStream* stream) const { // @@protoc_insertion_point(serialize_to_array_start:google.protobuf.Option) ::PROTOBUF_NAMESPACE_ID::uint32 cached_has_bits = 0; @@ -2050,7 +2068,7 @@ if (this->has_value()) { target = stream->EnsureSpace(target); target = ::PROTOBUF_NAMESPACE_ID::internal::WireFormatLite:: - InternalWriteMessageToArray( + InternalWriteMessage( 2, _Internal::value(this), target, stream); }
diff --git a/src/google/protobuf/type.pb.h b/src/google/protobuf/type.pb.h index 56d4d0c..679e132 100644 --- a/src/google/protobuf/type.pb.h +++ b/src/google/protobuf/type.pb.h
@@ -264,7 +264,7 @@ size_t ByteSizeLong() const final; const char* _InternalParse(const char* ptr, ::PROTOBUF_NAMESPACE_ID::internal::ParseContext* ctx) final; - ::PROTOBUF_NAMESPACE_ID::uint8* InternalSerializeWithCachedSizesToArray( + ::PROTOBUF_NAMESPACE_ID::uint8* _InternalSerialize( ::PROTOBUF_NAMESPACE_ID::uint8* target, ::PROTOBUF_NAMESPACE_ID::io::EpsCopyOutputStream* stream) const final; int GetCachedSize() const final { return _cached_size_.Get(); } @@ -528,7 +528,7 @@ size_t ByteSizeLong() const final; const char* _InternalParse(const char* ptr, ::PROTOBUF_NAMESPACE_ID::internal::ParseContext* ctx) final; - ::PROTOBUF_NAMESPACE_ID::uint8* InternalSerializeWithCachedSizesToArray( + ::PROTOBUF_NAMESPACE_ID::uint8* _InternalSerialize( ::PROTOBUF_NAMESPACE_ID::uint8* target, ::PROTOBUF_NAMESPACE_ID::io::EpsCopyOutputStream* stream) const final; int GetCachedSize() const final { return _cached_size_.Get(); } @@ -949,7 +949,7 @@ size_t ByteSizeLong() const final; const char* _InternalParse(const char* ptr, ::PROTOBUF_NAMESPACE_ID::internal::ParseContext* ctx) final; - ::PROTOBUF_NAMESPACE_ID::uint8* InternalSerializeWithCachedSizesToArray( + ::PROTOBUF_NAMESPACE_ID::uint8* _InternalSerialize( ::PROTOBUF_NAMESPACE_ID::uint8* target, ::PROTOBUF_NAMESPACE_ID::io::EpsCopyOutputStream* stream) const final; int GetCachedSize() const final { return _cached_size_.Get(); } @@ -1187,7 +1187,7 @@ size_t ByteSizeLong() const final; const char* _InternalParse(const char* ptr, ::PROTOBUF_NAMESPACE_ID::internal::ParseContext* ctx) final; - ::PROTOBUF_NAMESPACE_ID::uint8* InternalSerializeWithCachedSizesToArray( + ::PROTOBUF_NAMESPACE_ID::uint8* _InternalSerialize( ::PROTOBUF_NAMESPACE_ID::uint8* target, ::PROTOBUF_NAMESPACE_ID::io::EpsCopyOutputStream* stream) const final; int GetCachedSize() const final { return _cached_size_.Get(); } @@ -1385,7 +1385,7 @@ size_t ByteSizeLong() const final; const char* _InternalParse(const char* ptr, ::PROTOBUF_NAMESPACE_ID::internal::ParseContext* ctx) final; - ::PROTOBUF_NAMESPACE_ID::uint8* InternalSerializeWithCachedSizesToArray( + ::PROTOBUF_NAMESPACE_ID::uint8* _InternalSerialize( ::PROTOBUF_NAMESPACE_ID::uint8* target, ::PROTOBUF_NAMESPACE_ID::io::EpsCopyOutputStream* stream) const final; int GetCachedSize() const final { return _cached_size_.Get(); }
diff --git a/src/google/protobuf/unittest_lite.proto b/src/google/protobuf/unittest_lite.proto index d6f1149..979c841 100644 --- a/src/google/protobuf/unittest_lite.proto +++ b/src/google/protobuf/unittest_lite.proto
@@ -33,17 +33,16 @@ // This is like unittest.proto but with optimize_for = LITE_RUNTIME. syntax = "proto2"; + package protobuf_unittest; import "google/protobuf/unittest_import_lite.proto"; option optimize_for = LITE_RUNTIME; - option java_package = "com.google.protobuf"; // Same as TestAllTypes but with the lite runtime. message TestAllTypesLite { - message NestedMessage { optional int32 bb = 1; optional int64 cc = 2; @@ -56,104 +55,105 @@ } // Singular - optional int32 optional_int32 = 1; - optional int64 optional_int64 = 2; - optional uint32 optional_uint32 = 3; - optional uint64 optional_uint64 = 4; - optional sint32 optional_sint32 = 5; - optional sint64 optional_sint64 = 6; - optional fixed32 optional_fixed32 = 7; - optional fixed64 optional_fixed64 = 8; - optional sfixed32 optional_sfixed32 = 9; + optional int32 optional_int32 = 1; + optional int64 optional_int64 = 2; + optional uint32 optional_uint32 = 3; + optional uint64 optional_uint64 = 4; + optional sint32 optional_sint32 = 5; + optional sint64 optional_sint64 = 6; + optional fixed32 optional_fixed32 = 7; + optional fixed64 optional_fixed64 = 8; + optional sfixed32 optional_sfixed32 = 9; optional sfixed64 optional_sfixed64 = 10; - optional float optional_float = 11; - optional double optional_double = 12; - optional bool optional_bool = 13; - optional string optional_string = 14; - optional bytes optional_bytes = 15; + optional float optional_float = 11; + optional double optional_double = 12; + optional bool optional_bool = 13; + optional string optional_string = 14; + optional bytes optional_bytes = 15; optional group OptionalGroup = 16 { optional int32 a = 17; } - optional NestedMessage optional_nested_message = 18; + optional NestedMessage optional_nested_message = 18; optional ForeignMessageLite optional_foreign_message = 19; - optional protobuf_unittest_import.ImportMessageLite - optional_import_message = 20; + optional protobuf_unittest_import.ImportMessageLite optional_import_message = + 20; - optional NestedEnum optional_nested_enum = 21; - optional ForeignEnumLite optional_foreign_enum = 22; + optional NestedEnum optional_nested_enum = 21; + optional ForeignEnumLite optional_foreign_enum = 22; optional protobuf_unittest_import.ImportEnumLite optional_import_enum = 23; - optional string optional_string_piece = 24 [ctype=STRING_PIECE]; - optional string optional_cord = 25 [ctype=CORD]; + optional string optional_string_piece = 24 [ctype = STRING_PIECE]; + optional string optional_cord = 25 [ctype = CORD]; // Defined in unittest_import_public.proto optional protobuf_unittest_import.PublicImportMessageLite optional_public_import_message = 26; - optional NestedMessage optional_lazy_message = 27 [lazy=true]; + optional NestedMessage optional_lazy_message = 27 [lazy = true]; // Repeated - repeated int32 repeated_int32 = 31; - repeated int64 repeated_int64 = 32; - repeated uint32 repeated_uint32 = 33; - repeated uint64 repeated_uint64 = 34; - repeated sint32 repeated_sint32 = 35; - repeated sint64 repeated_sint64 = 36; - repeated fixed32 repeated_fixed32 = 37; - repeated fixed64 repeated_fixed64 = 38; + repeated int32 repeated_int32 = 31; + repeated int64 repeated_int64 = 32; + repeated uint32 repeated_uint32 = 33; + repeated uint64 repeated_uint64 = 34; + repeated sint32 repeated_sint32 = 35; + repeated sint64 repeated_sint64 = 36; + repeated fixed32 repeated_fixed32 = 37; + repeated fixed64 repeated_fixed64 = 38; repeated sfixed32 repeated_sfixed32 = 39; repeated sfixed64 repeated_sfixed64 = 40; - repeated float repeated_float = 41; - repeated double repeated_double = 42; - repeated bool repeated_bool = 43; - repeated string repeated_string = 44; - repeated bytes repeated_bytes = 45; + repeated float repeated_float = 41; + repeated double repeated_double = 42; + repeated bool repeated_bool = 43; + repeated string repeated_string = 44; + repeated bytes repeated_bytes = 45; repeated group RepeatedGroup = 46 { optional int32 a = 47; } - repeated NestedMessage repeated_nested_message = 48; + repeated NestedMessage repeated_nested_message = 48; repeated ForeignMessageLite repeated_foreign_message = 49; - repeated protobuf_unittest_import.ImportMessageLite - repeated_import_message = 50; + repeated protobuf_unittest_import.ImportMessageLite repeated_import_message = + 50; - repeated NestedEnum repeated_nested_enum = 51; + repeated NestedEnum repeated_nested_enum = 51; repeated ForeignEnumLite repeated_foreign_enum = 52; repeated protobuf_unittest_import.ImportEnumLite repeated_import_enum = 53; - repeated string repeated_string_piece = 54 [ctype=STRING_PIECE]; - repeated string repeated_cord = 55 [ctype=CORD]; + repeated string repeated_string_piece = 54 [ctype = STRING_PIECE]; + repeated string repeated_cord = 55 [ctype = CORD]; - repeated NestedMessage repeated_lazy_message = 57 [lazy=true]; + repeated NestedMessage repeated_lazy_message = 57 [lazy = true]; // Singular with defaults - optional int32 default_int32 = 61 [default = 41 ]; - optional int64 default_int64 = 62 [default = 42 ]; - optional uint32 default_uint32 = 63 [default = 43 ]; - optional uint64 default_uint64 = 64 [default = 44 ]; - optional sint32 default_sint32 = 65 [default = -45 ]; - optional sint64 default_sint64 = 66 [default = 46 ]; - optional fixed32 default_fixed32 = 67 [default = 47 ]; - optional fixed64 default_fixed64 = 68 [default = 48 ]; - optional sfixed32 default_sfixed32 = 69 [default = 49 ]; - optional sfixed64 default_sfixed64 = 70 [default = -50 ]; - optional float default_float = 71 [default = 51.5 ]; - optional double default_double = 72 [default = 52e3 ]; - optional bool default_bool = 73 [default = true ]; - optional string default_string = 74 [default = "hello"]; - optional bytes default_bytes = 75 [default = "world"]; + optional int32 default_int32 = 61 [default = 41]; + optional int64 default_int64 = 62 [default = 42]; + optional uint32 default_uint32 = 63 [default = 43]; + optional uint64 default_uint64 = 64 [default = 44]; + optional sint32 default_sint32 = 65 [default = -45]; + optional sint64 default_sint64 = 66 [default = 46]; + optional fixed32 default_fixed32 = 67 [default = 47]; + optional fixed64 default_fixed64 = 68 [default = 48]; + optional sfixed32 default_sfixed32 = 69 [default = 49]; + optional sfixed64 default_sfixed64 = 70 [default = -50]; + optional float default_float = 71 [default = 51.5]; + optional double default_double = 72 [default = 52e3]; + optional bool default_bool = 73 [default = true]; + optional string default_string = 74 [default = "hello"]; + optional bytes default_bytes = 75 [default = "world"]; optional NestedEnum default_nested_enum = 81 [default = BAR]; optional ForeignEnumLite default_foreign_enum = 82 [default = FOREIGN_LITE_BAR]; - optional protobuf_unittest_import.ImportEnumLite - default_import_enum = 83 [default = IMPORT_LITE_BAR]; + optional protobuf_unittest_import.ImportEnumLite default_import_enum = 83 + [default = IMPORT_LITE_BAR]; - optional string default_string_piece = 84 [ctype=STRING_PIECE,default="abc"]; - optional string default_cord = 85 [ctype=CORD,default="123"]; + optional string default_string_piece = 84 + [ctype = STRING_PIECE, default = "abc"]; + optional string default_cord = 85 [ctype = CORD, default = "123"]; // For oneof test oneof oneof_field { @@ -179,20 +179,20 @@ } message TestPackedTypesLite { - repeated int32 packed_int32 = 90 [packed = true]; - repeated int64 packed_int64 = 91 [packed = true]; - repeated uint32 packed_uint32 = 92 [packed = true]; - repeated uint64 packed_uint64 = 93 [packed = true]; - repeated sint32 packed_sint32 = 94 [packed = true]; - repeated sint64 packed_sint64 = 95 [packed = true]; - repeated fixed32 packed_fixed32 = 96 [packed = true]; - repeated fixed64 packed_fixed64 = 97 [packed = true]; - repeated sfixed32 packed_sfixed32 = 98 [packed = true]; - repeated sfixed64 packed_sfixed64 = 99 [packed = true]; - repeated float packed_float = 100 [packed = true]; - repeated double packed_double = 101 [packed = true]; - repeated bool packed_bool = 102 [packed = true]; - repeated ForeignEnumLite packed_enum = 103 [packed = true]; + repeated int32 packed_int32 = 90 [packed = true]; + repeated int64 packed_int64 = 91 [packed = true]; + repeated uint32 packed_uint32 = 92 [packed = true]; + repeated uint64 packed_uint64 = 93 [packed = true]; + repeated sint32 packed_sint32 = 94 [packed = true]; + repeated sint64 packed_sint64 = 95 [packed = true]; + repeated fixed32 packed_fixed32 = 96 [packed = true]; + repeated fixed64 packed_fixed64 = 97 [packed = true]; + repeated sfixed32 packed_sfixed32 = 98 [packed = true]; + repeated sfixed64 packed_sfixed64 = 99 [packed = true]; + repeated float packed_float = 100 [packed = true]; + repeated double packed_double = 101 [packed = true]; + repeated bool packed_bool = 102 [packed = true]; + repeated ForeignEnumLite packed_enum = 103 [packed = true]; } message TestAllExtensionsLite { @@ -201,117 +201,119 @@ extend TestAllExtensionsLite { // Singular - optional int32 optional_int32_extension_lite = 1; - optional int64 optional_int64_extension_lite = 2; - optional uint32 optional_uint32_extension_lite = 3; - optional uint64 optional_uint64_extension_lite = 4; - optional sint32 optional_sint32_extension_lite = 5; - optional sint64 optional_sint64_extension_lite = 6; - optional fixed32 optional_fixed32_extension_lite = 7; - optional fixed64 optional_fixed64_extension_lite = 8; - optional sfixed32 optional_sfixed32_extension_lite = 9; + optional int32 optional_int32_extension_lite = 1; + optional int64 optional_int64_extension_lite = 2; + optional uint32 optional_uint32_extension_lite = 3; + optional uint64 optional_uint64_extension_lite = 4; + optional sint32 optional_sint32_extension_lite = 5; + optional sint64 optional_sint64_extension_lite = 6; + optional fixed32 optional_fixed32_extension_lite = 7; + optional fixed64 optional_fixed64_extension_lite = 8; + optional sfixed32 optional_sfixed32_extension_lite = 9; optional sfixed64 optional_sfixed64_extension_lite = 10; - optional float optional_float_extension_lite = 11; - optional double optional_double_extension_lite = 12; - optional bool optional_bool_extension_lite = 13; - optional string optional_string_extension_lite = 14; - optional bytes optional_bytes_extension_lite = 15; + optional float optional_float_extension_lite = 11; + optional double optional_double_extension_lite = 12; + optional bool optional_bool_extension_lite = 13; + optional string optional_string_extension_lite = 14; + optional bytes optional_bytes_extension_lite = 15; optional group OptionalGroup_extension_lite = 16 { optional int32 a = 17; } - optional TestAllTypesLite.NestedMessage optional_nested_message_extension_lite - = 18; + optional TestAllTypesLite.NestedMessage + optional_nested_message_extension_lite = 18; optional ForeignMessageLite optional_foreign_message_extension_lite = 19; optional protobuf_unittest_import.ImportMessageLite - optional_import_message_extension_lite = 20; + optional_import_message_extension_lite = 20; optional TestAllTypesLite.NestedEnum optional_nested_enum_extension_lite = 21; optional ForeignEnumLite optional_foreign_enum_extension_lite = 22; optional protobuf_unittest_import.ImportEnumLite - optional_import_enum_extension_lite = 23; + optional_import_enum_extension_lite = 23; optional string optional_string_piece_extension_lite = 24 - [ctype=STRING_PIECE]; - optional string optional_cord_extension_lite = 25 [ctype=CORD]; + [ctype = STRING_PIECE]; + optional string optional_cord_extension_lite = 25 [ctype = CORD]; optional protobuf_unittest_import.PublicImportMessageLite - optional_public_import_message_extension_lite = 26; + optional_public_import_message_extension_lite = 26; - optional TestAllTypesLite.NestedMessage - optional_lazy_message_extension_lite = 27 [lazy=true]; + optional TestAllTypesLite.NestedMessage optional_lazy_message_extension_lite = + 27 [lazy = true]; // Repeated - repeated int32 repeated_int32_extension_lite = 31; - repeated int64 repeated_int64_extension_lite = 32; - repeated uint32 repeated_uint32_extension_lite = 33; - repeated uint64 repeated_uint64_extension_lite = 34; - repeated sint32 repeated_sint32_extension_lite = 35; - repeated sint64 repeated_sint64_extension_lite = 36; - repeated fixed32 repeated_fixed32_extension_lite = 37; - repeated fixed64 repeated_fixed64_extension_lite = 38; + repeated int32 repeated_int32_extension_lite = 31; + repeated int64 repeated_int64_extension_lite = 32; + repeated uint32 repeated_uint32_extension_lite = 33; + repeated uint64 repeated_uint64_extension_lite = 34; + repeated sint32 repeated_sint32_extension_lite = 35; + repeated sint64 repeated_sint64_extension_lite = 36; + repeated fixed32 repeated_fixed32_extension_lite = 37; + repeated fixed64 repeated_fixed64_extension_lite = 38; repeated sfixed32 repeated_sfixed32_extension_lite = 39; repeated sfixed64 repeated_sfixed64_extension_lite = 40; - repeated float repeated_float_extension_lite = 41; - repeated double repeated_double_extension_lite = 42; - repeated bool repeated_bool_extension_lite = 43; - repeated string repeated_string_extension_lite = 44; - repeated bytes repeated_bytes_extension_lite = 45; + repeated float repeated_float_extension_lite = 41; + repeated double repeated_double_extension_lite = 42; + repeated bool repeated_bool_extension_lite = 43; + repeated string repeated_string_extension_lite = 44; + repeated bytes repeated_bytes_extension_lite = 45; repeated group RepeatedGroup_extension_lite = 46 { optional int32 a = 47; } - repeated TestAllTypesLite.NestedMessage repeated_nested_message_extension_lite - = 48; + repeated TestAllTypesLite.NestedMessage + repeated_nested_message_extension_lite = 48; repeated ForeignMessageLite repeated_foreign_message_extension_lite = 49; repeated protobuf_unittest_import.ImportMessageLite - repeated_import_message_extension_lite = 50; + repeated_import_message_extension_lite = 50; repeated TestAllTypesLite.NestedEnum repeated_nested_enum_extension_lite = 51; repeated ForeignEnumLite repeated_foreign_enum_extension_lite = 52; repeated protobuf_unittest_import.ImportEnumLite - repeated_import_enum_extension_lite = 53; + repeated_import_enum_extension_lite = 53; repeated string repeated_string_piece_extension_lite = 54 - [ctype=STRING_PIECE]; - repeated string repeated_cord_extension_lite = 55 [ctype=CORD]; + [ctype = STRING_PIECE]; + repeated string repeated_cord_extension_lite = 55 [ctype = CORD]; - repeated TestAllTypesLite.NestedMessage - repeated_lazy_message_extension_lite = 57 [lazy=true]; + repeated TestAllTypesLite.NestedMessage repeated_lazy_message_extension_lite = + 57 [lazy = true]; // Singular with defaults - optional int32 default_int32_extension_lite = 61 [default = 41 ]; - optional int64 default_int64_extension_lite = 62 [default = 42 ]; - optional uint32 default_uint32_extension_lite = 63 [default = 43 ]; - optional uint64 default_uint64_extension_lite = 64 [default = 44 ]; - optional sint32 default_sint32_extension_lite = 65 [default = -45 ]; - optional sint64 default_sint64_extension_lite = 66 [default = 46 ]; - optional fixed32 default_fixed32_extension_lite = 67 [default = 47 ]; - optional fixed64 default_fixed64_extension_lite = 68 [default = 48 ]; - optional sfixed32 default_sfixed32_extension_lite = 69 [default = 49 ]; - optional sfixed64 default_sfixed64_extension_lite = 70 [default = -50 ]; - optional float default_float_extension_lite = 71 [default = 51.5 ]; - optional double default_double_extension_lite = 72 [default = 52e3 ]; - optional bool default_bool_extension_lite = 73 [default = true ]; - optional string default_string_extension_lite = 74 [default = "hello"]; - optional bytes default_bytes_extension_lite = 75 [default = "world"]; + optional int32 default_int32_extension_lite = 61 [default = 41]; + optional int64 default_int64_extension_lite = 62 [default = 42]; + optional uint32 default_uint32_extension_lite = 63 [default = 43]; + optional uint64 default_uint64_extension_lite = 64 [default = 44]; + optional sint32 default_sint32_extension_lite = 65 [default = -45]; + optional sint64 default_sint64_extension_lite = 66 [default = 46]; + optional fixed32 default_fixed32_extension_lite = 67 [default = 47]; + optional fixed64 default_fixed64_extension_lite = 68 [default = 48]; + optional sfixed32 default_sfixed32_extension_lite = 69 [default = 49]; + optional sfixed64 default_sfixed64_extension_lite = 70 [default = -50]; + optional float default_float_extension_lite = 71 [default = 51.5]; + optional double default_double_extension_lite = 72 [default = 52e3]; + optional bool default_bool_extension_lite = 73 [default = true]; + optional string default_string_extension_lite = 74 [default = "hello"]; + optional bytes default_bytes_extension_lite = 75 [default = "world"]; - optional TestAllTypesLite.NestedEnum - default_nested_enum_extension_lite = 81 [default = BAR]; - optional ForeignEnumLite - default_foreign_enum_extension_lite = 82 [default = FOREIGN_LITE_BAR]; + optional TestAllTypesLite.NestedEnum default_nested_enum_extension_lite = 81 + [default = BAR]; + optional ForeignEnumLite default_foreign_enum_extension_lite = 82 + [default = FOREIGN_LITE_BAR]; optional protobuf_unittest_import.ImportEnumLite - default_import_enum_extension_lite = 83 [default = IMPORT_LITE_BAR]; + default_import_enum_extension_lite = 83 [default = IMPORT_LITE_BAR]; - optional string default_string_piece_extension_lite = 84 [ctype=STRING_PIECE, - default="abc"]; - optional string default_cord_extension_lite = 85 [ctype=CORD, default="123"]; + optional string default_string_piece_extension_lite = 84 + [ctype = STRING_PIECE, default = "abc"]; + optional string default_cord_extension_lite = 85 + [ctype = CORD, default = "123"]; // For oneof test optional uint32 oneof_uint32_extension_lite = 111; - optional TestAllTypesLite.NestedMessage oneof_nested_message_extension_lite = 112; + optional TestAllTypesLite.NestedMessage oneof_nested_message_extension_lite = + 112; optional string oneof_string_extension_lite = 113; optional bytes oneof_bytes_extension_lite = 114; } @@ -321,19 +323,19 @@ } extend TestPackedExtensionsLite { - repeated int32 packed_int32_extension_lite = 90 [packed = true]; - repeated int64 packed_int64_extension_lite = 91 [packed = true]; - repeated uint32 packed_uint32_extension_lite = 92 [packed = true]; - repeated uint64 packed_uint64_extension_lite = 93 [packed = true]; - repeated sint32 packed_sint32_extension_lite = 94 [packed = true]; - repeated sint64 packed_sint64_extension_lite = 95 [packed = true]; - repeated fixed32 packed_fixed32_extension_lite = 96 [packed = true]; - repeated fixed64 packed_fixed64_extension_lite = 97 [packed = true]; - repeated sfixed32 packed_sfixed32_extension_lite = 98 [packed = true]; - repeated sfixed64 packed_sfixed64_extension_lite = 99 [packed = true]; - repeated float packed_float_extension_lite = 100 [packed = true]; - repeated double packed_double_extension_lite = 101 [packed = true]; - repeated bool packed_bool_extension_lite = 102 [packed = true]; + repeated int32 packed_int32_extension_lite = 90 [packed = true]; + repeated int64 packed_int64_extension_lite = 91 [packed = true]; + repeated uint32 packed_uint32_extension_lite = 92 [packed = true]; + repeated uint64 packed_uint64_extension_lite = 93 [packed = true]; + repeated sint32 packed_sint32_extension_lite = 94 [packed = true]; + repeated sint64 packed_sint64_extension_lite = 95 [packed = true]; + repeated fixed32 packed_fixed32_extension_lite = 96 [packed = true]; + repeated fixed64 packed_fixed64_extension_lite = 97 [packed = true]; + repeated sfixed32 packed_sfixed32_extension_lite = 98 [packed = true]; + repeated sfixed64 packed_sfixed64_extension_lite = 99 [packed = true]; + repeated float packed_float_extension_lite = 100 [packed = true]; + repeated double packed_double_extension_lite = 101 [packed = true]; + repeated bool packed_bool_extension_lite = 102 [packed = true]; repeated ForeignEnumLite packed_enum_extension_lite = 103 [packed = true]; } @@ -347,6 +349,9 @@ // point this failed). message TestDeprecatedLite { optional int32 deprecated_field = 1 [deprecated = true]; + required int32 deprecated_field2 = 2 [deprecated = true]; + optional string deprecated_field3 = 3 [deprecated = true]; + optional TestDeprecatedLite deprecated_field4 = 4 [deprecated = true]; } // See the comments of the same type in unittest.proto. @@ -381,8 +386,7 @@ } // TestEmptyMessageLite is used to test unknown fields support in lite mode. -message TestEmptyMessageLite{ -} +message TestEmptyMessageLite {} // Like above, but declare all field numbers as potential extensions. No // actual extensions should ever be defined for this type. @@ -390,23 +394,21 @@ extensions 1 to max; } -enum V1EnumLite { - V1_FIRST = 1; -} +enum V1EnumLite { V1_FIRST = 1; } enum V2EnumLite { - V2_FIRST = 1; - V2_SECOND = 2; + V2_FIRST = 1; + V2_SECOND = 2; } message V1MessageLite { - required int32 int_field = 1; - optional V1EnumLite enum_field = 2 [ default = V1_FIRST ]; + required int32 int_field = 1; + optional V1EnumLite enum_field = 2 [default = V1_FIRST]; } message V2MessageLite { - required int32 int_field = 1; - optional V2EnumLite enum_field = 2 [ default = V2_FIRST ]; + required int32 int_field = 1; + optional V2EnumLite enum_field = 2 [default = V2_FIRST]; } message TestHugeFieldNumbersLite { @@ -433,7 +435,7 @@ bytes oneof_bytes = 536870014; } - extensions 536860000 to 536869999; + extensions 536860000 to 536869999; } extend TestHugeFieldNumbersLite {
diff --git a/src/google/protobuf/unittest_proto3.proto b/src/google/protobuf/unittest_proto3.proto index 1c3bf91..e93622a 100644 --- a/src/google/protobuf/unittest_proto3.proto +++ b/src/google/protobuf/unittest_proto3.proto
@@ -30,11 +30,11 @@ syntax = "proto3"; -option optimize_for = SPEED; +package proto3_unittest; import "google/protobuf/unittest_import.proto"; -package proto3_unittest; +option optimize_for = SPEED; // This proto includes every type of field in both singular and repeated // forms. @@ -55,88 +55,88 @@ } // Singular - int32 optional_int32 = 1; - int64 optional_int64 = 2; - uint32 optional_uint32 = 3; - uint64 optional_uint64 = 4; - sint32 optional_sint32 = 5; - sint64 optional_sint64 = 6; - fixed32 optional_fixed32 = 7; - fixed64 optional_fixed64 = 8; - sfixed32 optional_sfixed32 = 9; + int32 optional_int32 = 1; + int64 optional_int64 = 2; + uint32 optional_uint32 = 3; + uint64 optional_uint64 = 4; + sint32 optional_sint32 = 5; + sint64 optional_sint64 = 6; + fixed32 optional_fixed32 = 7; + fixed64 optional_fixed64 = 8; + sfixed32 optional_sfixed32 = 9; sfixed64 optional_sfixed64 = 10; - float optional_float = 11; - double optional_double = 12; - bool optional_bool = 13; - string optional_string = 14; - bytes optional_bytes = 15; + float optional_float = 11; + double optional_double = 12; + bool optional_bool = 13; + string optional_string = 14; + bytes optional_bytes = 15; // Groups are not allowed in proto3. // optional group OptionalGroup = 16 { // optional int32 a = 17; // } - NestedMessage optional_nested_message = 18; - ForeignMessage optional_foreign_message = 19; - protobuf_unittest_import.ImportMessage optional_import_message = 20; + NestedMessage optional_nested_message = 18; + ForeignMessage optional_foreign_message = 19; + protobuf_unittest_import.ImportMessage optional_import_message = 20; - NestedEnum optional_nested_enum = 21; - ForeignEnum optional_foreign_enum = 22; + NestedEnum optional_nested_enum = 21; + ForeignEnum optional_foreign_enum = 22; // Omitted (compared to unittest.proto) because proto2 enums are not allowed // inside proto2 messages. // // optional protobuf_unittest_import.ImportEnum optional_import_enum = 23; - string optional_string_piece = 24 [ctype=STRING_PIECE]; - string optional_cord = 25 [ctype=CORD]; + string optional_string_piece = 24 [ctype = STRING_PIECE]; + string optional_cord = 25 [ctype = CORD]; // Defined in unittest_import_public.proto - protobuf_unittest_import.PublicImportMessage - optional_public_import_message = 26; + protobuf_unittest_import.PublicImportMessage optional_public_import_message = + 26; - NestedMessage optional_lazy_message = 27 [lazy=true]; + NestedMessage optional_lazy_message = 27 [lazy = true]; protobuf_unittest_import.ImportMessage optional_lazy_import_message = 115 [lazy = true]; // Repeated - repeated int32 repeated_int32 = 31; - repeated int64 repeated_int64 = 32; - repeated uint32 repeated_uint32 = 33; - repeated uint64 repeated_uint64 = 34; - repeated sint32 repeated_sint32 = 35; - repeated sint64 repeated_sint64 = 36; - repeated fixed32 repeated_fixed32 = 37; - repeated fixed64 repeated_fixed64 = 38; + repeated int32 repeated_int32 = 31; + repeated int64 repeated_int64 = 32; + repeated uint32 repeated_uint32 = 33; + repeated uint64 repeated_uint64 = 34; + repeated sint32 repeated_sint32 = 35; + repeated sint64 repeated_sint64 = 36; + repeated fixed32 repeated_fixed32 = 37; + repeated fixed64 repeated_fixed64 = 38; repeated sfixed32 repeated_sfixed32 = 39; repeated sfixed64 repeated_sfixed64 = 40; - repeated float repeated_float = 41; - repeated double repeated_double = 42; - repeated bool repeated_bool = 43; - repeated string repeated_string = 44; - repeated bytes repeated_bytes = 45; + repeated float repeated_float = 41; + repeated double repeated_double = 42; + repeated bool repeated_bool = 43; + repeated string repeated_string = 44; + repeated bytes repeated_bytes = 45; // Groups are not allowed in proto3. // repeated group RepeatedGroup = 46 { // optional int32 a = 47; // } - repeated NestedMessage repeated_nested_message = 48; - repeated ForeignMessage repeated_foreign_message = 49; - repeated protobuf_unittest_import.ImportMessage repeated_import_message = 50; + repeated NestedMessage repeated_nested_message = 48; + repeated ForeignMessage repeated_foreign_message = 49; + repeated protobuf_unittest_import.ImportMessage repeated_import_message = 50; - repeated NestedEnum repeated_nested_enum = 51; - repeated ForeignEnum repeated_foreign_enum = 52; + repeated NestedEnum repeated_nested_enum = 51; + repeated ForeignEnum repeated_foreign_enum = 52; // Omitted (compared to unittest.proto) because proto2 enums are not allowed // inside proto2 messages. // // repeated protobuf_unittest_import.ImportEnum repeated_import_enum = 53; - repeated string repeated_string_piece = 54 [ctype=STRING_PIECE]; - repeated string repeated_cord = 55 [ctype=CORD]; + repeated string repeated_string_piece = 54 [ctype = STRING_PIECE]; + repeated string repeated_cord = 55 [ctype = CORD]; - repeated NestedMessage repeated_lazy_message = 57 [lazy=true]; + repeated NestedMessage repeated_lazy_message = 57 [lazy = true]; oneof oneof_field { uint32 oneof_uint32 = 111; @@ -149,37 +149,37 @@ // Test messages for packed fields message TestPackedTypes { - repeated int32 packed_int32 = 90 [packed = true]; - repeated int64 packed_int64 = 91 [packed = true]; - repeated uint32 packed_uint32 = 92 [packed = true]; - repeated uint64 packed_uint64 = 93 [packed = true]; - repeated sint32 packed_sint32 = 94 [packed = true]; - repeated sint64 packed_sint64 = 95 [packed = true]; - repeated fixed32 packed_fixed32 = 96 [packed = true]; - repeated fixed64 packed_fixed64 = 97 [packed = true]; - repeated sfixed32 packed_sfixed32 = 98 [packed = true]; - repeated sfixed64 packed_sfixed64 = 99 [packed = true]; - repeated float packed_float = 100 [packed = true]; - repeated double packed_double = 101 [packed = true]; - repeated bool packed_bool = 102 [packed = true]; - repeated ForeignEnum packed_enum = 103 [packed = true]; + repeated int32 packed_int32 = 90 [packed = true]; + repeated int64 packed_int64 = 91 [packed = true]; + repeated uint32 packed_uint32 = 92 [packed = true]; + repeated uint64 packed_uint64 = 93 [packed = true]; + repeated sint32 packed_sint32 = 94 [packed = true]; + repeated sint64 packed_sint64 = 95 [packed = true]; + repeated fixed32 packed_fixed32 = 96 [packed = true]; + repeated fixed64 packed_fixed64 = 97 [packed = true]; + repeated sfixed32 packed_sfixed32 = 98 [packed = true]; + repeated sfixed64 packed_sfixed64 = 99 [packed = true]; + repeated float packed_float = 100 [packed = true]; + repeated double packed_double = 101 [packed = true]; + repeated bool packed_bool = 102 [packed = true]; + repeated ForeignEnum packed_enum = 103 [packed = true]; } // Explicitly set packed to false message TestUnpackedTypes { - repeated int32 repeated_int32 = 1 [packed = false]; - repeated int64 repeated_int64 = 2 [packed = false]; - repeated uint32 repeated_uint32 = 3 [packed = false]; - repeated uint64 repeated_uint64 = 4 [packed = false]; - repeated sint32 repeated_sint32 = 5 [packed = false]; - repeated sint64 repeated_sint64 = 6 [packed = false]; - repeated fixed32 repeated_fixed32 = 7 [packed = false]; - repeated fixed64 repeated_fixed64 = 8 [packed = false]; - repeated sfixed32 repeated_sfixed32 = 9 [packed = false]; + repeated int32 repeated_int32 = 1 [packed = false]; + repeated int64 repeated_int64 = 2 [packed = false]; + repeated uint32 repeated_uint32 = 3 [packed = false]; + repeated uint64 repeated_uint64 = 4 [packed = false]; + repeated sint32 repeated_sint32 = 5 [packed = false]; + repeated sint64 repeated_sint64 = 6 [packed = false]; + repeated fixed32 repeated_fixed32 = 7 [packed = false]; + repeated fixed64 repeated_fixed64 = 8 [packed = false]; + repeated sfixed32 repeated_sfixed32 = 9 [packed = false]; repeated sfixed64 repeated_sfixed64 = 10 [packed = false]; - repeated float repeated_float = 11 [packed = false]; - repeated double repeated_double = 12 [packed = false]; - repeated bool repeated_bool = 13 [packed = false]; + repeated float repeated_float = 11 [packed = false]; + repeated double repeated_double = 12 [packed = false]; + repeated bool repeated_bool = 13 [packed = false]; repeated TestAllTypes.NestedEnum repeated_nested_enum = 14 [packed = false]; } @@ -203,7 +203,13 @@ } // TestEmptyMessage is used to test behavior of unknown fields. -message TestEmptyMessage { +message TestEmptyMessage {} + +// TestMessageWithDummy is also used to test behavior of unknown fields. +message TestMessageWithDummy { + // This field is only here for triggering copy-on-write; it's not intended to + // be serialized. + bool dummy = 536870911; } // Same layout as TestOneof2 in unittest.proto to test unknown enum value
diff --git a/src/google/protobuf/util/field_comparator.cc b/src/google/protobuf/util/field_comparator.cc index 3316506..54abcd4 100644 --- a/src/google/protobuf/util/field_comparator.cc +++ b/src/google/protobuf/util/field_comparator.cc
@@ -32,13 +32,13 @@ #include <google/protobuf/util/field_comparator.h> +#include <limits> #include <string> #include <google/protobuf/descriptor.h> #include <google/protobuf/message.h> #include <google/protobuf/util/message_differencer.h> #include <google/protobuf/stubs/map_util.h> -#include <google/protobuf/stubs/mathlimits.h> #include <google/protobuf/stubs/mathutil.h> namespace google { @@ -175,14 +175,12 @@ // themselves), and is a shortcut for finite values. return true; } else if (float_comparison_ == EXACT) { - if (treat_nan_as_equal_ && MathLimits<T>::IsNaN(value_1) && - MathLimits<T>::IsNaN(value_2)) { + if (treat_nan_as_equal_ && std::isnan(value_1) && std::isnan(value_2)) { return true; } return false; } else { - if (treat_nan_as_equal_ && MathLimits<T>::IsNaN(value_1) && - MathLimits<T>::IsNaN(value_2)) { + if (treat_nan_as_equal_ && std::isnan(value_1) && std::isnan(value_2)) { return true; } // float_comparison_ == APPROXIMATE covers two use cases.
diff --git a/src/google/protobuf/util/field_comparator_test.cc b/src/google/protobuf/util/field_comparator_test.cc index 7e538f8..90a5caf 100644 --- a/src/google/protobuf/util/field_comparator_test.cc +++ b/src/google/protobuf/util/field_comparator_test.cc
@@ -32,16 +32,13 @@ #include <google/protobuf/util/field_comparator.h> +#include <limits> + #include <google/protobuf/unittest.pb.h> #include <google/protobuf/descriptor.h> -#include <google/protobuf/stubs/mathutil.h> -// This gtest header is put after mathutil.h intentionally. We have to do -// this because mathutil.h includes mathlimits.h which requires cmath not -// being included to compile on some versions of gcc: -// https://github.com/protocolbuffers/protobuf/blob/818c5eee08840355d70d2f3bdf1a2f17986a5e70/src/google/protobuf/stubs/mathlimits.h#L48 -// and the opensource version gtest.h header includes cmath transitively -// somehow. #include <gtest/gtest.h> +#include <google/protobuf/stubs/mathutil.h> + namespace google { namespace protobuf { namespace util { @@ -248,10 +245,10 @@ const FieldDescriptor* field_double = descriptor_->FindFieldByName("optional_double"); - message_1_.set_optional_float(MathLimits<float>::kNaN); - message_2_.set_optional_float(MathLimits<float>::kNaN); - message_1_.set_optional_double(MathLimits<double>::kNaN); - message_2_.set_optional_double(MathLimits<double>::kNaN); + message_1_.set_optional_float(std::numeric_limits<float>::quiet_NaN()); + message_2_.set_optional_float(std::numeric_limits<float>::quiet_NaN()); + message_1_.set_optional_double(std::numeric_limits<double>::quiet_NaN()); + message_2_.set_optional_double(std::numeric_limits<double>::quiet_NaN()); // DefaultFieldComparator's default float comparison mode is EXACT with // treating NaNs as different.
diff --git a/src/google/protobuf/util/internal/datapiece.cc b/src/google/protobuf/util/internal/datapiece.cc index 1ab0b86..041ff7b 100644 --- a/src/google/protobuf/util/internal/datapiece.cc +++ b/src/google/protobuf/util/internal/datapiece.cc
@@ -30,12 +30,14 @@ #include <google/protobuf/util/internal/datapiece.h> +#include <cmath> +#include <limits> + #include <google/protobuf/struct.pb.h> #include <google/protobuf/type.pb.h> #include <google/protobuf/descriptor.h> #include <google/protobuf/util/internal/utility.h> #include <google/protobuf/stubs/strutil.h> -#include <google/protobuf/stubs/mathlimits.h> #include <google/protobuf/stubs/mathutil.h> namespace google { @@ -96,9 +98,9 @@ } StatusOr<float> DoubleToFloat(double before) { - if (MathLimits<double>::IsNaN(before)) { + if (std::isnan(before)) { return std::numeric_limits<float>::quiet_NaN(); - } else if (!MathLimits<double>::IsFinite(before)) { + } else if (!std::isfinite(before)) { // Converting a double +inf/-inf to float should just work. return static_cast<float>(before); } else if (before > std::numeric_limits<float>::max() || @@ -171,7 +173,7 @@ if (str_ == "-Infinity") return -std::numeric_limits<double>::infinity(); if (str_ == "NaN") return std::numeric_limits<double>::quiet_NaN(); StatusOr<double> value = StringToNumber<double>(safe_strtod); - if (value.ok() && !MathLimits<double>::IsFinite(value.ValueOrDie())) { + if (value.ok() && !std::isfinite(value.ValueOrDie())) { // safe_strtod converts out-of-range values to +inf/-inf, but we want // to report them as errors. return InvalidArgument(StrCat("\"", str_, "\""));
diff --git a/src/google/protobuf/util/internal/json_objectwriter.cc b/src/google/protobuf/util/internal/json_objectwriter.cc index 54a405a..a98e7ba 100644 --- a/src/google/protobuf/util/internal/json_objectwriter.cc +++ b/src/google/protobuf/util/internal/json_objectwriter.cc
@@ -30,7 +30,8 @@ #include <google/protobuf/util/internal/json_objectwriter.h> -#include <math.h> +#include <cmath> +#include <limits> #include <google/protobuf/stubs/casts.h> #include <google/protobuf/stubs/logging.h> @@ -38,7 +39,6 @@ #include <google/protobuf/util/internal/utility.h> #include <google/protobuf/util/internal/json_escaping.h> #include <google/protobuf/stubs/strutil.h> -#include <google/protobuf/stubs/mathlimits.h> namespace google { namespace protobuf { @@ -115,7 +115,7 @@ JsonObjectWriter* JsonObjectWriter::RenderDouble(StringPiece name, double value) { - if (MathLimits<double>::IsFinite(value)) { + if (std::isfinite(value)) { return RenderSimple(name, SimpleDtoa(value)); } @@ -125,7 +125,7 @@ JsonObjectWriter* JsonObjectWriter::RenderFloat(StringPiece name, float value) { - if (MathLimits<float>::IsFinite(value)) { + if (std::isfinite(value)) { return RenderSimple(name, SimpleFtoa(value)); }
diff --git a/src/google/protobuf/util/internal/json_stream_parser.cc b/src/google/protobuf/util/internal/json_stream_parser.cc index 2ecdb3c..a221b98 100644 --- a/src/google/protobuf/util/internal/json_stream_parser.cc +++ b/src/google/protobuf/util/internal/json_stream_parser.cc
@@ -33,8 +33,10 @@ #include <algorithm> #include <cctype> #include <cerrno> +#include <cmath> #include <cstdlib> #include <cstring> +#include <limits> #include <memory> #include <google/protobuf/stubs/logging.h> @@ -42,7 +44,6 @@ #include <google/protobuf/stubs/strutil.h> #include <google/protobuf/util/internal/object_writer.h> #include <google/protobuf/util/internal/json_escaping.h> -#include <google/protobuf/stubs/mathlimits.h> namespace google { @@ -527,8 +528,7 @@ if (!safe_strtod(number, &result->double_val)) { return ReportFailure("Unable to parse number."); } - if (!loose_float_number_conversion_ && - !MathLimits<double>::IsFinite(result->double_val)) { + if (!loose_float_number_conversion_ && !std::isfinite(result->double_val)) { return ReportFailure("Number exceeds the range of double."); } result->type = NumberResult::DOUBLE;
diff --git a/src/google/protobuf/util/internal/json_stream_parser_test.cc b/src/google/protobuf/util/internal/json_stream_parser_test.cc index 398363a..6bb22a6 100644 --- a/src/google/protobuf/util/internal/json_stream_parser_test.cc +++ b/src/google/protobuf/util/internal/json_stream_parser_test.cc
@@ -130,7 +130,7 @@ if (!result.ok()) { GOOGLE_LOG(WARNING) << result; } - EXPECT_OK(result); + EXPECT_TRUE(result.ok()); } void DoErrorTest(
diff --git a/src/google/protobuf/util/internal/protostream_objectsource.cc b/src/google/protobuf/util/internal/protostream_objectsource.cc index 89f424b..4fc026f 100644 --- a/src/google/protobuf/util/internal/protostream_objectsource.cc +++ b/src/google/protobuf/util/internal/protostream_objectsource.cc
@@ -128,7 +128,8 @@ render_unknown_fields_(false), render_unknown_enum_values_(true), add_trailing_zeros_for_timestamp_and_duration_(false), - suppress_empty_object_(false) { + suppress_empty_object_(false), + use_legacy_json_map_format_(false) { GOOGLE_LOG_IF(DFATAL, stream == nullptr) << "Input stream is nullptr."; } @@ -147,7 +148,8 @@ render_unknown_fields_(false), render_unknown_enum_values_(true), add_trailing_zeros_for_timestamp_and_duration_(false), - suppress_empty_object_(false) { + suppress_empty_object_(false), + use_legacy_json_map_format_(false) { GOOGLE_LOG_IF(DFATAL, stream == nullptr) << "Input stream is nullptr."; }
diff --git a/src/google/protobuf/util/internal/protostream_objectsource.h b/src/google/protobuf/util/internal/protostream_objectsource.h index 9a9a74c..a83031d 100644 --- a/src/google/protobuf/util/internal/protostream_objectsource.h +++ b/src/google/protobuf/util/internal/protostream_objectsource.h
@@ -324,6 +324,8 @@ // the fields of the message are filtered out by field mask. bool suppress_empty_object_; + bool use_legacy_json_map_format_; + GOOGLE_DISALLOW_IMPLICIT_CONSTRUCTORS(ProtoStreamObjectSource); };
diff --git a/src/google/protobuf/util/internal/utility.cc b/src/google/protobuf/util/internal/utility.cc index fb958e0..e3cdbcb 100644 --- a/src/google/protobuf/util/internal/utility.cc +++ b/src/google/protobuf/util/internal/utility.cc
@@ -31,6 +31,8 @@ #include <google/protobuf/util/internal/utility.h> #include <algorithm> +#include <cmath> +#include <limits> #include <google/protobuf/stubs/callback.h> #include <google/protobuf/stubs/common.h> @@ -41,7 +43,6 @@ #include <google/protobuf/util/internal/constants.h> #include <google/protobuf/stubs/strutil.h> #include <google/protobuf/stubs/map_util.h> -#include <google/protobuf/stubs/mathlimits.h> // clang-format off #include <google/protobuf/port_def.inc> @@ -377,15 +378,15 @@ } std::string DoubleAsString(double value) { - if (MathLimits<double>::IsPosInf(value)) return "Infinity"; - if (MathLimits<double>::IsNegInf(value)) return "-Infinity"; - if (MathLimits<double>::IsNaN(value)) return "NaN"; + if (value == std::numeric_limits<double>::infinity()) return "Infinity"; + if (value == -std::numeric_limits<double>::infinity()) return "-Infinity"; + if (std::isnan(value)) return "NaN"; return SimpleDtoa(value); } std::string FloatAsString(float value) { - if (MathLimits<float>::IsFinite(value)) return SimpleFtoa(value); + if (std::isfinite(value)) return SimpleFtoa(value); return DoubleAsString(value); } @@ -395,9 +396,7 @@ return false; } - if (MathLimits<double>::IsInf(double_value) || - MathLimits<double>::IsNaN(double_value)) - return false; + if (std::isinf(double_value) || std::isnan(double_value)) return false; // Fail if the value is not representable in float. if (double_value > std::numeric_limits<float>::max() ||
diff --git a/src/google/protobuf/util/message_differencer.cc b/src/google/protobuf/util/message_differencer.cc index de08096..c9f10ba 100644 --- a/src/google/protobuf/util/message_differencer.cc +++ b/src/google/protobuf/util/message_differencer.cc
@@ -42,7 +42,6 @@ #include <google/protobuf/stubs/logging.h> #include <google/protobuf/stubs/common.h> #include <google/protobuf/stubs/stringprintf.h> -#include <google/protobuf/any.h> #include <google/protobuf/io/printer.h> #include <google/protobuf/io/zero_copy_stream.h> #include <google/protobuf/io/zero_copy_stream_impl.h> @@ -309,6 +308,11 @@ repeated_field_comparison_ = comparison; } +MessageDifferencer::RepeatedFieldComparison +MessageDifferencer::repeated_field_comparison() { + return repeated_field_comparison_; +} + void MessageDifferencer::CheckRepeatedFieldComparisons( const FieldDescriptor* field, const RepeatedFieldComparison& new_comparison) { @@ -454,7 +458,7 @@ void MessageDifferencer::ReportDifferencesTo(Reporter* reporter) { // If an output string is set, clear it to prevent - // it superceding the specified reporter. + // it superseding the specified reporter. if (output_string_) { output_string_ = NULL; } @@ -580,7 +584,7 @@ *unknown_field_set2, parent_fields)) { if (reporter_ == NULL) { return false; - }; + } unknown_compare_result = false; } } @@ -861,7 +865,7 @@ parent_fields->pop_back(); } } - // Increment the field indicies. + // Increment the field indices. ++field_index1; ++field_index2; }
diff --git a/src/google/protobuf/util/message_differencer.h b/src/google/protobuf/util/message_differencer.h index dd4267b..21cf374 100644 --- a/src/google/protobuf/util/message_differencer.h +++ b/src/google/protobuf/util/message_differencer.h
@@ -570,6 +570,9 @@ // differencer when compare repeated fields in messages. void set_repeated_field_comparison(RepeatedFieldComparison comparison); + // Returns the current repeated field comparison used by this differencer. + RepeatedFieldComparison repeated_field_comparison(); + // Compares the two specified messages, returning true if they are the same, // false otherwise. If this method returns false, any changes between the // two messages will be reported if a Reporter was specified via
diff --git a/src/google/protobuf/wire_format.cc b/src/google/protobuf/wire_format.cc index c94881b..f60b774 100644 --- a/src/google/protobuf/wire_format.cc +++ b/src/google/protobuf/wire_format.cc
@@ -655,8 +655,8 @@ // =================================================================== -uint8* WireFormat::InternalSerializeWithCachedSizesToArray( - const Message& message, uint8* target, io::EpsCopyOutputStream* stream) { +uint8* WireFormat::_InternalSerialize(const Message& message, uint8* target, + io::EpsCopyOutputStream* stream) { const Descriptor* descriptor = message.GetDescriptor(); const Reflection* message_reflection = message.GetReflection(); @@ -751,12 +751,12 @@ target = stream->WriteString(2, value.GetStringValue(), target); break; case FieldDescriptor::TYPE_MESSAGE: - target = WireFormatLite::InternalWriteMessageToArray( - 2, value.GetMessageValue(), target, stream); + target = WireFormatLite::InternalWriteMessage(2, value.GetMessageValue(), + target, stream); break; case FieldDescriptor::TYPE_GROUP: - target = WireFormatLite::InternalWriteGroupToArray( - 2, value.GetMessageValue(), target, stream); + target = WireFormatLite::InternalWriteGroup(2, value.GetMessageValue(), + target, stream); break; } return target; @@ -902,12 +902,13 @@ if (count == 0) return target; target = stream->EnsureSpace(target); switch (field->type()) { -#define HANDLE_PRIMITIVE_TYPE(TYPE, CPPTYPE, TYPE_METHOD, CPPTYPE_METHOD) \ - case FieldDescriptor::TYPE_##TYPE: { \ - auto r = message_reflection->GetRepeatedField<CPPTYPE>(message, field); \ - target = stream->Write##TYPE_METHOD##Packed( \ - field->number(), r, FieldDataOnlyByteSize(field, message), target); \ - break; \ +#define HANDLE_PRIMITIVE_TYPE(TYPE, CPPTYPE, TYPE_METHOD, CPPTYPE_METHOD) \ + case FieldDescriptor::TYPE_##TYPE: { \ + auto r = \ + message_reflection->GetRepeatedFieldInternal<CPPTYPE>(message, field); \ + target = stream->Write##TYPE_METHOD##Packed( \ + field->number(), r, FieldDataOnlyByteSize(field, message), target); \ + break; \ } HANDLE_PRIMITIVE_TYPE(INT32, int32, Int32, Int32) @@ -919,11 +920,12 @@ HANDLE_PRIMITIVE_TYPE(ENUM, int, Enum, Enum) #undef HANDLE_PRIMITIVE_TYPE -#define HANDLE_PRIMITIVE_TYPE(TYPE, CPPTYPE, TYPE_METHOD, CPPTYPE_METHOD) \ - case FieldDescriptor::TYPE_##TYPE: { \ - auto r = message_reflection->GetRepeatedField<CPPTYPE>(message, field); \ - target = stream->WriteFixedPacked(field->number(), r, target); \ - break; \ +#define HANDLE_PRIMITIVE_TYPE(TYPE, CPPTYPE, TYPE_METHOD, CPPTYPE_METHOD) \ + case FieldDescriptor::TYPE_##TYPE: { \ + auto r = \ + message_reflection->GetRepeatedFieldInternal<CPPTYPE>(message, field); \ + target = stream->WriteFixedPacked(field->number(), r, target); \ + break; \ } HANDLE_PRIMITIVE_TYPE(FIXED32, uint32, Fixed32, UInt32) @@ -977,7 +979,7 @@ #define HANDLE_TYPE(TYPE, TYPE_METHOD, CPPTYPE_METHOD) \ case FieldDescriptor::TYPE_##TYPE: \ - target = WireFormatLite::InternalWrite##TYPE_METHOD##ToArray( \ + target = WireFormatLite::InternalWrite##TYPE_METHOD( \ field->number(), \ field->is_repeated() \ ? (map_entries.empty() \ @@ -1054,7 +1056,7 @@ target = WireFormatLite::WriteUInt32ToArray( WireFormatLite::kMessageSetTypeIdNumber, field->number(), target); // Write message. - target = WireFormatLite::InternalWriteMessageToArray( + target = WireFormatLite::InternalWriteMessage( WireFormatLite::kMessageSetMessageNumber, message_reflection->GetMessage(message, field), target, stream); // End group.
diff --git a/src/google/protobuf/wire_format.h b/src/google/protobuf/wire_format.h index 9721fe0..57582e3 100644 --- a/src/google/protobuf/wire_format.h +++ b/src/google/protobuf/wire_format.h
@@ -116,15 +116,15 @@ static void SerializeWithCachedSizes(const Message& message, int size, io::CodedOutputStream* output) { int expected_endpoint = output->ByteCount() + size; - output->SetCur(InternalSerializeWithCachedSizesToArray( - message, output->Cur(), output->EpsCopy())); + output->SetCur( + _InternalSerialize(message, output->Cur(), output->EpsCopy())); GOOGLE_CHECK_EQ(output->ByteCount(), expected_endpoint) << ": Protocol message serialized to a size different from what was " "originally expected. Perhaps it was modified by another thread " "during serialization?"; } - static uint8* InternalSerializeWithCachedSizesToArray( - const Message& message, uint8* target, io::EpsCopyOutputStream* stream); + static uint8* _InternalSerialize(const Message& message, uint8* target, + io::EpsCopyOutputStream* stream); // Implements Message::ByteSize() via reflection. WARNING: The result // of this method is *not* cached anywhere. However, all embedded messages
diff --git a/src/google/protobuf/wire_format_lite.cc b/src/google/protobuf/wire_format_lite.cc index f2017da..47ad0f1 100644 --- a/src/google/protobuf/wire_format_lite.cc +++ b/src/google/protobuf/wire_format_lite.cc
@@ -526,8 +526,7 @@ void WireFormatLite::WriteSubMessageMaybeToArray( int size, const MessageLite& value, io::CodedOutputStream* output) { - output->SetCur(value.InternalSerializeWithCachedSizesToArray( - output->Cur(), output->EpsCopy())); + output->SetCur(value._InternalSerialize(output->Cur(), output->EpsCopy())); } void WireFormatLite::WriteGroupMaybeToArray(int field_number,
diff --git a/src/google/protobuf/wire_format_lite.h b/src/google/protobuf/wire_format_lite.h index 012206b..449517a 100644 --- a/src/google/protobuf/wire_format_lite.h +++ b/src/google/protobuf/wire_format_lite.h
@@ -621,11 +621,11 @@ // have a CodedOutputStream available, so they get an additional parameter // telling them whether to serialize deterministically. template <typename MessageType> - PROTOBUF_ALWAYS_INLINE static uint8* InternalWriteGroupToArray( + PROTOBUF_ALWAYS_INLINE static uint8* InternalWriteGroup( int field_number, const MessageType& value, uint8* target, io::EpsCopyOutputStream* stream); template <typename MessageType> - PROTOBUF_ALWAYS_INLINE static uint8* InternalWriteMessageToArray( + PROTOBUF_ALWAYS_INLINE static uint8* InternalWriteMessage( int field_number, const MessageType& value, uint8* target, io::EpsCopyOutputStream* stream); @@ -649,7 +649,7 @@ static_cast<int>(2 * io::CodedOutputStream::VarintSize32( static_cast<uint32>(field_number) << 3)), io::CodedOutputStream::IsDefaultSerializationDeterministic()); - return InternalWriteGroupToArray(field_number, value, target, &stream); + return InternalWriteGroup(field_number, value, target, &stream); } PROTOBUF_ALWAYS_INLINE static uint8* WriteMessageToArray( int field_number, const MessageLite& value, uint8* target) { @@ -660,7 +660,7 @@ static_cast<uint32>(field_number) << 3) + io::CodedOutputStream::VarintSize32(size)), io::CodedOutputStream::IsDefaultSerializationDeterministic()); - return InternalWriteMessageToArray(field_number, value, target, &stream); + return InternalWriteMessage(field_number, value, target, &stream); } // Compute the byte size of a field. The XxSize() functions do NOT include @@ -1698,22 +1698,22 @@ template <typename MessageType> -inline uint8* WireFormatLite::InternalWriteGroupToArray( +inline uint8* WireFormatLite::InternalWriteGroup( int field_number, const MessageType& value, uint8* target, io::EpsCopyOutputStream* stream) { target = WriteTagToArray(field_number, WIRETYPE_START_GROUP, target); - target = value.InternalSerializeWithCachedSizesToArray(target, stream); + target = value._InternalSerialize(target, stream); target = stream->EnsureSpace(target); return WriteTagToArray(field_number, WIRETYPE_END_GROUP, target); } template <typename MessageType> -inline uint8* WireFormatLite::InternalWriteMessageToArray( +inline uint8* WireFormatLite::InternalWriteMessage( int field_number, const MessageType& value, uint8* target, io::EpsCopyOutputStream* stream) { target = WriteTagToArray(field_number, WIRETYPE_LENGTH_DELIMITED, target); target = io::CodedOutputStream::WriteVarint32ToArray( static_cast<uint32>(value.GetCachedSize()), target); - return value.InternalSerializeWithCachedSizesToArray(target, stream); + return value._InternalSerialize(target, stream); } // See comment on ReadGroupNoVirtual to understand the need for this template @@ -1724,7 +1724,7 @@ uint8* target) { target = WriteTagToArray(field_number, WIRETYPE_START_GROUP, target); target = value.MessageType_WorkAroundCppLookupDefect:: - InternalSerializeWithCachedSizesToArray(target); + SerializeWithCachedSizesToArray(target); return WriteTagToArray(field_number, WIRETYPE_END_GROUP, target); } template <typename MessageType_WorkAroundCppLookupDefect> @@ -1736,8 +1736,9 @@ static_cast<uint32>( value.MessageType_WorkAroundCppLookupDefect::GetCachedSize()), target); - return value.MessageType_WorkAroundCppLookupDefect:: - InternalSerializeWithCachedSizesToArray(target); + return value + .MessageType_WorkAroundCppLookupDefect::SerializeWithCachedSizesToArray( + target); } // ===================================================================
diff --git a/src/google/protobuf/wrappers.pb.cc b/src/google/protobuf/wrappers.pb.cc index f378736..8c8ce68 100644 --- a/src/google/protobuf/wrappers.pb.cc +++ b/src/google/protobuf/wrappers.pb.cc
@@ -403,7 +403,7 @@ #undef CHK_ } -::PROTOBUF_NAMESPACE_ID::uint8* DoubleValue::InternalSerializeWithCachedSizesToArray( +::PROTOBUF_NAMESPACE_ID::uint8* DoubleValue::_InternalSerialize( ::PROTOBUF_NAMESPACE_ID::uint8* target, ::PROTOBUF_NAMESPACE_ID::io::EpsCopyOutputStream* stream) const { // @@protoc_insertion_point(serialize_to_array_start:google.protobuf.DoubleValue) ::PROTOBUF_NAMESPACE_ID::uint32 cached_has_bits = 0; @@ -602,7 +602,7 @@ #undef CHK_ } -::PROTOBUF_NAMESPACE_ID::uint8* FloatValue::InternalSerializeWithCachedSizesToArray( +::PROTOBUF_NAMESPACE_ID::uint8* FloatValue::_InternalSerialize( ::PROTOBUF_NAMESPACE_ID::uint8* target, ::PROTOBUF_NAMESPACE_ID::io::EpsCopyOutputStream* stream) const { // @@protoc_insertion_point(serialize_to_array_start:google.protobuf.FloatValue) ::PROTOBUF_NAMESPACE_ID::uint32 cached_has_bits = 0; @@ -801,7 +801,7 @@ #undef CHK_ } -::PROTOBUF_NAMESPACE_ID::uint8* Int64Value::InternalSerializeWithCachedSizesToArray( +::PROTOBUF_NAMESPACE_ID::uint8* Int64Value::_InternalSerialize( ::PROTOBUF_NAMESPACE_ID::uint8* target, ::PROTOBUF_NAMESPACE_ID::io::EpsCopyOutputStream* stream) const { // @@protoc_insertion_point(serialize_to_array_start:google.protobuf.Int64Value) ::PROTOBUF_NAMESPACE_ID::uint32 cached_has_bits = 0; @@ -1002,7 +1002,7 @@ #undef CHK_ } -::PROTOBUF_NAMESPACE_ID::uint8* UInt64Value::InternalSerializeWithCachedSizesToArray( +::PROTOBUF_NAMESPACE_ID::uint8* UInt64Value::_InternalSerialize( ::PROTOBUF_NAMESPACE_ID::uint8* target, ::PROTOBUF_NAMESPACE_ID::io::EpsCopyOutputStream* stream) const { // @@protoc_insertion_point(serialize_to_array_start:google.protobuf.UInt64Value) ::PROTOBUF_NAMESPACE_ID::uint32 cached_has_bits = 0; @@ -1203,7 +1203,7 @@ #undef CHK_ } -::PROTOBUF_NAMESPACE_ID::uint8* Int32Value::InternalSerializeWithCachedSizesToArray( +::PROTOBUF_NAMESPACE_ID::uint8* Int32Value::_InternalSerialize( ::PROTOBUF_NAMESPACE_ID::uint8* target, ::PROTOBUF_NAMESPACE_ID::io::EpsCopyOutputStream* stream) const { // @@protoc_insertion_point(serialize_to_array_start:google.protobuf.Int32Value) ::PROTOBUF_NAMESPACE_ID::uint32 cached_has_bits = 0; @@ -1404,7 +1404,7 @@ #undef CHK_ } -::PROTOBUF_NAMESPACE_ID::uint8* UInt32Value::InternalSerializeWithCachedSizesToArray( +::PROTOBUF_NAMESPACE_ID::uint8* UInt32Value::_InternalSerialize( ::PROTOBUF_NAMESPACE_ID::uint8* target, ::PROTOBUF_NAMESPACE_ID::io::EpsCopyOutputStream* stream) const { // @@protoc_insertion_point(serialize_to_array_start:google.protobuf.UInt32Value) ::PROTOBUF_NAMESPACE_ID::uint32 cached_has_bits = 0; @@ -1605,7 +1605,7 @@ #undef CHK_ } -::PROTOBUF_NAMESPACE_ID::uint8* BoolValue::InternalSerializeWithCachedSizesToArray( +::PROTOBUF_NAMESPACE_ID::uint8* BoolValue::_InternalSerialize( ::PROTOBUF_NAMESPACE_ID::uint8* target, ::PROTOBUF_NAMESPACE_ID::io::EpsCopyOutputStream* stream) const { // @@protoc_insertion_point(serialize_to_array_start:google.protobuf.BoolValue) ::PROTOBUF_NAMESPACE_ID::uint32 cached_has_bits = 0; @@ -1786,7 +1786,9 @@ // string value = 1; case 1: if (PROTOBUF_PREDICT_TRUE(static_cast<::PROTOBUF_NAMESPACE_ID::uint8>(tag) == 10)) { - ptr = ::PROTOBUF_NAMESPACE_ID::internal::InlineGreedyStringParserUTF8(_internal_mutable_value(), ptr, ctx, "google.protobuf.StringValue.value"); + auto str = _internal_mutable_value(); + ptr = ::PROTOBUF_NAMESPACE_ID::internal::InlineGreedyStringParser(str, ptr, ctx); + CHK_(::PROTOBUF_NAMESPACE_ID::internal::VerifyUTF8(str, "google.protobuf.StringValue.value")); CHK_(ptr); } else goto handle_unusual; continue; @@ -1810,7 +1812,7 @@ #undef CHK_ } -::PROTOBUF_NAMESPACE_ID::uint8* StringValue::InternalSerializeWithCachedSizesToArray( +::PROTOBUF_NAMESPACE_ID::uint8* StringValue::_InternalSerialize( ::PROTOBUF_NAMESPACE_ID::uint8* target, ::PROTOBUF_NAMESPACE_ID::io::EpsCopyOutputStream* stream) const { // @@protoc_insertion_point(serialize_to_array_start:google.protobuf.StringValue) ::PROTOBUF_NAMESPACE_ID::uint32 cached_has_bits = 0; @@ -1998,7 +2000,8 @@ // bytes value = 1; case 1: if (PROTOBUF_PREDICT_TRUE(static_cast<::PROTOBUF_NAMESPACE_ID::uint8>(tag) == 10)) { - ptr = ::PROTOBUF_NAMESPACE_ID::internal::InlineGreedyStringParser(_internal_mutable_value(), ptr, ctx); + auto str = _internal_mutable_value(); + ptr = ::PROTOBUF_NAMESPACE_ID::internal::InlineGreedyStringParser(str, ptr, ctx); CHK_(ptr); } else goto handle_unusual; continue; @@ -2022,7 +2025,7 @@ #undef CHK_ } -::PROTOBUF_NAMESPACE_ID::uint8* BytesValue::InternalSerializeWithCachedSizesToArray( +::PROTOBUF_NAMESPACE_ID::uint8* BytesValue::_InternalSerialize( ::PROTOBUF_NAMESPACE_ID::uint8* target, ::PROTOBUF_NAMESPACE_ID::io::EpsCopyOutputStream* stream) const { // @@protoc_insertion_point(serialize_to_array_start:google.protobuf.BytesValue) ::PROTOBUF_NAMESPACE_ID::uint32 cached_has_bits = 0;
diff --git a/src/google/protobuf/wrappers.pb.h b/src/google/protobuf/wrappers.pb.h index 95c7d6f..4ee66db 100644 --- a/src/google/protobuf/wrappers.pb.h +++ b/src/google/protobuf/wrappers.pb.h
@@ -183,7 +183,7 @@ size_t ByteSizeLong() const final; const char* _InternalParse(const char* ptr, ::PROTOBUF_NAMESPACE_ID::internal::ParseContext* ctx) final; - ::PROTOBUF_NAMESPACE_ID::uint8* InternalSerializeWithCachedSizesToArray( + ::PROTOBUF_NAMESPACE_ID::uint8* _InternalSerialize( ::PROTOBUF_NAMESPACE_ID::uint8* target, ::PROTOBUF_NAMESPACE_ID::io::EpsCopyOutputStream* stream) const final; int GetCachedSize() const final { return _cached_size_.Get(); } @@ -334,7 +334,7 @@ size_t ByteSizeLong() const final; const char* _InternalParse(const char* ptr, ::PROTOBUF_NAMESPACE_ID::internal::ParseContext* ctx) final; - ::PROTOBUF_NAMESPACE_ID::uint8* InternalSerializeWithCachedSizesToArray( + ::PROTOBUF_NAMESPACE_ID::uint8* _InternalSerialize( ::PROTOBUF_NAMESPACE_ID::uint8* target, ::PROTOBUF_NAMESPACE_ID::io::EpsCopyOutputStream* stream) const final; int GetCachedSize() const final { return _cached_size_.Get(); } @@ -485,7 +485,7 @@ size_t ByteSizeLong() const final; const char* _InternalParse(const char* ptr, ::PROTOBUF_NAMESPACE_ID::internal::ParseContext* ctx) final; - ::PROTOBUF_NAMESPACE_ID::uint8* InternalSerializeWithCachedSizesToArray( + ::PROTOBUF_NAMESPACE_ID::uint8* _InternalSerialize( ::PROTOBUF_NAMESPACE_ID::uint8* target, ::PROTOBUF_NAMESPACE_ID::io::EpsCopyOutputStream* stream) const final; int GetCachedSize() const final { return _cached_size_.Get(); } @@ -636,7 +636,7 @@ size_t ByteSizeLong() const final; const char* _InternalParse(const char* ptr, ::PROTOBUF_NAMESPACE_ID::internal::ParseContext* ctx) final; - ::PROTOBUF_NAMESPACE_ID::uint8* InternalSerializeWithCachedSizesToArray( + ::PROTOBUF_NAMESPACE_ID::uint8* _InternalSerialize( ::PROTOBUF_NAMESPACE_ID::uint8* target, ::PROTOBUF_NAMESPACE_ID::io::EpsCopyOutputStream* stream) const final; int GetCachedSize() const final { return _cached_size_.Get(); } @@ -787,7 +787,7 @@ size_t ByteSizeLong() const final; const char* _InternalParse(const char* ptr, ::PROTOBUF_NAMESPACE_ID::internal::ParseContext* ctx) final; - ::PROTOBUF_NAMESPACE_ID::uint8* InternalSerializeWithCachedSizesToArray( + ::PROTOBUF_NAMESPACE_ID::uint8* _InternalSerialize( ::PROTOBUF_NAMESPACE_ID::uint8* target, ::PROTOBUF_NAMESPACE_ID::io::EpsCopyOutputStream* stream) const final; int GetCachedSize() const final { return _cached_size_.Get(); } @@ -938,7 +938,7 @@ size_t ByteSizeLong() const final; const char* _InternalParse(const char* ptr, ::PROTOBUF_NAMESPACE_ID::internal::ParseContext* ctx) final; - ::PROTOBUF_NAMESPACE_ID::uint8* InternalSerializeWithCachedSizesToArray( + ::PROTOBUF_NAMESPACE_ID::uint8* _InternalSerialize( ::PROTOBUF_NAMESPACE_ID::uint8* target, ::PROTOBUF_NAMESPACE_ID::io::EpsCopyOutputStream* stream) const final; int GetCachedSize() const final { return _cached_size_.Get(); } @@ -1089,7 +1089,7 @@ size_t ByteSizeLong() const final; const char* _InternalParse(const char* ptr, ::PROTOBUF_NAMESPACE_ID::internal::ParseContext* ctx) final; - ::PROTOBUF_NAMESPACE_ID::uint8* InternalSerializeWithCachedSizesToArray( + ::PROTOBUF_NAMESPACE_ID::uint8* _InternalSerialize( ::PROTOBUF_NAMESPACE_ID::uint8* target, ::PROTOBUF_NAMESPACE_ID::io::EpsCopyOutputStream* stream) const final; int GetCachedSize() const final { return _cached_size_.Get(); } @@ -1240,7 +1240,7 @@ size_t ByteSizeLong() const final; const char* _InternalParse(const char* ptr, ::PROTOBUF_NAMESPACE_ID::internal::ParseContext* ctx) final; - ::PROTOBUF_NAMESPACE_ID::uint8* InternalSerializeWithCachedSizesToArray( + ::PROTOBUF_NAMESPACE_ID::uint8* _InternalSerialize( ::PROTOBUF_NAMESPACE_ID::uint8* target, ::PROTOBUF_NAMESPACE_ID::io::EpsCopyOutputStream* stream) const final; int GetCachedSize() const final { return _cached_size_.Get(); } @@ -1407,7 +1407,7 @@ size_t ByteSizeLong() const final; const char* _InternalParse(const char* ptr, ::PROTOBUF_NAMESPACE_ID::internal::ParseContext* ctx) final; - ::PROTOBUF_NAMESPACE_ID::uint8* InternalSerializeWithCachedSizesToArray( + ::PROTOBUF_NAMESPACE_ID::uint8* _InternalSerialize( ::PROTOBUF_NAMESPACE_ID::uint8* target, ::PROTOBUF_NAMESPACE_ID::io::EpsCopyOutputStream* stream) const final; int GetCachedSize() const final { return _cached_size_.Get(); }