From cc8ca5b6a5478b40546d4206392eb1471454460d Mon Sep 17 00:00:00 2001 From: Bo Yang Date: Mon, 19 Sep 2016 13:45:07 -0700 Subject: Integrate internal changes --- conformance/Makefile.am | 16 +- conformance/conformance_python.py | 8 +- conformance/conformance_test.cc | 586 ++-- conformance/conformance_test.h | 52 +- conformance/conformance_test_runner.cc | 12 + conformance/failure_list_cpp.txt | 83 +- conformance/failure_list_java.txt | 88 +- conformance/failure_list_python.txt | 61 +- conformance/failure_list_python_cpp.txt | 93 +- .../main/java/com/google/protobuf/ByteString.java | 14 + .../java/com/google/protobuf/CodedInputStream.java | 3593 ++++++++++++++------ .../com/google/protobuf/CodedOutputStream.java | 400 ++- .../main/java/com/google/protobuf/Descriptors.java | 31 +- .../com/google/protobuf/GeneratedMessageV3.java | 481 ++- .../main/java/com/google/protobuf/Internal.java | 10 + .../protobuf/InvalidProtocolBufferException.java | 16 +- .../main/java/com/google/protobuf/MapEntry.java | 9 + .../java/com/google/protobuf/NioByteString.java | 9 +- .../java/com/google/protobuf/RopeByteString.java | 1 + .../main/java/com/google/protobuf/TextFormat.java | 22 +- .../google/protobuf/TextFormatParseInfoTree.java | 3 +- .../com/google/protobuf/UnsafeByteOperations.java | 31 +- .../main/java/com/google/protobuf/UnsafeUtil.java | 119 +- .../main/java/com/google/protobuf/WireFormat.java | 4 + .../com/google/protobuf/AbstractMessageTest.java | 4 +- .../com/google/protobuf/BooleanArrayListTest.java | 3 +- .../com/google/protobuf/ByteBufferWriterTest.java | 3 +- .../java/com/google/protobuf/ByteStringTest.java | 4 +- .../com/google/protobuf/CodedInputStreamTest.java | 802 +++-- .../com/google/protobuf/CodedOutputStreamTest.java | 55 +- .../com/google/protobuf/DeprecatedFieldTest.java | 4 +- .../java/com/google/protobuf/DescriptorsTest.java | 15 +- .../com/google/protobuf/DoubleArrayListTest.java | 3 +- .../com/google/protobuf/DynamicMessageTest.java | 4 +- .../protobuf/ExtensionRegistryFactoryTest.java | 47 +- .../com/google/protobuf/FloatArrayListTest.java | 3 +- .../com/google/protobuf/GeneratedMessageTest.java | 4 +- .../java/com/google/protobuf/IntArrayListTest.java | 3 +- .../com/google/protobuf/LazyFieldLiteTest.java | 4 +- .../java/com/google/protobuf/LazyFieldTest.java | 4 +- .../com/google/protobuf/LazyMessageLiteTest.java | 4 +- .../google/protobuf/LazyStringArrayListTest.java | 3 +- .../google/protobuf/LazyStringEndToEndTest.java | 4 +- .../test/java/com/google/protobuf/LiteTest.java | 9 - .../com/google/protobuf/LiteralByteStringTest.java | 3 +- .../com/google/protobuf/LongArrayListTest.java | 3 +- .../com/google/protobuf/MapForProto2LiteTest.java | 4 +- .../java/com/google/protobuf/MapForProto2Test.java | 10 +- .../src/test/java/com/google/protobuf/MapTest.java | 170 +- .../test/java/com/google/protobuf/MessageTest.java | 4 +- .../com/google/protobuf/NestedBuildersTest.java | 4 +- .../com/google/protobuf/NioByteStringTest.java | 3 +- .../com/google/protobuf/ParseExceptionsTest.java | 8 +- .../test/java/com/google/protobuf/ParserTest.java | 4 +- .../com/google/protobuf/ProtobufArrayListTest.java | 3 +- .../protobuf/RepeatedFieldBuilderV3Test.java | 4 +- .../test/java/com/google/protobuf/ServiceTest.java | 8 +- .../com/google/protobuf/SmallSortedMapTest.java | 3 +- .../test/java/com/google/protobuf/TestUtil.java | 11 +- .../java/com/google/protobuf/TextFormatTest.java | 29 +- .../google/protobuf/UnknownFieldSetLiteTest.java | 4 +- .../com/google/protobuf/UnknownFieldSetTest.java | 4 +- .../protobuf/UnmodifiableLazyStringListTest.java | 3 +- .../java/com/google/protobuf/WireFormatTest.java | 4 +- .../com/google/protobuf/field_presence_test.proto | 1 - .../google/protobuf/map_for_proto2_lite_test.proto | 37 +- .../com/google/protobuf/map_for_proto2_test.proto | 37 +- .../test/proto/com/google/protobuf/map_test.proto | 39 +- .../com/google/protobuf/test_bad_identifiers.proto | 1 - .../java/com/google/protobuf/AbstractMessage.java | 646 ++++ .../com/google/protobuf/AbstractMessageLite.java | 384 +++ .../java/com/google/protobuf/AbstractParser.java | 258 ++ .../com/google/protobuf/AbstractProtobufList.java | 180 + .../com/google/protobuf/BlockingRpcChannel.java | 51 + .../java/com/google/protobuf/BlockingService.java | 64 + .../java/com/google/protobuf/util/Durations.java | 182 +- .../java/com/google/protobuf/util/JsonFormat.java | 15 +- .../java/com/google/protobuf/util/Timestamps.java | 207 +- .../com/google/protobuf/util/JsonFormatTest.java | 110 +- .../com/google/protobuf/util/TimeUtilTest.java | 7 +- .../proto/com/google/protobuf/util/json_test.proto | 1 + js/binary/proto_test.js | 2 +- js/debug.js | 3 +- js/debug_test.js | 2 +- js/map.js | 22 +- js/maps_test.js | 359 ++ js/message.js | 154 +- js/message_test.js | 55 +- js/proto3_test.js | 2 +- objectivec/google/protobuf/Duration.pbobjc.h | 6 + objectivec/google/protobuf/FieldMask.pbobjc.h | 6 +- objectivec/google/protobuf/Timestamp.pbobjc.h | 8 +- php/tests/test.pb.php | 1385 ++++++++ php/tests/test_include.pb.php | 36 + python/google/protobuf/descriptor.py | 49 +- python/google/protobuf/descriptor_pool.py | 138 +- python/google/protobuf/internal/any_test.proto | 14 +- python/google/protobuf/internal/containers.py | 21 +- .../protobuf/internal/descriptor_pool_test.py | 5 + python/google/protobuf/internal/descriptor_test.py | 19 + python/google/protobuf/internal/generator_test.py | 3 +- .../google/protobuf/internal/json_format_test.py | 78 +- python/google/protobuf/internal/message_test.py | 45 +- python/google/protobuf/internal/python_message.py | 6 +- python/google/protobuf/internal/reflection_test.py | 41 +- .../google/protobuf/internal/testing_refleaks.py | 124 + .../google/protobuf/internal/text_format_test.py | 25 +- .../protobuf/internal/unknown_fields_test.py | 107 +- .../google/protobuf/internal/well_known_types.py | 75 +- .../protobuf/internal/well_known_types_test.py | 132 +- python/google/protobuf/json_format.py | 93 +- python/google/protobuf/message.py | 9 +- python/google/protobuf/message_factory.py | 11 +- python/google/protobuf/pyext/descriptor.cc | 22 +- python/google/protobuf/pyext/descriptor_pool.cc | 59 +- python/google/protobuf/pyext/descriptor_pool.h | 35 +- python/google/protobuf/pyext/extension_dict.cc | 78 +- python/google/protobuf/pyext/extension_dict.h | 43 - python/google/protobuf/pyext/map_container.cc | 95 +- python/google/protobuf/pyext/map_container.h | 12 +- python/google/protobuf/pyext/message.cc | 212 +- python/google/protobuf/pyext/message.h | 33 +- python/google/protobuf/pyext/message_factory.cc | 214 ++ python/google/protobuf/pyext/message_factory.h | 103 + .../protobuf/pyext/repeated_composite_container.cc | 2 +- python/google/protobuf/symbol_database.py | 3 +- python/google/protobuf/text_format.py | 16 +- src/Makefile.am | 6 + src/google/protobuf/any.pb.cc | 126 +- src/google/protobuf/any.pb.h | 14 +- src/google/protobuf/any.proto | 1 - src/google/protobuf/api.pb.cc | 399 ++- src/google/protobuf/api.pb.h | 51 +- src/google/protobuf/api.proto | 1 - src/google/protobuf/arena.cc | 10 +- src/google/protobuf/arena.h | 13 +- src/google/protobuf/arena_unittest.cc | 46 +- src/google/protobuf/compiler/code_generator.cc | 28 + src/google/protobuf/compiler/code_generator.h | 41 +- .../protobuf/compiler/command_line_interface.cc | 59 +- .../protobuf/compiler/command_line_interface.h | 5 + .../compiler/command_line_interface_unittest.cc | 86 + .../compiler/cpp/cpp_bootstrap_unittest.cc | 1 - src/google/protobuf/compiler/cpp/cpp_enum.cc | 2 +- src/google/protobuf/compiler/cpp/cpp_enum_field.cc | 39 +- src/google/protobuf/compiler/cpp/cpp_enum_field.h | 1 + src/google/protobuf/compiler/cpp/cpp_extension.cc | 30 +- src/google/protobuf/compiler/cpp/cpp_field.h | 7 + src/google/protobuf/compiler/cpp/cpp_file.cc | 163 +- src/google/protobuf/compiler/cpp/cpp_helpers.cc | 41 +- src/google/protobuf/compiler/cpp/cpp_helpers.h | 19 +- src/google/protobuf/compiler/cpp/cpp_map_field.cc | 3 +- src/google/protobuf/compiler/cpp/cpp_message.cc | 855 +++-- src/google/protobuf/compiler/cpp/cpp_message.h | 10 + .../protobuf/compiler/cpp/cpp_message_field.cc | 49 +- .../protobuf/compiler/cpp/cpp_primitive_field.cc | 47 +- .../protobuf/compiler/cpp/cpp_primitive_field.h | 1 + .../protobuf/compiler/cpp/cpp_string_field.cc | 104 +- .../protobuf/compiler/cpp/cpp_string_field.h | 1 + src/google/protobuf/compiler/cpp/cpp_unittest.cc | 6 +- src/google/protobuf/compiler/java/java_file.cc | 2 - .../protobuf/compiler/java/java_map_field.cc | 38 +- .../protobuf/compiler/java/java_map_field_lite.cc | 6 +- src/google/protobuf/compiler/java/java_message.cc | 2 +- .../protobuf/compiler/java/java_message_builder.cc | 13 +- .../compiler/java/java_message_field_lite.cc | 1 + .../protobuf/compiler/java/java_message_lite.cc | 4 +- src/google/protobuf/compiler/java/java_service.cc | 20 +- src/google/protobuf/compiler/java/java_service.h | 3 + .../compiler/java/java_shared_code_generator.cc | 2 - src/google/protobuf/compiler/js/js_generator.cc | 777 +++-- src/google/protobuf/compiler/js/js_generator.h | 87 +- src/google/protobuf/compiler/main.cc | 10 + src/google/protobuf/compiler/plugin.cc | 39 +- src/google/protobuf/compiler/plugin.pb.cc | 340 +- src/google/protobuf/compiler/plugin.pb.h | 47 +- .../protobuf/compiler/python/python_generator.cc | 19 +- src/google/protobuf/descriptor.cc | 198 +- src/google/protobuf/descriptor.h | 9 +- src/google/protobuf/descriptor.pb.cc | 3118 +++++++++-------- src/google/protobuf/descriptor.pb.h | 516 +-- src/google/protobuf/descriptor.proto | 25 +- src/google/protobuf/descriptor_unittest.cc | 76 +- src/google/protobuf/duration.pb.cc | 141 +- src/google/protobuf/duration.pb.h | 27 +- src/google/protobuf/duration.proto | 8 +- src/google/protobuf/dynamic_message.cc | 62 +- src/google/protobuf/empty.pb.cc | 101 +- src/google/protobuf/empty.pb.h | 14 +- src/google/protobuf/empty.proto | 1 - src/google/protobuf/extension_set.cc | 21 +- src/google/protobuf/extension_set.h | 8 +- src/google/protobuf/extension_set_heavy.cc | 10 +- src/google/protobuf/extension_set_unittest.cc | 2 +- src/google/protobuf/field_mask.pb.cc | 121 +- src/google/protobuf/field_mask.pb.h | 14 +- src/google/protobuf/field_mask.proto | 7 +- .../protobuf/generated_message_reflection.cc | 165 +- src/google/protobuf/generated_message_reflection.h | 34 +- src/google/protobuf/generated_message_util.cc | 6 +- src/google/protobuf/generated_message_util.h | 64 +- src/google/protobuf/has_bits.h | 72 + src/google/protobuf/io/coded_stream.cc | 45 +- src/google/protobuf/io/coded_stream.h | 14 +- src/google/protobuf/io/coded_stream_unittest.cc | 1 + src/google/protobuf/io/zero_copy_stream_impl.h | 12 +- src/google/protobuf/map.h | 12 +- src/google/protobuf/map_entry.h | 4 +- src/google/protobuf/map_entry_lite.h | 6 +- src/google/protobuf/map_type_handler.h | 4 +- src/google/protobuf/message.cc | 10 +- src/google/protobuf/message.h | 10 +- src/google/protobuf/message_lite.cc | 39 +- src/google/protobuf/message_lite.h | 7 +- src/google/protobuf/message_unittest.cc | 36 + src/google/protobuf/metadata.h | 4 - src/google/protobuf/reflection.h | 29 +- src/google/protobuf/reflection_ops.h | 2 +- src/google/protobuf/repeated_field.cc | 18 +- src/google/protobuf/repeated_field.h | 39 +- src/google/protobuf/repeated_field_unittest.cc | 46 +- src/google/protobuf/source_context.pb.cc | 110 +- src/google/protobuf/source_context.pb.h | 14 +- src/google/protobuf/source_context.proto | 1 - src/google/protobuf/struct.pb.cc | 559 ++- src/google/protobuf/struct.pb.h | 250 +- src/google/protobuf/struct.proto | 2 +- src/google/protobuf/stubs/port.h | 55 + src/google/protobuf/stubs/strutil.cc | 15 + src/google/protobuf/stubs/strutil.h | 4 +- src/google/protobuf/text_format.cc | 35 +- src/google/protobuf/text_format.h | 12 +- src/google/protobuf/text_format_unittest.cc | 99 +- src/google/protobuf/timestamp.pb.cc | 119 +- src/google/protobuf/timestamp.pb.h | 14 +- src/google/protobuf/timestamp.proto | 9 +- src/google/protobuf/type.pb.cc | 1365 +++++--- src/google/protobuf/type.pb.h | 615 +++- src/google/protobuf/type.proto | 2 +- src/google/protobuf/unittest.proto | 8 + src/google/protobuf/unknown_field_set.cc | 7 + src/google/protobuf/unknown_field_set.h | 16 +- src/google/protobuf/util/field_comparator.h | 2 +- src/google/protobuf/util/internal/datapiece.cc | 32 +- src/google/protobuf/util/internal/datapiece.h | 33 +- .../util/internal/default_value_objectwriter.cc | 41 +- src/google/protobuf/util/internal/error_listener.h | 4 +- .../protobuf/util/internal/json_objectwriter.cc | 21 +- .../protobuf/util/internal/json_objectwriter.h | 20 +- .../util/internal/json_objectwriter_test.cc | 4 +- .../protobuf/util/internal/json_stream_parser.cc | 44 +- .../protobuf/util/internal/json_stream_parser.h | 8 + .../util/internal/json_stream_parser_test.cc | 18 +- src/google/protobuf/util/internal/object_writer.h | 7 + src/google/protobuf/util/internal/proto_writer.cc | 9 +- src/google/protobuf/util/internal/proto_writer.h | 8 + .../util/internal/protostream_objectsource.cc | 11 +- .../util/internal/protostream_objectsource.h | 43 +- .../util/internal/protostream_objectsource_test.cc | 66 +- .../util/internal/protostream_objectwriter.cc | 131 +- .../util/internal/protostream_objectwriter.h | 62 +- .../util/internal/protostream_objectwriter_test.cc | 459 ++- .../protobuf/util/internal/testdata/anys.proto | 69 +- .../protobuf/util/internal/testdata/books.proto | 5 + .../protobuf/util/internal/testdata/maps.proto | 76 +- .../protobuf/util/internal/testdata/oneofs.proto | 31 +- .../protobuf/util/internal/testdata/proto3.proto | 42 + .../protobuf/util/internal/testdata/struct.proto | 86 +- .../internal/testdata/timestamp_duration.proto | 47 +- src/google/protobuf/util/internal/utility.cc | 41 + src/google/protobuf/util/internal/utility.h | 11 + src/google/protobuf/util/message_differencer.h | 126 +- src/google/protobuf/wire_format.cc | 39 +- src/google/protobuf/wire_format.h | 17 +- src/google/protobuf/wire_format_lite.cc | 2 +- src/google/protobuf/wire_format_lite.h | 53 +- src/google/protobuf/wire_format_lite_inl.h | 44 +- src/google/protobuf/wrappers.pb.cc | 695 ++-- src/google/protobuf/wrappers.pb.h | 118 +- src/google/protobuf/wrappers.proto | 1 - 280 files changed, 19683 insertions(+), 8179 deletions(-) create mode 100755 java/src/main/java/com/google/protobuf/AbstractMessage.java create mode 100755 java/src/main/java/com/google/protobuf/AbstractMessageLite.java create mode 100755 java/src/main/java/com/google/protobuf/AbstractParser.java create mode 100755 java/src/main/java/com/google/protobuf/AbstractProtobufList.java create mode 100755 java/src/main/java/com/google/protobuf/BlockingRpcChannel.java create mode 100755 java/src/main/java/com/google/protobuf/BlockingService.java create mode 100755 js/maps_test.js create mode 100644 php/tests/test.pb.php create mode 100644 php/tests/test_include.pb.php create mode 100644 python/google/protobuf/internal/testing_refleaks.py create mode 100644 python/google/protobuf/pyext/message_factory.cc create mode 100644 python/google/protobuf/pyext/message_factory.h create mode 100644 src/google/protobuf/has_bits.h create mode 100644 src/google/protobuf/util/internal/testdata/proto3.proto diff --git a/conformance/Makefile.am b/conformance/Makefile.am index 28ac3c8a..bdd23a07 100644 --- a/conformance/Makefile.am +++ b/conformance/Makefile.am @@ -251,31 +251,31 @@ conformance-csharp: $(other_language_protoc_outputs) # Targets for actually running tests. test_cpp: protoc_middleman conformance-test-runner conformance-cpp - ./conformance-test-runner --failure_list failure_list_cpp.txt ./conformance-cpp + ./conformance-test-runner --enforce_recommended --failure_list failure_list_cpp.txt ./conformance-cpp test_java: protoc_middleman conformance-test-runner conformance-java - ./conformance-test-runner --failure_list failure_list_java.txt ./conformance-java + ./conformance-test-runner --enforce_recommended --failure_list failure_list_java.txt ./conformance-java test_java_lite: protoc_middleman conformance-test-runner conformance-java-lite - ./conformance-test-runner ./conformance-java-lite + ./conformance-test-runner --enforce_recommended ./conformance-java-lite test_csharp: protoc_middleman conformance-test-runner conformance-csharp - ./conformance-test-runner --failure_list failure_list_csharp.txt ./conformance-csharp + ./conformance-test-runner --enforce_recommended --failure_list failure_list_csharp.txt ./conformance-csharp test_ruby: protoc_middleman conformance-test-runner $(other_language_protoc_outputs) - RUBYLIB=../ruby/lib:. ./conformance-test-runner --failure_list failure_list_ruby.txt ./conformance_ruby.rb + RUBYLIB=../ruby/lib:. ./conformance-test-runner --enforce_recommended --failure_list failure_list_ruby.txt ./conformance_ruby.rb # These depend on library paths being properly set up. The easiest way to # run them is to just use "tox" from the python dir. test_python: protoc_middleman conformance-test-runner - ./conformance-test-runner --failure_list failure_list_python.txt ./conformance_python.py + ./conformance-test-runner --enforce_recommended --failure_list failure_list_python.txt ./conformance_python.py test_python_cpp: protoc_middleman conformance-test-runner - ./conformance-test-runner --failure_list failure_list_python_cpp.txt ./conformance_python.py + ./conformance-test-runner --enforce_recommended --failure_list failure_list_python_cpp.txt ./conformance_python.py if OBJC_CONFORMANCE_TEST test_objc: protoc_middleman conformance-test-runner conformance-objc - ./conformance-test-runner --failure_list failure_list_objc.txt ./conformance-objc + ./conformance-test-runner --enforce_recomemnded --failure_list failure_list_objc.txt ./conformance-objc endif diff --git a/conformance/conformance_python.py b/conformance/conformance_python.py index a490c8e8..2f4a7812 100755 --- a/conformance/conformance_python.py +++ b/conformance/conformance_python.py @@ -67,7 +67,7 @@ def do_test(request): elif request.WhichOneof('payload') == 'json_payload': try: json_format.Parse(request.json_payload, test_message) - except json_format.ParseError as e: + except Exception as e: response.parse_error = str(e) return response @@ -81,7 +81,11 @@ def do_test(request): response.protobuf_payload = test_message.SerializeToString() elif request.requested_output_format == conformance_pb2.JSON: - response.json_payload = json_format.MessageToJson(test_message) + try: + response.json_payload = json_format.MessageToJson(test_message) + except Exception as e: + response.serialize_error = str(e) + return response except Exception as e: response.runtime_error = str(e) diff --git a/conformance/conformance_test.cc b/conformance/conformance_test.cc index fb963f68..a74f2837 100644 --- a/conformance/conformance_test.cc +++ b/conformance/conformance_test.cc @@ -183,6 +183,7 @@ void ConformanceTestSuite::ReportSuccess(const string& test_name) { } void ConformanceTestSuite::ReportFailure(const string& test_name, + ConformanceLevel level, const ConformanceRequest& request, const ConformanceResponse& response, const char* fmt, ...) { @@ -190,6 +191,8 @@ void ConformanceTestSuite::ReportFailure(const string& test_name, expected_failures_++; if (!verbose_) return; + } else if (level == RECOMMENDED && !enforce_recommended_) { + StringAppendF(&output_, "WARNING, test=%s: ", test_name.c_str()); } else { StringAppendF(&output_, "ERROR, test=%s: ", test_name.c_str()); unexpected_failing_tests_.insert(test_name); @@ -214,6 +217,15 @@ void ConformanceTestSuite::ReportSkip(const string& test_name, skipped_.insert(test_name); } +string ConformanceTestSuite::ConformanceLevelToString(ConformanceLevel level) { + switch (level) { + case REQUIRED: return "Required"; + case RECOMMENDED: return "Recommended"; + } + GOOGLE_LOG(FATAL) << "Unknown value: " << level; + return ""; +} + void ConformanceTestSuite::RunTest(const string& test_name, const ConformanceRequest& request, ConformanceResponse* response) { @@ -241,8 +253,9 @@ void ConformanceTestSuite::RunTest(const string& test_name, } void ConformanceTestSuite::RunValidInputTest( - const string& test_name, const string& input, WireFormat input_format, - const string& equivalent_text_format, WireFormat requested_output) { + const string& test_name, ConformanceLevel level, const string& input, + WireFormat input_format, const string& equivalent_text_format, + WireFormat requested_output) { TestAllTypes reference_message; GOOGLE_CHECK( TextFormat::ParseFromString(equivalent_text_format, &reference_message)) @@ -291,7 +304,7 @@ void ConformanceTestSuite::RunValidInputTest( case ConformanceResponse::kJsonPayload: { if (requested_output != conformance::JSON) { ReportFailure( - test_name, request, response, + test_name, level, request, response, "Test was asked for protobuf output but provided JSON instead."); return; } @@ -300,13 +313,13 @@ void ConformanceTestSuite::RunValidInputTest( JsonToBinaryString(type_resolver_.get(), type_url_, response.json_payload(), &binary_protobuf); if (!status.ok()) { - ReportFailure(test_name, request, response, + ReportFailure(test_name, level, request, response, "JSON output we received from test was unparseable."); return; } if (!test_message.ParseFromString(binary_protobuf)) { - ReportFailure(test_name, request, response, + ReportFailure(test_name, level, request, response, "INTERNAL ERROR: internal JSON->protobuf transcode " "yielded unparseable proto."); return; @@ -318,13 +331,13 @@ void ConformanceTestSuite::RunValidInputTest( case ConformanceResponse::kProtobufPayload: { if (requested_output != conformance::PROTOBUF) { ReportFailure( - test_name, request, response, + test_name, level, request, response, "Test was asked for JSON output but provided protobuf instead."); return; } if (!test_message.ParseFromString(response.protobuf_payload())) { - ReportFailure(test_name, request, response, + ReportFailure(test_name, level, request, response, "Protobuf output we received from test was unparseable."); return; } @@ -347,7 +360,7 @@ void ConformanceTestSuite::RunValidInputTest( if (differencer.Compare(reference_message, test_message)) { ReportSuccess(test_name); } else { - ReportFailure(test_name, request, response, + ReportFailure(test_name, level, request, response, "Output was not equivalent to reference message: %s.", differences.c_str()); } @@ -355,11 +368,12 @@ void ConformanceTestSuite::RunValidInputTest( // Expect that this precise protobuf will cause a parse error. void ConformanceTestSuite::ExpectParseFailureForProto( - const string& proto, const string& test_name) { + const string& proto, const string& test_name, ConformanceLevel level) { ConformanceRequest request; ConformanceResponse response; request.set_protobuf_payload(proto); - string effective_test_name = "ProtobufInput." + test_name; + string effective_test_name = ConformanceLevelToString(level) + + ".ProtobufInput." + test_name; // We don't expect output, but if the program erroneously accepts the protobuf // we let it send its response as this. We must not leave it unspecified. @@ -371,7 +385,7 @@ void ConformanceTestSuite::ExpectParseFailureForProto( } else if (response.result_case() == ConformanceResponse::kSkipped) { ReportSkip(effective_test_name, request, response); } else { - ReportFailure(effective_test_name, request, response, + ReportFailure(effective_test_name, level, request, response, "Should have failed to parse, but didn't."); } } @@ -382,27 +396,30 @@ void ConformanceTestSuite::ExpectParseFailureForProto( // // TODO(haberman): implement the second of these. void ConformanceTestSuite::ExpectHardParseFailureForProto( - const string& proto, const string& test_name) { - return ExpectParseFailureForProto(proto, test_name); + const string& proto, const string& test_name, ConformanceLevel level) { + return ExpectParseFailureForProto(proto, test_name, level); } void ConformanceTestSuite::RunValidJsonTest( - const string& test_name, const string& input_json, + const string& test_name, ConformanceLevel level, const string& input_json, const string& equivalent_text_format) { - RunValidInputTest("JsonInput." + test_name + ".ProtobufOutput", input_json, - conformance::JSON, equivalent_text_format, - conformance::PROTOBUF); - RunValidInputTest("JsonInput." + test_name + ".JsonOutput", input_json, - conformance::JSON, equivalent_text_format, - conformance::JSON); + RunValidInputTest( + ConformanceLevelToString(level) + ".JsonInput." + test_name + + ".ProtobufOutput", level, input_json, conformance::JSON, + equivalent_text_format, conformance::PROTOBUF); + RunValidInputTest( + ConformanceLevelToString(level) + ".JsonInput." + test_name + + ".JsonOutput", level, input_json, conformance::JSON, + equivalent_text_format, conformance::JSON); } void ConformanceTestSuite::RunValidJsonTestWithProtobufInput( - const string& test_name, const TestAllTypes& input, + const string& test_name, ConformanceLevel level, const TestAllTypes& input, const string& equivalent_text_format) { - RunValidInputTest("ProtobufInput." + test_name + ".JsonOutput", - input.SerializeAsString(), conformance::PROTOBUF, - equivalent_text_format, conformance::JSON); + RunValidInputTest( + ConformanceLevelToString(level) + ".ProtobufInput." + test_name + + ".JsonOutput", level, input.SerializeAsString(), conformance::PROTOBUF, + equivalent_text_format, conformance::JSON); } void ConformanceTestSuite::RunValidProtobufTest( @@ -422,14 +439,15 @@ void ConformanceTestSuite::RunValidProtobufTest( // method allows strict checking on a proto3 JSON serializer by inspecting // the JSON output directly. void ConformanceTestSuite::RunValidJsonTestWithValidator( - const string& test_name, const string& input_json, + const string& test_name, ConformanceLevel level, const string& input_json, const Validator& validator) { ConformanceRequest request; ConformanceResponse response; request.set_json_payload(input_json); request.set_requested_output_format(conformance::JSON); - string effective_test_name = "JsonInput." + test_name + ".Validator"; + string effective_test_name = ConformanceLevelToString(level) + + ".JsonInput." + test_name + ".Validator"; RunTest(effective_test_name, request, &response); @@ -439,7 +457,7 @@ void ConformanceTestSuite::RunValidJsonTestWithValidator( } if (response.result_case() != ConformanceResponse::kJsonPayload) { - ReportFailure(effective_test_name, request, response, + ReportFailure(effective_test_name, level, request, response, "Expected JSON payload but got type %d.", response.result_case()); return; @@ -447,13 +465,13 @@ void ConformanceTestSuite::RunValidJsonTestWithValidator( Json::Reader reader; Json::Value value; if (!reader.parse(response.json_payload(), value)) { - ReportFailure(effective_test_name, request, response, + ReportFailure(effective_test_name, level, request, response, "JSON payload cannot be parsed as valid JSON: %s", reader.getFormattedErrorMessages().c_str()); return; } if (!validator(value)) { - ReportFailure(effective_test_name, request, response, + ReportFailure(effective_test_name, level, request, response, "JSON payload validation failed."); return; } @@ -461,11 +479,12 @@ void ConformanceTestSuite::RunValidJsonTestWithValidator( } void ConformanceTestSuite::ExpectParseFailureForJson( - const string& test_name, const string& input_json) { + const string& test_name, ConformanceLevel level, const string& input_json) { ConformanceRequest request; ConformanceResponse response; request.set_json_payload(input_json); - string effective_test_name = "JsonInput." + test_name; + string effective_test_name = + ConformanceLevelToString(level) + ".JsonInput." + test_name; // We don't expect output, but if the program erroneously accepts the protobuf // we let it send its response as this. We must not leave it unspecified. @@ -477,13 +496,13 @@ void ConformanceTestSuite::ExpectParseFailureForJson( } else if (response.result_case() == ConformanceResponse::kSkipped) { ReportSkip(effective_test_name, request, response); } else { - ReportFailure(effective_test_name, request, response, + ReportFailure(effective_test_name, level, request, response, "Should have failed to parse, but didn't."); } } void ConformanceTestSuite::ExpectSerializeFailureForJson( - const string& test_name, const string& text_format) { + const string& test_name, ConformanceLevel level, const string& text_format) { TestAllTypes payload_message; GOOGLE_CHECK( TextFormat::ParseFromString(text_format, &payload_message)) @@ -492,7 +511,8 @@ void ConformanceTestSuite::ExpectSerializeFailureForJson( ConformanceRequest request; ConformanceResponse response; request.set_protobuf_payload(payload_message.SerializeAsString()); - string effective_test_name = test_name + ".JsonOutput"; + string effective_test_name = + ConformanceLevelToString(level) + "." + test_name + ".JsonOutput"; request.set_requested_output_format(conformance::JSON); RunTest(effective_test_name, request, &response); @@ -501,7 +521,7 @@ void ConformanceTestSuite::ExpectSerializeFailureForJson( } else if (response.result_case() == ConformanceResponse::kSkipped) { ReportSkip(effective_test_name, request, response); } else { - ReportFailure(effective_test_name, request, response, + ReportFailure(effective_test_name, level, request, response, "Should have failed to serialize, but didn't."); } } @@ -527,41 +547,43 @@ void ConformanceTestSuite::TestPrematureEOFForType(FieldDescriptor::Type type) { ExpectParseFailureForProto( tag(fieldnum, wire_type), - "PrematureEofBeforeKnownNonRepeatedValue" + type_name); + "PrematureEofBeforeKnownNonRepeatedValue" + type_name, REQUIRED); ExpectParseFailureForProto( tag(rep_fieldnum, wire_type), - "PrematureEofBeforeKnownRepeatedValue" + type_name); + "PrematureEofBeforeKnownRepeatedValue" + type_name, REQUIRED); ExpectParseFailureForProto( tag(UNKNOWN_FIELD, wire_type), - "PrematureEofBeforeUnknownValue" + type_name); + "PrematureEofBeforeUnknownValue" + type_name, REQUIRED); ExpectParseFailureForProto( cat( tag(fieldnum, wire_type), incomplete ), - "PrematureEofInsideKnownNonRepeatedValue" + type_name); + "PrematureEofInsideKnownNonRepeatedValue" + type_name, REQUIRED); ExpectParseFailureForProto( cat( tag(rep_fieldnum, wire_type), incomplete ), - "PrematureEofInsideKnownRepeatedValue" + type_name); + "PrematureEofInsideKnownRepeatedValue" + type_name, REQUIRED); ExpectParseFailureForProto( cat( tag(UNKNOWN_FIELD, wire_type), incomplete ), - "PrematureEofInsideUnknownValue" + type_name); + "PrematureEofInsideUnknownValue" + type_name, REQUIRED); if (wire_type == WireFormatLite::WIRETYPE_LENGTH_DELIMITED) { ExpectParseFailureForProto( cat( tag(fieldnum, wire_type), varint(1) ), - "PrematureEofInDelimitedDataForKnownNonRepeatedValue" + type_name); + "PrematureEofInDelimitedDataForKnownNonRepeatedValue" + type_name, + REQUIRED); ExpectParseFailureForProto( cat( tag(rep_fieldnum, wire_type), varint(1) ), - "PrematureEofInDelimitedDataForKnownRepeatedValue" + type_name); + "PrematureEofInDelimitedDataForKnownRepeatedValue" + type_name, + REQUIRED); // EOF in the middle of delimited data for unknown value. ExpectParseFailureForProto( cat( tag(UNKNOWN_FIELD, wire_type), varint(1) ), - "PrematureEofInDelimitedDataForUnknownValue" + type_name); + "PrematureEofInDelimitedDataForUnknownValue" + type_name, REQUIRED); if (type == FieldDescriptor::TYPE_MESSAGE) { // Submessage ends in the middle of a value. @@ -572,7 +594,7 @@ void ConformanceTestSuite::TestPrematureEOFForType(FieldDescriptor::Type type) { cat( tag(fieldnum, WireFormatLite::WIRETYPE_LENGTH_DELIMITED), varint(incomplete_submsg.size()), incomplete_submsg ), - "PrematureEofInSubmessageValue" + type_name); + "PrematureEofInSubmessageValue" + type_name, REQUIRED); } } else if (type != FieldDescriptor::TYPE_GROUP) { // Non-delimited, non-group: eligible for packing. @@ -582,13 +604,13 @@ void ConformanceTestSuite::TestPrematureEOFForType(FieldDescriptor::Type type) { cat( tag(rep_fieldnum, WireFormatLite::WIRETYPE_LENGTH_DELIMITED), varint(incomplete.size()), incomplete ), - "PrematureEofInPackedFieldValue" + type_name); + "PrematureEofInPackedFieldValue" + type_name, REQUIRED); // EOF in the middle of packed region. ExpectParseFailureForProto( cat( tag(rep_fieldnum, WireFormatLite::WIRETYPE_LENGTH_DELIMITED), varint(1) ), - "PrematureEofInPackedField" + type_name); + "PrematureEofInPackedField" + type_name, REQUIRED); } } @@ -651,14 +673,15 @@ bool ConformanceTestSuite::RunSuite(ConformanceTestRunner* runner, TestPrematureEOFForType(static_cast(i)); } - RunValidJsonTest("HelloWorld", "{\"optionalString\":\"Hello, World!\"}", + 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. RunValidJsonTest( - "FieldNameInSnakeCase", + "FieldNameInSnakeCase", REQUIRED, R"({ "fieldname1": 1, "fieldName2": 2, @@ -672,7 +695,7 @@ bool ConformanceTestSuite::RunSuite(ConformanceTestRunner* runner, field__name4_: 4 )"); RunValidJsonTest( - "FieldNameWithNumbers", + "FieldNameWithNumbers", REQUIRED, R"({ "field0name5": 5, "field0Name6": 6 @@ -682,14 +705,14 @@ bool ConformanceTestSuite::RunSuite(ConformanceTestRunner* runner, field_0_name6: 6 )"); RunValidJsonTest( - "FieldNameWithMixedCases", + "FieldNameWithMixedCases", REQUIRED, R"({ "fieldName7": 7, - "fieldName8": 8, + "FieldName8": 8, "fieldName9": 9, - "fieldName10": 10, - "fIELDNAME11": 11, - "fIELDName12": 12 + "FieldName10": 10, + "FIELDNAME11": 11, + "FIELDName12": 12 })", R"( fieldName7: 7 @@ -719,7 +742,7 @@ bool ConformanceTestSuite::RunSuite(ConformanceTestRunner* runner, )"); // Using the original proto field name in JSON is also allowed. RunValidJsonTest( - "OriginalProtoFieldName", + "OriginalProtoFieldName", REQUIRED, R"({ "fieldname1": 1, "field_name2": 2, @@ -762,7 +785,7 @@ bool ConformanceTestSuite::RunSuite(ConformanceTestRunner* runner, )"); // Field names can be escaped. RunValidJsonTest( - "FieldNameEscaped", + "FieldNameEscaped", REQUIRED, R"({"fieldn\u0061me1": 1})", "fieldname1: 1"); // String ends with escape character. @@ -771,11 +794,11 @@ bool ConformanceTestSuite::RunSuite(ConformanceTestRunner* runner, "{\"optionalString\": \"abc\\"); // Field names must be quoted (or it's not valid JSON). ExpectParseFailureForJson( - "FieldNameNotQuoted", + "FieldNameNotQuoted", RECOMMENDED, "{fieldname1: 1}"); // Trailing comma is not allowed (not valid JSON). ExpectParseFailureForJson( - "TrailingCommaInAnObject", + "TrailingCommaInAnObject", RECOMMENDED, R"({"fieldname1":1,})"); ExpectParseFailureForJson( "TrailingCommaInAnObjectWithSpace", @@ -790,7 +813,7 @@ bool ConformanceTestSuite::RunSuite(ConformanceTestRunner* runner, })"); // JSON doesn't support comments. ExpectParseFailureForJson( - "JsonWithComments", + "JsonWithComments", RECOMMENDED, R"({ // This is a comment. "fieldname1": 1 @@ -833,19 +856,19 @@ bool ConformanceTestSuite::RunSuite(ConformanceTestRunner* runner, "{\n \"optionalInt32\": 1\n \"optionalInt64\": 2\n}"); // Duplicated field names are not allowed. ExpectParseFailureForJson( - "FieldNameDuplicate", + "FieldNameDuplicate", RECOMMENDED, R"({ "optionalNestedMessage": {a: 1}, "optionalNestedMessage": {} })"); ExpectParseFailureForJson( - "FieldNameDuplicateDifferentCasing1", + "FieldNameDuplicateDifferentCasing1", RECOMMENDED, R"({ "optional_nested_message": {a: 1}, "optionalNestedMessage": {} })"); ExpectParseFailureForJson( - "FieldNameDuplicateDifferentCasing2", + "FieldNameDuplicateDifferentCasing2", RECOMMENDED, R"({ "optionalNestedMessage": {a: 1}, "optional_nested_message": {} @@ -854,7 +877,7 @@ bool ConformanceTestSuite::RunSuite(ConformanceTestRunner* runner, // all be correct. // Serializers should use lowerCamelCase by default. RunValidJsonTestWithValidator( - "FieldNameInLowerCamelCase", + "FieldNameInLowerCamelCase", REQUIRED, R"({ "fieldname1": 1, "fieldName2": 2, @@ -868,7 +891,7 @@ bool ConformanceTestSuite::RunSuite(ConformanceTestRunner* runner, value.isMember("fieldName4"); }); RunValidJsonTestWithValidator( - "FieldNameWithNumbers", + "FieldNameWithNumbers", REQUIRED, R"({ "field0name5": 5, "field0Name6": 6 @@ -878,22 +901,22 @@ bool ConformanceTestSuite::RunSuite(ConformanceTestRunner* runner, value.isMember("field0Name6"); }); RunValidJsonTestWithValidator( - "FieldNameWithMixedCases", + "FieldNameWithMixedCases", REQUIRED, R"({ "fieldName7": 7, - "fieldName8": 8, + "FieldName8": 8, "fieldName9": 9, - "fieldName10": 10, - "fIELDNAME11": 11, - "fIELDName12": 12 + "FieldName10": 10, + "FIELDNAME11": 11, + "FIELDName12": 12 })", [](const Json::Value& value) { return value.isMember("fieldName7") && - value.isMember("fieldName8") && + value.isMember("FieldName8") && value.isMember("fieldName9") && - value.isMember("fieldName10") && - value.isMember("fIELDNAME11") && - value.isMember("fIELDName12"); + value.isMember("FieldName10") && + value.isMember("FIELDNAME11") && + value.isMember("FIELDName12"); }); RunValidJsonTestWithValidator( "FieldNameWithDoubleUnderscores", @@ -916,27 +939,27 @@ bool ConformanceTestSuite::RunSuite(ConformanceTestRunner* runner, // Integer fields. RunValidJsonTest( - "Int32FieldMaxValue", + "Int32FieldMaxValue", REQUIRED, R"({"optionalInt32": 2147483647})", "optional_int32: 2147483647"); RunValidJsonTest( - "Int32FieldMinValue", + "Int32FieldMinValue", REQUIRED, R"({"optionalInt32": -2147483648})", "optional_int32: -2147483648"); RunValidJsonTest( - "Uint32FieldMaxValue", + "Uint32FieldMaxValue", REQUIRED, R"({"optionalUint32": 4294967295})", "optional_uint32: 4294967295"); RunValidJsonTest( - "Int64FieldMaxValue", + "Int64FieldMaxValue", REQUIRED, R"({"optionalInt64": "9223372036854775807"})", "optional_int64: 9223372036854775807"); RunValidJsonTest( - "Int64FieldMinValue", + "Int64FieldMinValue", REQUIRED, R"({"optionalInt64": "-9223372036854775808"})", "optional_int64: -9223372036854775808"); RunValidJsonTest( - "Uint64FieldMaxValue", + "Uint64FieldMaxValue", REQUIRED, R"({"optionalUint64": "18446744073709551615"})", "optional_uint64: 18446744073709551615"); // While not the largest Int64, this is the largest @@ -946,127 +969,127 @@ bool ConformanceTestSuite::RunSuite(ConformanceTestRunner* runner, // work in some implementations, but should not be // relied upon. RunValidJsonTest( - "Int64FieldMaxValueNotQuoted", + "Int64FieldMaxValueNotQuoted", REQUIRED, R"({"optionalInt64": 9223372036854774784})", "optional_int64: 9223372036854774784"); RunValidJsonTest( - "Int64FieldMinValueNotQuoted", + "Int64FieldMinValueNotQuoted", REQUIRED, R"({"optionalInt64": -9223372036854775808})", "optional_int64: -9223372036854775808"); // Largest interoperable Uint64; see comment above // for Int64FieldMaxValueNotQuoted. RunValidJsonTest( - "Uint64FieldMaxValueNotQuoted", + "Uint64FieldMaxValueNotQuoted", REQUIRED, R"({"optionalUint64": 18446744073709549568})", "optional_uint64: 18446744073709549568"); // Values can be represented as JSON strings. RunValidJsonTest( - "Int32FieldStringValue", + "Int32FieldStringValue", REQUIRED, R"({"optionalInt32": "2147483647"})", "optional_int32: 2147483647"); RunValidJsonTest( - "Int32FieldStringValueEscaped", + "Int32FieldStringValueEscaped", REQUIRED, R"({"optionalInt32": "2\u003147483647"})", "optional_int32: 2147483647"); // Parsers reject out-of-bound integer values. ExpectParseFailureForJson( - "Int32FieldTooLarge", + "Int32FieldTooLarge", REQUIRED, R"({"optionalInt32": 2147483648})"); ExpectParseFailureForJson( - "Int32FieldTooSmall", + "Int32FieldTooSmall", REQUIRED, R"({"optionalInt32": -2147483649})"); ExpectParseFailureForJson( - "Uint32FieldTooLarge", + "Uint32FieldTooLarge", REQUIRED, R"({"optionalUint32": 4294967296})"); ExpectParseFailureForJson( - "Int64FieldTooLarge", + "Int64FieldTooLarge", REQUIRED, R"({"optionalInt64": "9223372036854775808"})"); ExpectParseFailureForJson( - "Int64FieldTooSmall", + "Int64FieldTooSmall", REQUIRED, R"({"optionalInt64": "-9223372036854775809"})"); ExpectParseFailureForJson( - "Uint64FieldTooLarge", + "Uint64FieldTooLarge", REQUIRED, R"({"optionalUint64": "18446744073709551616"})"); // Parser reject non-integer numeric values as well. ExpectParseFailureForJson( - "Int32FieldNotInteger", + "Int32FieldNotInteger", REQUIRED, R"({"optionalInt32": 0.5})"); ExpectParseFailureForJson( - "Uint32FieldNotInteger", + "Uint32FieldNotInteger", REQUIRED, R"({"optionalUint32": 0.5})"); ExpectParseFailureForJson( - "Int64FieldNotInteger", + "Int64FieldNotInteger", REQUIRED, R"({"optionalInt64": "0.5"})"); ExpectParseFailureForJson( - "Uint64FieldNotInteger", + "Uint64FieldNotInteger", REQUIRED, R"({"optionalUint64": "0.5"})"); // Integers but represented as float values are accepted. RunValidJsonTest( - "Int32FieldFloatTrailingZero", + "Int32FieldFloatTrailingZero", REQUIRED, R"({"optionalInt32": 100000.000})", "optional_int32: 100000"); RunValidJsonTest( - "Int32FieldExponentialFormat", + "Int32FieldExponentialFormat", REQUIRED, R"({"optionalInt32": 1e5})", "optional_int32: 100000"); RunValidJsonTest( - "Int32FieldMaxFloatValue", + "Int32FieldMaxFloatValue", REQUIRED, R"({"optionalInt32": 2.147483647e9})", "optional_int32: 2147483647"); RunValidJsonTest( - "Int32FieldMinFloatValue", + "Int32FieldMinFloatValue", REQUIRED, R"({"optionalInt32": -2.147483648e9})", "optional_int32: -2147483648"); RunValidJsonTest( - "Uint32FieldMaxFloatValue", + "Uint32FieldMaxFloatValue", REQUIRED, R"({"optionalUint32": 4.294967295e9})", "optional_uint32: 4294967295"); // Parser reject non-numeric values. ExpectParseFailureForJson( - "Int32FieldNotNumber", + "Int32FieldNotNumber", REQUIRED, R"({"optionalInt32": "3x3"})"); ExpectParseFailureForJson( - "Uint32FieldNotNumber", + "Uint32FieldNotNumber", REQUIRED, R"({"optionalUint32": "3x3"})"); ExpectParseFailureForJson( - "Int64FieldNotNumber", + "Int64FieldNotNumber", REQUIRED, R"({"optionalInt64": "3x3"})"); ExpectParseFailureForJson( - "Uint64FieldNotNumber", + "Uint64FieldNotNumber", REQUIRED, R"({"optionalUint64": "3x3"})"); // JSON does not allow "+" on numric values. ExpectParseFailureForJson( - "Int32FieldPlusSign", + "Int32FieldPlusSign", REQUIRED, R"({"optionalInt32": +1})"); // JSON doesn't allow leading 0s. ExpectParseFailureForJson( - "Int32FieldLeadingZero", + "Int32FieldLeadingZero", REQUIRED, R"({"optionalInt32": 01})"); ExpectParseFailureForJson( - "Int32FieldNegativeWithLeadingZero", + "Int32FieldNegativeWithLeadingZero", REQUIRED, R"({"optionalInt32": -01})"); // String values must follow the same syntax rule. Specifically leading // or traling spaces are not allowed. ExpectParseFailureForJson( - "Int32FieldLeadingSpace", + "Int32FieldLeadingSpace", REQUIRED, R"({"optionalInt32": " 1"})"); ExpectParseFailureForJson( - "Int32FieldTrailingSpace", + "Int32FieldTrailingSpace", REQUIRED, R"({"optionalInt32": "1 "})"); // 64-bit values are serialized as strings. RunValidJsonTestWithValidator( - "Int64FieldBeString", + "Int64FieldBeString", RECOMMENDED, R"({"optionalInt64": 1})", [](const Json::Value& value) { return value["optionalInt64"].type() == Json::stringValue && value["optionalInt64"].asString() == "1"; }); RunValidJsonTestWithValidator( - "Uint64FieldBeString", + "Uint64FieldBeString", RECOMMENDED, R"({"optionalUint64": 1})", [](const Json::Value& value) { return value["optionalUint64"].type() == Json::stringValue && @@ -1075,73 +1098,73 @@ bool ConformanceTestSuite::RunSuite(ConformanceTestRunner* runner, // Bool fields. RunValidJsonTest( - "BoolFieldTrue", + "BoolFieldTrue", REQUIRED, R"({"optionalBool":true})", "optional_bool: true"); RunValidJsonTest( - "BoolFieldFalse", + "BoolFieldFalse", REQUIRED, R"({"optionalBool":false})", "optional_bool: false"); // Other forms are not allowed. ExpectParseFailureForJson( - "BoolFieldIntegerZero", + "BoolFieldIntegerZero", RECOMMENDED, R"({"optionalBool":0})"); ExpectParseFailureForJson( - "BoolFieldIntegerOne", + "BoolFieldIntegerOne", RECOMMENDED, R"({"optionalBool":1})"); ExpectParseFailureForJson( - "BoolFieldCamelCaseTrue", + "BoolFieldCamelCaseTrue", RECOMMENDED, R"({"optionalBool":True})"); ExpectParseFailureForJson( - "BoolFieldCamelCaseFalse", + "BoolFieldCamelCaseFalse", RECOMMENDED, R"({"optionalBool":False})"); ExpectParseFailureForJson( - "BoolFieldAllCapitalTrue", + "BoolFieldAllCapitalTrue", RECOMMENDED, R"({"optionalBool":TRUE})"); ExpectParseFailureForJson( - "BoolFieldAllCapitalFalse", + "BoolFieldAllCapitalFalse", RECOMMENDED, R"({"optionalBool":FALSE})"); ExpectParseFailureForJson( - "BoolFieldDoubleQuotedTrue", + "BoolFieldDoubleQuotedTrue", RECOMMENDED, R"({"optionalBool":"true"})"); ExpectParseFailureForJson( - "BoolFieldDoubleQuotedFalse", + "BoolFieldDoubleQuotedFalse", RECOMMENDED, R"({"optionalBool":"false"})"); // Float fields. RunValidJsonTest( - "FloatFieldMinPositiveValue", + "FloatFieldMinPositiveValue", REQUIRED, R"({"optionalFloat": 1.175494e-38})", "optional_float: 1.175494e-38"); RunValidJsonTest( - "FloatFieldMaxNegativeValue", + "FloatFieldMaxNegativeValue", REQUIRED, R"({"optionalFloat": -1.175494e-38})", "optional_float: -1.175494e-38"); RunValidJsonTest( - "FloatFieldMaxPositiveValue", + "FloatFieldMaxPositiveValue", REQUIRED, R"({"optionalFloat": 3.402823e+38})", "optional_float: 3.402823e+38"); RunValidJsonTest( - "FloatFieldMinNegativeValue", + "FloatFieldMinNegativeValue", REQUIRED, R"({"optionalFloat": 3.402823e+38})", "optional_float: 3.402823e+38"); // Values can be quoted. RunValidJsonTest( - "FloatFieldQuotedValue", + "FloatFieldQuotedValue", REQUIRED, R"({"optionalFloat": "1"})", "optional_float: 1"); // Special values. RunValidJsonTest( - "FloatFieldNan", + "FloatFieldNan", REQUIRED, R"({"optionalFloat": "NaN"})", "optional_float: nan"); RunValidJsonTest( - "FloatFieldInfinity", + "FloatFieldInfinity", REQUIRED, R"({"optionalFloat": "Infinity"})", "optional_float: inf"); RunValidJsonTest( - "FloatFieldNegativeInfinity", + "FloatFieldNegativeInfinity", REQUIRED, R"({"optionalFloat": "-Infinity"})", "optional_float: -inf"); // Non-cannonical Nan will be correctly normalized. @@ -1152,68 +1175,68 @@ bool ConformanceTestSuite::RunSuite(ConformanceTestRunner* runner, message.set_optional_float( WireFormatLite::DecodeFloat(0x7FA12345)); RunValidJsonTestWithProtobufInput( - "FloatFieldNormalizeQuietNan", message, + "FloatFieldNormalizeQuietNan", REQUIRED, message, "optional_float: nan"); // IEEE floating-point standard 64-bit signaling NaN: // 1111 1111 1xxx xxxx xxxx xxxx xxxx xxxx message.set_optional_float( WireFormatLite::DecodeFloat(0xFFB54321)); RunValidJsonTestWithProtobufInput( - "FloatFieldNormalizeSignalingNan", message, + "FloatFieldNormalizeSignalingNan", REQUIRED, message, "optional_float: nan"); } // Special values must be quoted. ExpectParseFailureForJson( - "FloatFieldNanNotQuoted", + "FloatFieldNanNotQuoted", RECOMMENDED, R"({"optionalFloat": NaN})"); ExpectParseFailureForJson( - "FloatFieldInfinityNotQuoted", + "FloatFieldInfinityNotQuoted", RECOMMENDED, R"({"optionalFloat": Infinity})"); ExpectParseFailureForJson( - "FloatFieldNegativeInfinityNotQuoted", + "FloatFieldNegativeInfinityNotQuoted", RECOMMENDED, R"({"optionalFloat": -Infinity})"); // Parsers should reject out-of-bound values. ExpectParseFailureForJson( - "FloatFieldTooSmall", + "FloatFieldTooSmall", REQUIRED, R"({"optionalFloat": -3.502823e+38})"); ExpectParseFailureForJson( - "FloatFieldTooLarge", + "FloatFieldTooLarge", REQUIRED, R"({"optionalFloat": 3.502823e+38})"); // Double fields. RunValidJsonTest( - "DoubleFieldMinPositiveValue", + "DoubleFieldMinPositiveValue", REQUIRED, R"({"optionalDouble": 2.22507e-308})", "optional_double: 2.22507e-308"); RunValidJsonTest( - "DoubleFieldMaxNegativeValue", + "DoubleFieldMaxNegativeValue", REQUIRED, R"({"optionalDouble": -2.22507e-308})", "optional_double: -2.22507e-308"); RunValidJsonTest( - "DoubleFieldMaxPositiveValue", + "DoubleFieldMaxPositiveValue", REQUIRED, R"({"optionalDouble": 1.79769e+308})", "optional_double: 1.79769e+308"); RunValidJsonTest( - "DoubleFieldMinNegativeValue", + "DoubleFieldMinNegativeValue", REQUIRED, R"({"optionalDouble": -1.79769e+308})", "optional_double: -1.79769e+308"); // Values can be quoted. RunValidJsonTest( - "DoubleFieldQuotedValue", + "DoubleFieldQuotedValue", REQUIRED, R"({"optionalDouble": "1"})", "optional_double: 1"); // Speical values. RunValidJsonTest( - "DoubleFieldNan", + "DoubleFieldNan", REQUIRED, R"({"optionalDouble": "NaN"})", "optional_double: nan"); RunValidJsonTest( - "DoubleFieldInfinity", + "DoubleFieldInfinity", REQUIRED, R"({"optionalDouble": "Infinity"})", "optional_double: inf"); RunValidJsonTest( - "DoubleFieldNegativeInfinity", + "DoubleFieldNegativeInfinity", REQUIRED, R"({"optionalDouble": "-Infinity"})", "optional_double: -inf"); // Non-cannonical Nan will be correctly normalized. @@ -1222,55 +1245,55 @@ bool ConformanceTestSuite::RunSuite(ConformanceTestRunner* runner, message.set_optional_double( WireFormatLite::DecodeDouble(0x7FFA123456789ABCLL)); RunValidJsonTestWithProtobufInput( - "DoubleFieldNormalizeQuietNan", message, + "DoubleFieldNormalizeQuietNan", REQUIRED, message, "optional_double: nan"); message.set_optional_double( WireFormatLite::DecodeDouble(0xFFFBCBA987654321LL)); RunValidJsonTestWithProtobufInput( - "DoubleFieldNormalizeSignalingNan", message, + "DoubleFieldNormalizeSignalingNan", REQUIRED, message, "optional_double: nan"); } // Special values must be quoted. ExpectParseFailureForJson( - "DoubleFieldNanNotQuoted", + "DoubleFieldNanNotQuoted", RECOMMENDED, R"({"optionalDouble": NaN})"); ExpectParseFailureForJson( - "DoubleFieldInfinityNotQuoted", + "DoubleFieldInfinityNotQuoted", RECOMMENDED, R"({"optionalDouble": Infinity})"); ExpectParseFailureForJson( - "DoubleFieldNegativeInfinityNotQuoted", + "DoubleFieldNegativeInfinityNotQuoted", RECOMMENDED, R"({"optionalDouble": -Infinity})"); // Parsers should reject out-of-bound values. ExpectParseFailureForJson( - "DoubleFieldTooSmall", + "DoubleFieldTooSmall", REQUIRED, R"({"optionalDouble": -1.89769e+308})"); ExpectParseFailureForJson( - "DoubleFieldTooLarge", + "DoubleFieldTooLarge", REQUIRED, R"({"optionalDouble": +1.89769e+308})"); // Enum fields. RunValidJsonTest( - "EnumField", + "EnumField", REQUIRED, R"({"optionalNestedEnum": "FOO"})", "optional_nested_enum: FOO"); // Enum values must be represented as strings. ExpectParseFailureForJson( - "EnumFieldNotQuoted", + "EnumFieldNotQuoted", REQUIRED, R"({"optionalNestedEnum": FOO})"); // Numeric values are allowed. RunValidJsonTest( - "EnumFieldNumericValueZero", + "EnumFieldNumericValueZero", REQUIRED, R"({"optionalNestedEnum": 0})", "optional_nested_enum: FOO"); RunValidJsonTest( - "EnumFieldNumericValueNonZero", + "EnumFieldNumericValueNonZero", REQUIRED, R"({"optionalNestedEnum": 1})", "optional_nested_enum: BAR"); // Unknown enum values are represented as numeric values. RunValidJsonTestWithValidator( - "EnumFieldUnknownValue", + "EnumFieldUnknownValue", REQUIRED, R"({"optionalNestedEnum": 123})", [](const Json::Value& value) { return value["optionalNestedEnum"].type() == Json::intValue && @@ -1279,76 +1302,73 @@ bool ConformanceTestSuite::RunSuite(ConformanceTestRunner* runner, // String fields. RunValidJsonTest( - "StringField", + "StringField", REQUIRED, R"({"optionalString": "Hello world!"})", "optional_string: \"Hello world!\""); RunValidJsonTest( - "StringFieldUnicode", + "StringFieldUnicode", REQUIRED, // Google in Chinese. R"({"optionalString": "谷歌"})", R"(optional_string: "谷歌")"); RunValidJsonTest( - "StringFieldEscape", + "StringFieldEscape", REQUIRED, R"({"optionalString": "\"\\\/\b\f\n\r\t"})", R"(optional_string: "\"\\/\b\f\n\r\t")"); RunValidJsonTest( - "StringFieldUnicodeEscape", + "StringFieldUnicodeEscape", REQUIRED, R"({"optionalString": "\u8C37\u6B4C"})", R"(optional_string: "谷歌")"); RunValidJsonTest( - "StringFieldUnicodeEscapeWithLowercaseHexLetters", + "StringFieldUnicodeEscapeWithLowercaseHexLetters", REQUIRED, R"({"optionalString": "\u8c37\u6b4c"})", R"(optional_string: "谷歌")"); RunValidJsonTest( - "StringFieldSurrogatePair", + "StringFieldSurrogatePair", REQUIRED, // The character is an emoji: grinning face with smiling eyes. 😁 R"({"optionalString": "\uD83D\uDE01"})", R"(optional_string: "\xF0\x9F\x98\x81")"); // Unicode escapes must start with "\u" (lowercase u). ExpectParseFailureForJson( - "StringFieldUppercaseEscapeLetter", + "StringFieldUppercaseEscapeLetter", RECOMMENDED, R"({"optionalString": "\U8C37\U6b4C"})"); ExpectParseFailureForJson( - "StringFieldInvalidEscape", + "StringFieldInvalidEscape", RECOMMENDED, R"({"optionalString": "\uXXXX\u6B4C"})"); ExpectParseFailureForJson( - "StringFieldUnterminatedEscape", + "StringFieldUnterminatedEscape", RECOMMENDED, R"({"optionalString": "\u8C3"})"); ExpectParseFailureForJson( - "StringFieldUnpairedHighSurrogate", + "StringFieldUnpairedHighSurrogate", RECOMMENDED, R"({"optionalString": "\uD800"})"); ExpectParseFailureForJson( - "StringFieldUnpairedLowSurrogate", + "StringFieldUnpairedLowSurrogate", RECOMMENDED, R"({"optionalString": "\uDC00"})"); ExpectParseFailureForJson( - "StringFieldSurrogateInWrongOrder", + "StringFieldSurrogateInWrongOrder", RECOMMENDED, R"({"optionalString": "\uDE01\uD83D"})"); ExpectParseFailureForJson( - "StringFieldNotAString", + "StringFieldNotAString", REQUIRED, R"({"optionalString": 12345})"); // Bytes fields. RunValidJsonTest( - "BytesField", + "BytesField", REQUIRED, R"({"optionalBytes": "AQI="})", R"(optional_bytes: "\x01\x02")"); ExpectParseFailureForJson( - "BytesFieldNoPadding", - R"({"optionalBytes": "AQI"})"); - ExpectParseFailureForJson( - "BytesFieldInvalidBase64Characters", + "BytesFieldInvalidBase64Characters", REQUIRED, R"({"optionalBytes": "-_=="})"); // Message fields. RunValidJsonTest( - "MessageField", + "MessageField", REQUIRED, R"({"optionalNestedMessage": {"a": 1234}})", "optional_nested_message: {a: 1234}"); // Oneof fields. ExpectParseFailureForJson( - "OneofFieldDuplicate", + "OneofFieldDuplicate", REQUIRED, R"({"oneofUint32": 1, "oneofString": "test"})"); // Ensure zero values for oneof make it out/backs. { @@ -1411,58 +1431,58 @@ bool ConformanceTestSuite::RunSuite(ConformanceTestRunner* runner, // Repeated fields. RunValidJsonTest( - "PrimitiveRepeatedField", + "PrimitiveRepeatedField", REQUIRED, R"({"repeatedInt32": [1, 2, 3, 4]})", "repeated_int32: [1, 2, 3, 4]"); RunValidJsonTest( - "EnumRepeatedField", + "EnumRepeatedField", REQUIRED, R"({"repeatedNestedEnum": ["FOO", "BAR", "BAZ"]})", "repeated_nested_enum: [FOO, BAR, BAZ]"); RunValidJsonTest( - "StringRepeatedField", + "StringRepeatedField", REQUIRED, R"({"repeatedString": ["Hello", "world"]})", R"(repeated_string: ["Hello", "world"])"); RunValidJsonTest( - "BytesRepeatedField", + "BytesRepeatedField", REQUIRED, R"({"repeatedBytes": ["AAEC", "AQI="]})", R"(repeated_bytes: ["\x00\x01\x02", "\x01\x02"])"); RunValidJsonTest( - "MessageRepeatedField", + "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", + "RepeatedFieldWrongElementTypeExpectingIntegersGotBool", REQUIRED, R"({"repeatedInt32": [1, false, 3, 4]})"); ExpectParseFailureForJson( - "RepeatedFieldWrongElementTypeExpectingIntegersGotString", + "RepeatedFieldWrongElementTypeExpectingIntegersGotString", REQUIRED, R"({"repeatedInt32": [1, 2, "name", 4]})"); ExpectParseFailureForJson( - "RepeatedFieldWrongElementTypeExpectingIntegersGotMessage", + "RepeatedFieldWrongElementTypeExpectingIntegersGotMessage", REQUIRED, R"({"repeatedInt32": [1, 2, 3, {"a": 4}]})"); ExpectParseFailureForJson( - "RepeatedFieldWrongElementTypeExpectingStringsGotInt", + "RepeatedFieldWrongElementTypeExpectingStringsGotInt", REQUIRED, R"({"repeatedString": ["1", 2, "3", "4"]})"); ExpectParseFailureForJson( - "RepeatedFieldWrongElementTypeExpectingStringsGotBool", + "RepeatedFieldWrongElementTypeExpectingStringsGotBool", REQUIRED, R"({"repeatedString": ["1", "2", false, "4"]})"); ExpectParseFailureForJson( - "RepeatedFieldWrongElementTypeExpectingStringsGotMessage", + "RepeatedFieldWrongElementTypeExpectingStringsGotMessage", REQUIRED, R"({"repeatedString": ["1", 2, "3", {"a": 4}]})"); ExpectParseFailureForJson( - "RepeatedFieldWrongElementTypeExpectingMessagesGotInt", + "RepeatedFieldWrongElementTypeExpectingMessagesGotInt", REQUIRED, R"({"repeatedNestedMessage": [{"a": 1}, 2]})"); ExpectParseFailureForJson( - "RepeatedFieldWrongElementTypeExpectingMessagesGotBool", + "RepeatedFieldWrongElementTypeExpectingMessagesGotBool", REQUIRED, R"({"repeatedNestedMessage": [{"a": 1}, false]})"); ExpectParseFailureForJson( - "RepeatedFieldWrongElementTypeExpectingMessagesGotString", + "RepeatedFieldWrongElementTypeExpectingMessagesGotString", REQUIRED, R"({"repeatedNestedMessage": [{"a": 1}, "2"]})"); // Trailing comma in the repeated field is not allowed. ExpectParseFailureForJson( - "RepeatedFieldTrailingComma", + "RepeatedFieldTrailingComma", RECOMMENDED, R"({"repeatedInt32": [1, 2, 3, 4,]})"); ExpectParseFailureForJson( "RepeatedFieldTrailingCommaWithSpace", @@ -1476,47 +1496,47 @@ bool ConformanceTestSuite::RunSuite(ConformanceTestRunner* runner, // Map fields. RunValidJsonTest( - "Int32MapField", + "Int32MapField", REQUIRED, R"({"mapInt32Int32": {"1": 2, "3": 4}})", "map_int32_int32: {key: 1 value: 2}" "map_int32_int32: {key: 3 value: 4}"); ExpectParseFailureForJson( - "Int32MapFieldKeyNotQuoted", + "Int32MapFieldKeyNotQuoted", RECOMMENDED, R"({"mapInt32Int32": {1: 2, 3: 4}})"); RunValidJsonTest( - "Uint32MapField", + "Uint32MapField", REQUIRED, R"({"mapUint32Uint32": {"1": 2, "3": 4}})", "map_uint32_uint32: {key: 1 value: 2}" "map_uint32_uint32: {key: 3 value: 4}"); ExpectParseFailureForJson( - "Uint32MapFieldKeyNotQuoted", + "Uint32MapFieldKeyNotQuoted", RECOMMENDED, R"({"mapUint32Uint32": {1: 2, 3: 4}})"); RunValidJsonTest( - "Int64MapField", + "Int64MapField", REQUIRED, R"({"mapInt64Int64": {"1": 2, "3": 4}})", "map_int64_int64: {key: 1 value: 2}" "map_int64_int64: {key: 3 value: 4}"); ExpectParseFailureForJson( - "Int64MapFieldKeyNotQuoted", + "Int64MapFieldKeyNotQuoted", RECOMMENDED, R"({"mapInt64Int64": {1: 2, 3: 4}})"); RunValidJsonTest( - "Uint64MapField", + "Uint64MapField", REQUIRED, R"({"mapUint64Uint64": {"1": 2, "3": 4}})", "map_uint64_uint64: {key: 1 value: 2}" "map_uint64_uint64: {key: 3 value: 4}"); ExpectParseFailureForJson( - "Uint64MapFieldKeyNotQuoted", + "Uint64MapFieldKeyNotQuoted", RECOMMENDED, R"({"mapUint64Uint64": {1: 2, 3: 4}})"); RunValidJsonTest( - "BoolMapField", + "BoolMapField", REQUIRED, R"({"mapBoolBool": {"true": true, "false": false}})", "map_bool_bool: {key: true value: true}" "map_bool_bool: {key: false value: false}"); ExpectParseFailureForJson( - "BoolMapFieldKeyNotQuoted", + "BoolMapFieldKeyNotQuoted", RECOMMENDED, R"({"mapBoolBool": {true: true, false: false}})"); RunValidJsonTest( - "MessageMapField", + "MessageMapField", REQUIRED, R"({ "mapStringNestedMessage": { "hello": {"a": 1234}, @@ -1535,21 +1555,21 @@ bool ConformanceTestSuite::RunSuite(ConformanceTestRunner* runner, )"); // Since Map keys are represented as JSON strings, escaping should be allowed. RunValidJsonTest( - "Int32MapEscapedKey", + "Int32MapEscapedKey", REQUIRED, R"({"mapInt32Int32": {"\u0031": 2}})", "map_int32_int32: {key: 1 value: 2}"); RunValidJsonTest( - "Int64MapEscapedKey", + "Int64MapEscapedKey", REQUIRED, R"({"mapInt64Int64": {"\u0031": 2}})", "map_int64_int64: {key: 1 value: 2}"); RunValidJsonTest( - "BoolMapEscapedKey", + "BoolMapEscapedKey", REQUIRED, R"({"mapBoolBool": {"tr\u0075e": true}})", "map_bool_bool: {key: true value: true}"); // "null" is accepted for all fields types. RunValidJsonTest( - "AllFieldAcceptNull", + "AllFieldAcceptNull", REQUIRED, R"({ "optionalInt32": null, "optionalInt64": null, @@ -1577,18 +1597,18 @@ bool ConformanceTestSuite::RunSuite(ConformanceTestRunner* runner, // Repeated field elements cannot be null. ExpectParseFailureForJson( - "RepeatedFieldPrimitiveElementIsNull", + "RepeatedFieldPrimitiveElementIsNull", RECOMMENDED, R"({"repeatedInt32": [1, null, 2]})"); ExpectParseFailureForJson( - "RepeatedFieldMessageElementIsNull", + "RepeatedFieldMessageElementIsNull", RECOMMENDED, R"({"repeatedNestedMessage": [{"a":1}, null, {"a":2}]})"); // Map field keys cannot be null. ExpectParseFailureForJson( - "MapFieldKeyIsNull", + "MapFieldKeyIsNull", RECOMMENDED, R"({"mapInt32Int32": {null: 1}})"); // Map field values cannot be null. ExpectParseFailureForJson( - "MapFieldValueIsNull", + "MapFieldValueIsNull", RECOMMENDED, R"({"mapInt32Int32": {"0": null}})"); // http://www.rfc-editor.org/rfc/rfc7159.txt says strings have to use double @@ -1605,43 +1625,43 @@ bool ConformanceTestSuite::RunSuite(ConformanceTestRunner* runner, // Wrapper types. RunValidJsonTest( - "OptionalBoolWrapper", + "OptionalBoolWrapper", REQUIRED, R"({"optionalBoolWrapper": false})", "optional_bool_wrapper: {value: false}"); RunValidJsonTest( - "OptionalInt32Wrapper", + "OptionalInt32Wrapper", REQUIRED, R"({"optionalInt32Wrapper": 0})", "optional_int32_wrapper: {value: 0}"); RunValidJsonTest( - "OptionalUint32Wrapper", + "OptionalUint32Wrapper", REQUIRED, R"({"optionalUint32Wrapper": 0})", "optional_uint32_wrapper: {value: 0}"); RunValidJsonTest( - "OptionalInt64Wrapper", + "OptionalInt64Wrapper", REQUIRED, R"({"optionalInt64Wrapper": 0})", "optional_int64_wrapper: {value: 0}"); RunValidJsonTest( - "OptionalUint64Wrapper", + "OptionalUint64Wrapper", REQUIRED, R"({"optionalUint64Wrapper": 0})", "optional_uint64_wrapper: {value: 0}"); RunValidJsonTest( - "OptionalFloatWrapper", + "OptionalFloatWrapper", REQUIRED, R"({"optionalFloatWrapper": 0})", "optional_float_wrapper: {value: 0}"); RunValidJsonTest( - "OptionalDoubleWrapper", + "OptionalDoubleWrapper", REQUIRED, R"({"optionalDoubleWrapper": 0})", "optional_double_wrapper: {value: 0}"); RunValidJsonTest( - "OptionalStringWrapper", + "OptionalStringWrapper", REQUIRED, R"({"optionalStringWrapper": ""})", R"(optional_string_wrapper: {value: ""})"); RunValidJsonTest( - "OptionalBytesWrapper", + "OptionalBytesWrapper", REQUIRED, R"({"optionalBytesWrapper": ""})", R"(optional_bytes_wrapper: {value: ""})"); RunValidJsonTest( - "OptionalWrapperTypesWithNonDefaultValue", + "OptionalWrapperTypesWithNonDefaultValue", REQUIRED, R"({ "optionalBoolWrapper": true, "optionalInt32Wrapper": 1, @@ -1665,56 +1685,56 @@ bool ConformanceTestSuite::RunSuite(ConformanceTestRunner* runner, optional_bytes_wrapper: {value: "\x01\x02"} )"); RunValidJsonTest( - "RepeatedBoolWrapper", + "RepeatedBoolWrapper", REQUIRED, R"({"repeatedBoolWrapper": [true, false]})", "repeated_bool_wrapper: {value: true}" "repeated_bool_wrapper: {value: false}"); RunValidJsonTest( - "RepeatedInt32Wrapper", + "RepeatedInt32Wrapper", REQUIRED, R"({"repeatedInt32Wrapper": [0, 1]})", "repeated_int32_wrapper: {value: 0}" "repeated_int32_wrapper: {value: 1}"); RunValidJsonTest( - "RepeatedUint32Wrapper", + "RepeatedUint32Wrapper", REQUIRED, R"({"repeatedUint32Wrapper": [0, 1]})", "repeated_uint32_wrapper: {value: 0}" "repeated_uint32_wrapper: {value: 1}"); RunValidJsonTest( - "RepeatedInt64Wrapper", + "RepeatedInt64Wrapper", REQUIRED, R"({"repeatedInt64Wrapper": [0, 1]})", "repeated_int64_wrapper: {value: 0}" "repeated_int64_wrapper: {value: 1}"); RunValidJsonTest( - "RepeatedUint64Wrapper", + "RepeatedUint64Wrapper", REQUIRED, R"({"repeatedUint64Wrapper": [0, 1]})", "repeated_uint64_wrapper: {value: 0}" "repeated_uint64_wrapper: {value: 1}"); RunValidJsonTest( - "RepeatedFloatWrapper", + "RepeatedFloatWrapper", REQUIRED, R"({"repeatedFloatWrapper": [0, 1]})", "repeated_float_wrapper: {value: 0}" "repeated_float_wrapper: {value: 1}"); RunValidJsonTest( - "RepeatedDoubleWrapper", + "RepeatedDoubleWrapper", REQUIRED, R"({"repeatedDoubleWrapper": [0, 1]})", "repeated_double_wrapper: {value: 0}" "repeated_double_wrapper: {value: 1}"); RunValidJsonTest( - "RepeatedStringWrapper", + "RepeatedStringWrapper", REQUIRED, R"({"repeatedStringWrapper": ["", "AQI="]})", R"( repeated_string_wrapper: {value: ""} repeated_string_wrapper: {value: "AQI="} )"); RunValidJsonTest( - "RepeatedBytesWrapper", + "RepeatedBytesWrapper", REQUIRED, R"({"repeatedBytesWrapper": ["", "AQI="]})", R"( repeated_bytes_wrapper: {value: ""} repeated_bytes_wrapper: {value: "\x01\x02"} )"); RunValidJsonTest( - "WrapperTypesWithNullValue", + "WrapperTypesWithNullValue", REQUIRED, R"({ "optionalBoolWrapper": null, "optionalInt32Wrapper": null, @@ -1739,55 +1759,55 @@ bool ConformanceTestSuite::RunSuite(ConformanceTestRunner* runner, // Duration RunValidJsonTest( - "DurationMinValue", + "DurationMinValue", REQUIRED, R"({"optionalDuration": "-315576000000.999999999s"})", "optional_duration: {seconds: -315576000000 nanos: -999999999}"); RunValidJsonTest( - "DurationMaxValue", + "DurationMaxValue", REQUIRED, R"({"optionalDuration": "315576000000.999999999s"})", "optional_duration: {seconds: 315576000000 nanos: 999999999}"); RunValidJsonTest( - "DurationRepeatedValue", + "DurationRepeatedValue", REQUIRED, R"({"repeatedDuration": ["1.5s", "-1.5s"]})", "repeated_duration: {seconds: 1 nanos: 500000000}" "repeated_duration: {seconds: -1 nanos: -500000000}"); ExpectParseFailureForJson( - "DurationMissingS", + "DurationMissingS", REQUIRED, R"({"optionalDuration": "1"})"); ExpectParseFailureForJson( - "DurationJsonInputTooSmall", + "DurationJsonInputTooSmall", REQUIRED, R"({"optionalDuration": "-315576000001.000000000s"})"); ExpectParseFailureForJson( - "DurationJsonInputTooLarge", + "DurationJsonInputTooLarge", REQUIRED, R"({"optionalDuration": "315576000001.000000000s"})"); ExpectSerializeFailureForJson( - "DurationProtoInputTooSmall", + "DurationProtoInputTooSmall", REQUIRED, "optional_duration: {seconds: -315576000001 nanos: 0}"); ExpectSerializeFailureForJson( - "DurationProtoInputTooLarge", + "DurationProtoInputTooLarge", REQUIRED, "optional_duration: {seconds: 315576000001 nanos: 0}"); RunValidJsonTestWithValidator( - "DurationHasZeroFractionalDigit", + "DurationHasZeroFractionalDigit", RECOMMENDED, R"({"optionalDuration": "1.000000000s"})", [](const Json::Value& value) { return value["optionalDuration"].asString() == "1s"; }); RunValidJsonTestWithValidator( - "DurationHas3FractionalDigits", + "DurationHas3FractionalDigits", RECOMMENDED, R"({"optionalDuration": "1.010000000s"})", [](const Json::Value& value) { return value["optionalDuration"].asString() == "1.010s"; }); RunValidJsonTestWithValidator( - "DurationHas6FractionalDigits", + "DurationHas6FractionalDigits", RECOMMENDED, R"({"optionalDuration": "1.000010000s"})", [](const Json::Value& value) { return value["optionalDuration"].asString() == "1.000010s"; }); RunValidJsonTestWithValidator( - "DurationHas9FractionalDigits", + "DurationHas9FractionalDigits", RECOMMENDED, R"({"optionalDuration": "1.000000010s"})", [](const Json::Value& value) { return value["optionalDuration"].asString() == "1.000000010s"; @@ -1795,15 +1815,15 @@ bool ConformanceTestSuite::RunSuite(ConformanceTestRunner* runner, // Timestamp RunValidJsonTest( - "TimestampMinValue", + "TimestampMinValue", REQUIRED, R"({"optionalTimestamp": "0001-01-01T00:00:00Z"})", "optional_timestamp: {seconds: -62135596800}"); RunValidJsonTest( - "TimestampMaxValue", + "TimestampMaxValue", REQUIRED, R"({"optionalTimestamp": "9999-12-31T23:59:59.999999999Z"})", "optional_timestamp: {seconds: 253402300799 nanos: 999999999}"); RunValidJsonTest( - "TimestampRepeatedValue", + "TimestampRepeatedValue", REQUIRED, R"({ "repeatedTimestamp": [ "0001-01-01T00:00:00Z", @@ -1813,68 +1833,68 @@ bool ConformanceTestSuite::RunSuite(ConformanceTestRunner* runner, "repeated_timestamp: {seconds: -62135596800}" "repeated_timestamp: {seconds: 253402300799 nanos: 999999999}"); RunValidJsonTest( - "TimestampWithPositiveOffset", + "TimestampWithPositiveOffset", REQUIRED, R"({"optionalTimestamp": "1970-01-01T08:00:00+08:00"})", "optional_timestamp: {seconds: 0}"); RunValidJsonTest( - "TimestampWithNegativeOffset", + "TimestampWithNegativeOffset", REQUIRED, R"({"optionalTimestamp": "1969-12-31T16:00:00-08:00"})", "optional_timestamp: {seconds: 0}"); ExpectParseFailureForJson( - "TimestampJsonInputTooSmall", + "TimestampJsonInputTooSmall", REQUIRED, R"({"optionalTimestamp": "0000-01-01T00:00:00Z"})"); ExpectParseFailureForJson( - "TimestampJsonInputTooLarge", + "TimestampJsonInputTooLarge", REQUIRED, R"({"optionalTimestamp": "10000-01-01T00:00:00Z"})"); ExpectParseFailureForJson( - "TimestampJsonInputMissingZ", + "TimestampJsonInputMissingZ", REQUIRED, R"({"optionalTimestamp": "0001-01-01T00:00:00"})"); ExpectParseFailureForJson( - "TimestampJsonInputMissingT", + "TimestampJsonInputMissingT", REQUIRED, R"({"optionalTimestamp": "0001-01-01 00:00:00Z"})"); ExpectParseFailureForJson( - "TimestampJsonInputLowercaseZ", + "TimestampJsonInputLowercaseZ", REQUIRED, R"({"optionalTimestamp": "0001-01-01T00:00:00z"})"); ExpectParseFailureForJson( - "TimestampJsonInputLowercaseT", + "TimestampJsonInputLowercaseT", REQUIRED, R"({"optionalTimestamp": "0001-01-01t00:00:00Z"})"); ExpectSerializeFailureForJson( - "TimestampProtoInputTooSmall", + "TimestampProtoInputTooSmall", REQUIRED, "optional_timestamp: {seconds: -62135596801}"); ExpectSerializeFailureForJson( - "TimestampProtoInputTooLarge", + "TimestampProtoInputTooLarge", REQUIRED, "optional_timestamp: {seconds: 253402300800}"); RunValidJsonTestWithValidator( - "TimestampZeroNormalized", + "TimestampZeroNormalized", RECOMMENDED, R"({"optionalTimestamp": "1969-12-31T16:00:00-08:00"})", [](const Json::Value& value) { return value["optionalTimestamp"].asString() == "1970-01-01T00:00:00Z"; }); RunValidJsonTestWithValidator( - "TimestampHasZeroFractionalDigit", + "TimestampHasZeroFractionalDigit", RECOMMENDED, R"({"optionalTimestamp": "1970-01-01T00:00:00.000000000Z"})", [](const Json::Value& value) { return value["optionalTimestamp"].asString() == "1970-01-01T00:00:00Z"; }); RunValidJsonTestWithValidator( - "TimestampHas3FractionalDigits", + "TimestampHas3FractionalDigits", RECOMMENDED, R"({"optionalTimestamp": "1970-01-01T00:00:00.010000000Z"})", [](const Json::Value& value) { return value["optionalTimestamp"].asString() == "1970-01-01T00:00:00.010Z"; }); RunValidJsonTestWithValidator( - "TimestampHas6FractionalDigits", + "TimestampHas6FractionalDigits", RECOMMENDED, R"({"optionalTimestamp": "1970-01-01T00:00:00.000010000Z"})", [](const Json::Value& value) { return value["optionalTimestamp"].asString() == "1970-01-01T00:00:00.000010Z"; }); RunValidJsonTestWithValidator( - "TimestampHas9FractionalDigits", + "TimestampHas9FractionalDigits", RECOMMENDED, R"({"optionalTimestamp": "1970-01-01T00:00:00.000000010Z"})", [](const Json::Value& value) { return value["optionalTimestamp"].asString() == @@ -1883,25 +1903,25 @@ bool ConformanceTestSuite::RunSuite(ConformanceTestRunner* runner, // FieldMask RunValidJsonTest( - "FieldMask", + "FieldMask", REQUIRED, R"({"optionalFieldMask": "foo,barBaz"})", R"(optional_field_mask: {paths: "foo" paths: "bar_baz"})"); ExpectParseFailureForJson( - "FieldMaskInvalidCharacter", + "FieldMaskInvalidCharacter", RECOMMENDED, R"({"optionalFieldMask": "foo,bar_bar"})"); ExpectSerializeFailureForJson( - "FieldMaskPathsDontRoundTrip", + "FieldMaskPathsDontRoundTrip", RECOMMENDED, R"(optional_field_mask: {paths: "fooBar"})"); ExpectSerializeFailureForJson( - "FieldMaskNumbersDontRoundTrip", + "FieldMaskNumbersDontRoundTrip", RECOMMENDED, R"(optional_field_mask: {paths: "foo_3_bar"})"); ExpectSerializeFailureForJson( - "FieldMaskTooManyUnderscore", + "FieldMaskTooManyUnderscore", RECOMMENDED, R"(optional_field_mask: {paths: "foo__bar"})"); // Struct RunValidJsonTest( - "Struct", + "Struct", REQUIRED, R"({ "optionalStruct": { "nullValue": null, @@ -1967,27 +1987,27 @@ bool ConformanceTestSuite::RunSuite(ConformanceTestRunner* runner, )"); // Value RunValidJsonTest( - "ValueAcceptInteger", + "ValueAcceptInteger", REQUIRED, R"({"optionalValue": 1})", "optional_value: { number_value: 1}"); RunValidJsonTest( - "ValueAcceptFloat", + "ValueAcceptFloat", REQUIRED, R"({"optionalValue": 1.5})", "optional_value: { number_value: 1.5}"); RunValidJsonTest( - "ValueAcceptBool", + "ValueAcceptBool", REQUIRED, R"({"optionalValue": false})", "optional_value: { bool_value: false}"); RunValidJsonTest( - "ValueAcceptNull", + "ValueAcceptNull", REQUIRED, R"({"optionalValue": null})", "optional_value: { null_value: NULL_VALUE}"); RunValidJsonTest( - "ValueAcceptString", + "ValueAcceptString", REQUIRED, R"({"optionalValue": "hello"})", R"(optional_value: { string_value: "hello"})"); RunValidJsonTest( - "ValueAcceptList", + "ValueAcceptList", REQUIRED, R"({"optionalValue": [0, "hello"]})", R"( optional_value: { @@ -2002,7 +2022,7 @@ bool ConformanceTestSuite::RunSuite(ConformanceTestRunner* runner, } )"); RunValidJsonTest( - "ValueAcceptObject", + "ValueAcceptObject", REQUIRED, R"({"optionalValue": {"value": 1}})", R"( optional_value: { @@ -2019,7 +2039,7 @@ bool ConformanceTestSuite::RunSuite(ConformanceTestRunner* runner, // Any RunValidJsonTest( - "Any", + "Any", REQUIRED, R"({ "optionalAny": { "@type": "type.googleapis.com/conformance.TestAllTypes", @@ -2034,7 +2054,7 @@ bool ConformanceTestSuite::RunSuite(ConformanceTestRunner* runner, } )"); RunValidJsonTest( - "AnyNested", + "AnyNested", REQUIRED, R"({ "optionalAny": { "@type": "type.googleapis.com/google.protobuf.Any", @@ -2055,7 +2075,7 @@ bool ConformanceTestSuite::RunSuite(ConformanceTestRunner* runner, )"); // The special "@type" tag is not required to appear first. RunValidJsonTest( - "AnyUnorderedTypeTag", + "AnyUnorderedTypeTag", REQUIRED, R"({ "optionalAny": { "optionalInt32": 12345, @@ -2071,7 +2091,7 @@ bool ConformanceTestSuite::RunSuite(ConformanceTestRunner* runner, )"); // Well-known types in Any. RunValidJsonTest( - "AnyWithInt32ValueWrapper", + "AnyWithInt32ValueWrapper", REQUIRED, R"({ "optionalAny": { "@type": "type.googleapis.com/google.protobuf.Int32Value", @@ -2086,7 +2106,7 @@ bool ConformanceTestSuite::RunSuite(ConformanceTestRunner* runner, } )"); RunValidJsonTest( - "AnyWithDuration", + "AnyWithDuration", REQUIRED, R"({ "optionalAny": { "@type": "type.googleapis.com/google.protobuf.Duration", @@ -2102,7 +2122,7 @@ bool ConformanceTestSuite::RunSuite(ConformanceTestRunner* runner, } )"); RunValidJsonTest( - "AnyWithTimestamp", + "AnyWithTimestamp", REQUIRED, R"({ "optionalAny": { "@type": "type.googleapis.com/google.protobuf.Timestamp", @@ -2118,7 +2138,7 @@ bool ConformanceTestSuite::RunSuite(ConformanceTestRunner* runner, } )"); RunValidJsonTest( - "AnyWithFieldMask", + "AnyWithFieldMask", REQUIRED, R"({ "optionalAny": { "@type": "type.googleapis.com/google.protobuf.FieldMask", @@ -2133,7 +2153,7 @@ bool ConformanceTestSuite::RunSuite(ConformanceTestRunner* runner, } )"); RunValidJsonTest( - "AnyWithStruct", + "AnyWithStruct", REQUIRED, R"({ "optionalAny": { "@type": "type.googleapis.com/google.protobuf.Struct", @@ -2155,7 +2175,7 @@ bool ConformanceTestSuite::RunSuite(ConformanceTestRunner* runner, } )"); RunValidJsonTest( - "AnyWithValueForJsonObject", + "AnyWithValueForJsonObject", REQUIRED, R"({ "optionalAny": { "@type": "type.googleapis.com/google.protobuf.Value", @@ -2179,7 +2199,7 @@ bool ConformanceTestSuite::RunSuite(ConformanceTestRunner* runner, } )"); RunValidJsonTest( - "AnyWithValueForInteger", + "AnyWithValueForInteger", REQUIRED, R"({ "optionalAny": { "@type": "type.googleapis.com/google.protobuf.Value", diff --git a/conformance/conformance_test.h b/conformance/conformance_test.h index 56689318..2e6fc5d7 100644 --- a/conformance/conformance_test.h +++ b/conformance/conformance_test.h @@ -91,7 +91,7 @@ class ConformanceTestRunner { // class ConformanceTestSuite { public: - ConformanceTestSuite() : verbose_(false) {} + ConformanceTestSuite() : verbose_(false), enforce_recommended_(false) {} void SetVerbose(bool verbose) { verbose_ = verbose; } @@ -104,6 +104,18 @@ class ConformanceTestSuite { void SetFailureList(const std::string& filename, const std::vector& failure_list); + // Whether to require the testee to pass RECOMMENDED tests. By default failing + // a RECOMMENDED test case will not fail the entire suite but will only + // generated a warning. If this flag is set to true, RECOMMENDED tests will + // be treated the same way as REQUIRED tests and failing a RECOMMENDED test + // case will cause the entire test suite to fail as well. An implementation + // can enable this if it wants to be strictly conforming to protobuf spec. + // See the comments about ConformanceLevel below to learn more about the + // difference between REQUIRED and RECOMMENDED test cases. + void SetEnforceRecommended(bool value) { + enforce_recommended_ = value; + } + // Run all the conformance tests against the given test runner. // Test output will be stored in "output". // @@ -113,8 +125,27 @@ class ConformanceTestSuite { bool RunSuite(ConformanceTestRunner* runner, std::string* output); private: + // Test cases are classified into a few categories: + // REQUIRED: the test case must be passed for an implementation to be + // interoperable with other implementations. For example, a + // parser implementaiton must accept both packed and unpacked + // form of repeated primitive fields. + // RECOMMENDED: the test case is not required for the implementation to + // be interoperable with other implementations, but is + // recommended for best performance and compatibility. For + // example, a proto3 serializer should serialize repeated + // primitive fields in packed form, but an implementation + // failing to do so will still be able to communicate with + // other implementations. + enum ConformanceLevel { + REQUIRED = 0, + RECOMMENDED = 1, + }; + string ConformanceLevelToString(ConformanceLevel level); + void ReportSuccess(const std::string& test_name); void ReportFailure(const string& test_name, + ConformanceLevel level, const conformance::ConformanceRequest& request, const conformance::ConformanceResponse& response, const char* fmt, ...); @@ -124,13 +155,18 @@ class ConformanceTestSuite { void RunTest(const std::string& test_name, const conformance::ConformanceRequest& request, conformance::ConformanceResponse* response); - void RunValidInputTest(const string& test_name, const string& input, + void RunValidInputTest(const string& test_name, + ConformanceLevel level, + const string& input, conformance::WireFormat input_format, const string& equivalent_text_format, conformance::WireFormat requested_output); - void RunValidJsonTest(const string& test_name, const string& input_json, + void RunValidJsonTest(const string& test_name, + ConformanceLevel level, + const string& input_json, const string& equivalent_text_format); void RunValidJsonTestWithProtobufInput(const string& test_name, + ConformanceLevel level, const conformance::TestAllTypes& input, const string& equivalent_text_format); void RunValidProtobufTest(const string& test_name, @@ -139,16 +175,21 @@ class ConformanceTestSuite { typedef std::function Validator; void RunValidJsonTestWithValidator(const string& test_name, + ConformanceLevel level, const string& input_json, const Validator& validator); void ExpectParseFailureForJson(const string& test_name, + ConformanceLevel level, const string& input_json); void ExpectSerializeFailureForJson(const string& test_name, + ConformanceLevel level, const string& text_format); void ExpectParseFailureForProto(const std::string& proto, - const std::string& test_name); + const std::string& test_name, + ConformanceLevel level); void ExpectHardParseFailureForProto(const std::string& proto, - const std::string& test_name); + const std::string& test_name, + ConformanceLevel level); void TestPrematureEOFForType(google::protobuf::FieldDescriptor::Type type); bool CheckSetEmpty(const set& set_to_check, const std::string& write_to_file, const std::string& msg); @@ -156,6 +197,7 @@ class ConformanceTestSuite { int successes_; int expected_failures_; bool verbose_; + bool enforce_recommended_; std::string output_; std::string failure_list_filename_; diff --git a/conformance/conformance_test_runner.cc b/conformance/conformance_test_runner.cc index d6b1175c..7e91d388 100644 --- a/conformance/conformance_test_runner.cc +++ b/conformance/conformance_test_runner.cc @@ -251,6 +251,16 @@ void UsageError() { " should contain one test name per\n"); fprintf(stderr, " line. Use '#' for comments.\n"); + fprintf(stderr, + " --enforce_recommended Enforce that recommended test\n"); + fprintf(stderr, + " cases are also passing. Specify\n"); + fprintf(stderr, + " this flag if you want to be\n"); + fprintf(stderr, + " strictly conforming to protobuf\n"); + fprintf(stderr, + " spec.\n"); exit(1); } @@ -290,6 +300,8 @@ int main(int argc, char *argv[]) { ParseFailureList(argv[arg], &failure_list); } else if (strcmp(argv[arg], "--verbose") == 0) { suite.SetVerbose(true); + } else if (strcmp(argv[arg], "--enforce_recommended") == 0) { + suite.SetEnforceRecommended(true); } else if (argv[arg][0] == '-') { fprintf(stderr, "Unknown option: %s\n", argv[arg]); UsageError(); diff --git a/conformance/failure_list_cpp.txt b/conformance/failure_list_cpp.txt index 5e17176e..fcaa08bd 100644 --- a/conformance/failure_list_cpp.txt +++ b/conformance/failure_list_cpp.txt @@ -7,48 +7,41 @@ # TODO(haberman): insert links to corresponding bugs tracking the issue. # Should we use GitHub issues or the Google-internal bug tracker? -FieldMaskNumbersDontRoundTrip.JsonOutput -FieldMaskPathsDontRoundTrip.JsonOutput -FieldMaskTooManyUnderscore.JsonOutput -JsonInput.AnyUnorderedTypeTag.JsonOutput -JsonInput.AnyUnorderedTypeTag.ProtobufOutput -JsonInput.BoolFieldDoubleQuotedFalse -JsonInput.BoolFieldDoubleQuotedTrue -JsonInput.BytesFieldNoPadding -JsonInput.DoubleFieldTooSmall -JsonInput.DurationHasZeroFractionalDigit.Validator -JsonInput.EnumFieldUnknownValue.Validator -JsonInput.FieldMaskInvalidCharacter -JsonInput.FieldNameDuplicate -JsonInput.FieldNameDuplicateDifferentCasing1 -JsonInput.FieldNameDuplicateDifferentCasing2 -JsonInput.FieldNameNotQuoted -JsonInput.MapFieldValueIsNull -JsonInput.RepeatedFieldMessageElementIsNull -JsonInput.RepeatedFieldPrimitiveElementIsNull -JsonInput.RepeatedFieldTrailingComma -JsonInput.RepeatedFieldTrailingCommaWithNewlines -JsonInput.RepeatedFieldTrailingCommaWithSpace -JsonInput.RepeatedFieldTrailingCommaWithSpaceCommaSpace -JsonInput.StringFieldSingleQuoteBoth -JsonInput.StringFieldSingleQuoteKey -JsonInput.StringFieldSingleQuoteValue -JsonInput.StringFieldUppercaseEscapeLetter -JsonInput.TrailingCommaInAnObject -JsonInput.TrailingCommaInAnObjectWithNewlines -JsonInput.TrailingCommaInAnObjectWithSpace -JsonInput.TrailingCommaInAnObjectWithSpaceCommaSpace -JsonInput.WrapperTypesWithNullValue.JsonOutput -JsonInput.WrapperTypesWithNullValue.ProtobufOutput -ProtobufInput.PrematureEofBeforeKnownRepeatedValue.MESSAGE -ProtobufInput.PrematureEofInDelimitedDataForKnownNonRepeatedValue.MESSAGE -ProtobufInput.PrematureEofInDelimitedDataForKnownRepeatedValue.MESSAGE -ProtobufInput.PrematureEofInPackedField.BOOL -ProtobufInput.PrematureEofInPackedField.ENUM -ProtobufInput.PrematureEofInPackedField.INT32 -ProtobufInput.PrematureEofInPackedField.INT64 -ProtobufInput.PrematureEofInPackedField.SINT32 -ProtobufInput.PrematureEofInPackedField.SINT64 -ProtobufInput.PrematureEofInPackedField.UINT32 -ProtobufInput.PrematureEofInPackedField.UINT64 -ProtobufInput.PrematureEofInsideKnownRepeatedValue.MESSAGE +Recommended.FieldMaskNumbersDontRoundTrip.JsonOutput +Recommended.FieldMaskPathsDontRoundTrip.JsonOutput +Recommended.FieldMaskTooManyUnderscore.JsonOutput +Recommended.JsonInput.BoolFieldDoubleQuotedFalse +Recommended.JsonInput.BoolFieldDoubleQuotedTrue +Recommended.JsonInput.FieldMaskInvalidCharacter +Recommended.JsonInput.FieldNameDuplicate +Recommended.JsonInput.FieldNameDuplicateDifferentCasing1 +Recommended.JsonInput.FieldNameDuplicateDifferentCasing2 +Recommended.JsonInput.FieldNameNotQuoted +Recommended.JsonInput.MapFieldValueIsNull +Recommended.JsonInput.RepeatedFieldMessageElementIsNull +Recommended.JsonInput.RepeatedFieldPrimitiveElementIsNull +Recommended.JsonInput.RepeatedFieldTrailingComma +Recommended.JsonInput.RepeatedFieldTrailingCommaWithNewlines +Recommended.JsonInput.RepeatedFieldTrailingCommaWithSpace +Recommended.JsonInput.RepeatedFieldTrailingCommaWithSpaceCommaSpace +Recommended.JsonInput.StringFieldSingleQuoteBoth +Recommended.JsonInput.StringFieldSingleQuoteKey +Recommended.JsonInput.StringFieldSingleQuoteValue +Recommended.JsonInput.StringFieldUppercaseEscapeLetter +Recommended.JsonInput.TrailingCommaInAnObject +Recommended.JsonInput.TrailingCommaInAnObjectWithNewlines +Recommended.JsonInput.TrailingCommaInAnObjectWithSpace +Recommended.JsonInput.TrailingCommaInAnObjectWithSpaceCommaSpace +Required.JsonInput.DoubleFieldTooSmall +Required.ProtobufInput.PrematureEofBeforeKnownRepeatedValue.MESSAGE +Required.ProtobufInput.PrematureEofInDelimitedDataForKnownNonRepeatedValue.MESSAGE +Required.ProtobufInput.PrematureEofInDelimitedDataForKnownRepeatedValue.MESSAGE +Required.ProtobufInput.PrematureEofInPackedField.BOOL +Required.ProtobufInput.PrematureEofInPackedField.ENUM +Required.ProtobufInput.PrematureEofInPackedField.INT32 +Required.ProtobufInput.PrematureEofInPackedField.INT64 +Required.ProtobufInput.PrematureEofInPackedField.SINT32 +Required.ProtobufInput.PrematureEofInPackedField.SINT64 +Required.ProtobufInput.PrematureEofInPackedField.UINT32 +Required.ProtobufInput.PrematureEofInPackedField.UINT64 +Required.ProtobufInput.PrematureEofInsideKnownRepeatedValue.MESSAGE diff --git a/conformance/failure_list_java.txt b/conformance/failure_list_java.txt index b2122c8b..440696db 100644 --- a/conformance/failure_list_java.txt +++ b/conformance/failure_list_java.txt @@ -4,48 +4,46 @@ # By listing them here we can keep tabs on which ones are failing and be sure # that we don't introduce regressions in other tests. -FieldMaskNumbersDontRoundTrip.JsonOutput -FieldMaskPathsDontRoundTrip.JsonOutput -FieldMaskTooManyUnderscore.JsonOutput -JsonInput.BoolFieldAllCapitalFalse -JsonInput.BoolFieldAllCapitalTrue -JsonInput.BoolFieldCamelCaseFalse -JsonInput.BoolFieldCamelCaseTrue -JsonInput.BoolFieldDoubleQuotedFalse -JsonInput.BoolFieldDoubleQuotedTrue -JsonInput.BoolMapFieldKeyNotQuoted -JsonInput.DoubleFieldInfinityNotQuoted -JsonInput.DoubleFieldNanNotQuoted -JsonInput.DoubleFieldNegativeInfinityNotQuoted -JsonInput.EnumFieldNotQuoted -JsonInput.FieldMaskInvalidCharacter -JsonInput.FieldNameDuplicate -JsonInput.FieldNameInLowerCamelCase.Validator -JsonInput.FieldNameInSnakeCase.JsonOutput -JsonInput.FieldNameInSnakeCase.ProtobufOutput -JsonInput.FieldNameNotQuoted -JsonInput.FieldNameWithDoubleUnderscores.JsonOutput -JsonInput.FieldNameWithDoubleUnderscores.ProtobufOutput -JsonInput.FieldNameWithDoubleUnderscores.Validator -JsonInput.FloatFieldInfinityNotQuoted -JsonInput.FloatFieldNanNotQuoted -JsonInput.FloatFieldNegativeInfinityNotQuoted -JsonInput.Int32FieldLeadingZero -JsonInput.Int32FieldNegativeWithLeadingZero -JsonInput.Int32FieldPlusSign -JsonInput.Int32MapFieldKeyNotQuoted -JsonInput.Int64MapFieldKeyNotQuoted -JsonInput.JsonWithComments -JsonInput.OriginalProtoFieldName.JsonOutput -JsonInput.RepeatedFieldWrongElementTypeExpectingStringsGotBool -JsonInput.RepeatedFieldWrongElementTypeExpectingStringsGotInt -JsonInput.StringFieldNotAString -JsonInput.StringFieldSingleQuoteBoth -JsonInput.StringFieldSingleQuoteKey -JsonInput.StringFieldSingleQuoteValue -JsonInput.StringFieldSurrogateInWrongOrder -JsonInput.StringFieldUnpairedHighSurrogate -JsonInput.StringFieldUnpairedLowSurrogate -JsonInput.StringFieldUppercaseEscapeLetter -JsonInput.Uint32MapFieldKeyNotQuoted -JsonInput.Uint64MapFieldKeyNotQuoted +Recommended.FieldMaskNumbersDontRoundTrip.JsonOutput +Recommended.FieldMaskPathsDontRoundTrip.JsonOutput +Recommended.FieldMaskTooManyUnderscore.JsonOutput +Recommended.JsonInput.BoolFieldAllCapitalFalse +Recommended.JsonInput.BoolFieldAllCapitalTrue +Recommended.JsonInput.BoolFieldCamelCaseFalse +Recommended.JsonInput.BoolFieldCamelCaseTrue +Recommended.JsonInput.BoolFieldDoubleQuotedFalse +Recommended.JsonInput.BoolFieldDoubleQuotedTrue +Recommended.JsonInput.BoolMapFieldKeyNotQuoted +Recommended.JsonInput.DoubleFieldInfinityNotQuoted +Recommended.JsonInput.DoubleFieldNanNotQuoted +Recommended.JsonInput.DoubleFieldNegativeInfinityNotQuoted +Recommended.JsonInput.FieldMaskInvalidCharacter +Recommended.JsonInput.FieldNameDuplicate +Recommended.JsonInput.FieldNameInLowerCamelCase.Validator +Recommended.JsonInput.FieldNameInSnakeCase.ProtobufOutput +Recommended.JsonInput.FieldNameNotQuoted +Recommended.JsonInput.FieldNameWithDoubleUnderscores.JsonOutput +Recommended.JsonInput.FieldNameWithDoubleUnderscores.ProtobufOutput +Recommended.JsonInput.FieldNameWithDoubleUnderscores.Validator +Recommended.JsonInput.FloatFieldInfinityNotQuoted +Recommended.JsonInput.FloatFieldNanNotQuoted +Recommended.JsonInput.FloatFieldNegativeInfinityNotQuoted +Recommended.JsonInput.Int32MapFieldKeyNotQuoted +Recommended.JsonInput.Int64MapFieldKeyNotQuoted +Recommended.JsonInput.JsonWithComments +Recommended.JsonInput.StringFieldSingleQuoteBoth +Recommended.JsonInput.StringFieldSingleQuoteKey +Recommended.JsonInput.StringFieldSingleQuoteValue +Recommended.JsonInput.StringFieldSurrogateInWrongOrder +Recommended.JsonInput.StringFieldUnpairedHighSurrogate +Recommended.JsonInput.StringFieldUnpairedLowSurrogate +Recommended.JsonInput.StringFieldUppercaseEscapeLetter +Recommended.JsonInput.Uint32MapFieldKeyNotQuoted +Recommended.JsonInput.Uint64MapFieldKeyNotQuoted +Required.JsonInput.EnumFieldNotQuoted +Required.JsonInput.Int32FieldLeadingZero +Required.JsonInput.Int32FieldNegativeWithLeadingZero +Required.JsonInput.Int32FieldPlusSign +Required.JsonInput.RepeatedFieldWrongElementTypeExpectingStringsGotBool +Required.JsonInput.RepeatedFieldWrongElementTypeExpectingStringsGotInt +Required.JsonInput.StringFieldNotAString diff --git a/conformance/failure_list_python.txt b/conformance/failure_list_python.txt index d38b7828..84635670 100644 --- a/conformance/failure_list_python.txt +++ b/conformance/failure_list_python.txt @@ -1,46 +1,15 @@ -DurationProtoInputTooLarge.JsonOutput -DurationProtoInputTooSmall.JsonOutput -FieldMaskNumbersDontRoundTrip.JsonOutput -FieldMaskPathsDontRoundTrip.JsonOutput -FieldMaskTooManyUnderscore.JsonOutput -JsonInput.AnyWithFieldMask.ProtobufOutput -JsonInput.BytesFieldInvalidBase64Characters -JsonInput.DoubleFieldInfinityNotQuoted -JsonInput.DoubleFieldNanNotQuoted -JsonInput.DoubleFieldNegativeInfinityNotQuoted -JsonInput.DoubleFieldTooSmall -JsonInput.DurationJsonInputTooLarge -JsonInput.DurationJsonInputTooSmall -JsonInput.DurationMissingS -JsonInput.EnumFieldNumericValueNonZero.JsonOutput -JsonInput.EnumFieldNumericValueNonZero.ProtobufOutput -JsonInput.EnumFieldNumericValueZero.JsonOutput -JsonInput.EnumFieldNumericValueZero.ProtobufOutput -JsonInput.EnumFieldUnknownValue.Validator -JsonInput.FieldMask.ProtobufOutput -JsonInput.FieldMaskInvalidCharacter -JsonInput.FloatFieldInfinityNotQuoted -JsonInput.FloatFieldNanNotQuoted -JsonInput.FloatFieldNegativeInfinityNotQuoted -JsonInput.FloatFieldTooLarge -JsonInput.FloatFieldTooSmall -JsonInput.Int32FieldExponentialFormat.JsonOutput -JsonInput.Int32FieldExponentialFormat.ProtobufOutput -JsonInput.Int32FieldFloatTrailingZero.JsonOutput -JsonInput.Int32FieldFloatTrailingZero.ProtobufOutput -JsonInput.Int32FieldMaxFloatValue.JsonOutput -JsonInput.Int32FieldMaxFloatValue.ProtobufOutput -JsonInput.Int32FieldMinFloatValue.JsonOutput -JsonInput.Int32FieldMinFloatValue.ProtobufOutput -JsonInput.OneofZeroMessage.JsonOutput -JsonInput.OneofZeroMessage.ProtobufOutput -JsonInput.OriginalProtoFieldName.JsonOutput -JsonInput.OriginalProtoFieldName.ProtobufOutput -JsonInput.RepeatedFieldWrongElementTypeExpectingIntegersGotBool -JsonInput.TimestampJsonInputLowercaseT -JsonInput.Uint32FieldMaxFloatValue.JsonOutput -JsonInput.Uint32FieldMaxFloatValue.ProtobufOutput -JsonInput.ValueAcceptNull.JsonOutput -JsonInput.ValueAcceptNull.ProtobufOutput -TimestampProtoInputTooLarge.JsonOutput -TimestampProtoInputTooSmall.JsonOutput +Recommended.JsonInput.DoubleFieldInfinityNotQuoted +Recommended.JsonInput.DoubleFieldNanNotQuoted +Recommended.JsonInput.DoubleFieldNegativeInfinityNotQuoted +Recommended.JsonInput.FloatFieldInfinityNotQuoted +Recommended.JsonInput.FloatFieldNanNotQuoted +Recommended.JsonInput.FloatFieldNegativeInfinityNotQuoted +Recommended.JsonInput.OneofZeroMessage.JsonOutput +Recommended.JsonInput.OneofZeroMessage.ProtobufOutput +Required.JsonInput.BytesFieldInvalidBase64Characters +Required.JsonInput.DoubleFieldTooSmall +Required.JsonInput.EnumFieldUnknownValue.Validator +Required.JsonInput.FloatFieldTooLarge +Required.JsonInput.FloatFieldTooSmall +Required.JsonInput.RepeatedFieldWrongElementTypeExpectingIntegersGotBool +Required.JsonInput.TimestampJsonInputLowercaseT diff --git a/conformance/failure_list_python_cpp.txt b/conformance/failure_list_python_cpp.txt index 84d9fccd..d77e2afb 100644 --- a/conformance/failure_list_python_cpp.txt +++ b/conformance/failure_list_python_cpp.txt @@ -7,65 +7,34 @@ # TODO(haberman): insert links to corresponding bugs tracking the issue. # Should we use GitHub issues or the Google-internal bug tracker? -DurationProtoInputTooLarge.JsonOutput -DurationProtoInputTooSmall.JsonOutput -FieldMaskNumbersDontRoundTrip.JsonOutput -FieldMaskPathsDontRoundTrip.JsonOutput -FieldMaskTooManyUnderscore.JsonOutput -JsonInput.AnyWithFieldMask.ProtobufOutput -JsonInput.BytesFieldInvalidBase64Characters -JsonInput.DoubleFieldInfinityNotQuoted -JsonInput.DoubleFieldNanNotQuoted -JsonInput.DoubleFieldNegativeInfinityNotQuoted -JsonInput.DoubleFieldTooSmall -JsonInput.DurationJsonInputTooLarge -JsonInput.DurationJsonInputTooSmall -JsonInput.DurationMissingS -JsonInput.EnumFieldNumericValueNonZero.JsonOutput -JsonInput.EnumFieldNumericValueNonZero.ProtobufOutput -JsonInput.EnumFieldNumericValueZero.JsonOutput -JsonInput.EnumFieldNumericValueZero.ProtobufOutput -JsonInput.EnumFieldUnknownValue.Validator -JsonInput.FieldMask.ProtobufOutput -JsonInput.FieldMaskInvalidCharacter -JsonInput.FloatFieldInfinityNotQuoted -JsonInput.FloatFieldNanNotQuoted -JsonInput.FloatFieldNegativeInfinityNotQuoted -JsonInput.FloatFieldTooLarge -JsonInput.FloatFieldTooSmall -JsonInput.Int32FieldExponentialFormat.JsonOutput -JsonInput.Int32FieldExponentialFormat.ProtobufOutput -JsonInput.Int32FieldFloatTrailingZero.JsonOutput -JsonInput.Int32FieldFloatTrailingZero.ProtobufOutput -JsonInput.Int32FieldMaxFloatValue.JsonOutput -JsonInput.Int32FieldMaxFloatValue.ProtobufOutput -JsonInput.Int32FieldMinFloatValue.JsonOutput -JsonInput.Int32FieldMinFloatValue.ProtobufOutput -JsonInput.OneofZeroMessage.JsonOutput -JsonInput.OneofZeroMessage.ProtobufOutput -JsonInput.OriginalProtoFieldName.JsonOutput -JsonInput.OriginalProtoFieldName.ProtobufOutput -JsonInput.RepeatedFieldWrongElementTypeExpectingIntegersGotBool -JsonInput.TimestampJsonInputLowercaseT -JsonInput.Uint32FieldMaxFloatValue.JsonOutput -JsonInput.Uint32FieldMaxFloatValue.ProtobufOutput -JsonInput.ValueAcceptNull.JsonOutput -JsonInput.ValueAcceptNull.ProtobufOutput -ProtobufInput.PrematureEofInDelimitedDataForKnownNonRepeatedValue.MESSAGE -ProtobufInput.PrematureEofInDelimitedDataForKnownRepeatedValue.MESSAGE -ProtobufInput.PrematureEofInPackedField.BOOL -ProtobufInput.PrematureEofInPackedField.DOUBLE -ProtobufInput.PrematureEofInPackedField.ENUM -ProtobufInput.PrematureEofInPackedField.FIXED32 -ProtobufInput.PrematureEofInPackedField.FIXED64 -ProtobufInput.PrematureEofInPackedField.FLOAT -ProtobufInput.PrematureEofInPackedField.INT32 -ProtobufInput.PrematureEofInPackedField.INT64 -ProtobufInput.PrematureEofInPackedField.SFIXED32 -ProtobufInput.PrematureEofInPackedField.SFIXED64 -ProtobufInput.PrematureEofInPackedField.SINT32 -ProtobufInput.PrematureEofInPackedField.SINT64 -ProtobufInput.PrematureEofInPackedField.UINT32 -ProtobufInput.PrematureEofInPackedField.UINT64 -TimestampProtoInputTooLarge.JsonOutput -TimestampProtoInputTooSmall.JsonOutput +Recommended.JsonInput.DoubleFieldInfinityNotQuoted +Recommended.JsonInput.DoubleFieldNanNotQuoted +Recommended.JsonInput.DoubleFieldNegativeInfinityNotQuoted +Recommended.JsonInput.FloatFieldInfinityNotQuoted +Recommended.JsonInput.FloatFieldNanNotQuoted +Recommended.JsonInput.FloatFieldNegativeInfinityNotQuoted +Recommended.JsonInput.OneofZeroMessage.JsonOutput +Recommended.JsonInput.OneofZeroMessage.ProtobufOutput +Required.JsonInput.BytesFieldInvalidBase64Characters +Required.JsonInput.DoubleFieldTooSmall +Required.JsonInput.EnumFieldUnknownValue.Validator +Required.JsonInput.FloatFieldTooLarge +Required.JsonInput.FloatFieldTooSmall +Required.JsonInput.RepeatedFieldWrongElementTypeExpectingIntegersGotBool +Required.JsonInput.TimestampJsonInputLowercaseT +Required.ProtobufInput.PrematureEofInDelimitedDataForKnownNonRepeatedValue.MESSAGE +Required.ProtobufInput.PrematureEofInDelimitedDataForKnownRepeatedValue.MESSAGE +Required.ProtobufInput.PrematureEofInPackedField.BOOL +Required.ProtobufInput.PrematureEofInPackedField.DOUBLE +Required.ProtobufInput.PrematureEofInPackedField.ENUM +Required.ProtobufInput.PrematureEofInPackedField.FIXED32 +Required.ProtobufInput.PrematureEofInPackedField.FIXED64 +Required.ProtobufInput.PrematureEofInPackedField.FLOAT +Required.ProtobufInput.PrematureEofInPackedField.INT32 +Required.ProtobufInput.PrematureEofInPackedField.INT64 +Required.ProtobufInput.PrematureEofInPackedField.SFIXED32 +Required.ProtobufInput.PrematureEofInPackedField.SFIXED64 +Required.ProtobufInput.PrematureEofInPackedField.SINT32 +Required.ProtobufInput.PrematureEofInPackedField.SINT64 +Required.ProtobufInput.PrematureEofInPackedField.UINT32 +Required.ProtobufInput.PrematureEofInPackedField.UINT64 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 3f3f9f3c..5b24976d 100644 --- a/java/core/src/main/java/com/google/protobuf/ByteString.java +++ b/java/core/src/main/java/com/google/protobuf/ByteString.java @@ -310,6 +310,18 @@ public abstract class ByteString implements Iterable, Serializable { return copyFrom(bytes, 0, bytes.length); } + /** + * Wraps the given bytes into a {@code ByteString}. Intended for internal only usage. + */ + static ByteString wrap(ByteBuffer buffer) { + if (buffer.hasArray()) { + final int offset = buffer.arrayOffset(); + return ByteString.wrap(buffer.array(), offset + buffer.position(), buffer.remaining()); + } else { + return new NioByteString(buffer); + } + } + /** * Wraps the given bytes into a {@code ByteString}. Intended for internal only * usage to force a classload of ByteString before LiteralByteString. @@ -679,6 +691,7 @@ public abstract class ByteString implements Iterable, Serializable { */ abstract void writeTo(ByteOutput byteOutput) throws IOException; + /** * Constructs a read-only {@code java.nio.ByteBuffer} whose content * is equal to the contents of this byte string. @@ -820,6 +833,7 @@ public abstract class ByteString implements Iterable, Serializable { return true; } + /** * Check equality of the substring of given length of this object starting at * zero with another {@code ByteString} substring starting at offset. diff --git a/java/core/src/main/java/com/google/protobuf/CodedInputStream.java b/java/core/src/main/java/com/google/protobuf/CodedInputStream.java index e8860651..e461fa28 100644 --- a/java/core/src/main/java/com/google/protobuf/CodedInputStream.java +++ b/java/core/src/main/java/com/google/protobuf/CodedInputStream.java @@ -30,6 +30,14 @@ package com.google.protobuf; +import static com.google.protobuf.Internal.EMPTY_BYTE_ARRAY; +import static com.google.protobuf.Internal.EMPTY_BYTE_BUFFER; +import static com.google.protobuf.Internal.UTF_8; +import static com.google.protobuf.Internal.checkNotNull; +import static com.google.protobuf.WireFormat.FIXED_32_SIZE; +import static com.google.protobuf.WireFormat.FIXED_64_SIZE; +import static com.google.protobuf.WireFormat.MAX_VARINT_SIZE; + import java.io.ByteArrayOutputStream; import java.io.IOException; import java.io.InputStream; @@ -41,51 +49,55 @@ import java.util.List; /** * Reads and decodes protocol message fields. * - * This class contains two kinds of methods: methods that read specific - * protocol message constructs and field types (e.g. {@link #readTag()} and - * {@link #readInt32()}) and methods that read low-level values (e.g. - * {@link #readRawVarint32()} and {@link #readRawBytes}). If you are reading - * encoded protocol messages, you should use the former methods, but if you are - * reading some other format of your own design, use the latter. + *

This class contains two kinds of methods: methods that read specific protocol message + * constructs and field types (e.g. {@link #readTag()} and {@link #readInt32()}) and methods that + * read low-level values (e.g. {@link #readRawVarint32()} and {@link #readRawBytes}). If you are + * reading encoded protocol messages, you should use the former methods, but if you are reading some + * other format of your own design, use the latter. * * @author kenton@google.com Kenton Varda */ -public final class CodedInputStream { - /** - * Create a new CodedInputStream wrapping the given InputStream. - */ +public abstract class CodedInputStream { + private static final int DEFAULT_BUFFER_SIZE = 4096; + private static final int DEFAULT_RECURSION_LIMIT = 100; + private static final int DEFAULT_SIZE_LIMIT = 64 << 20; // 64MB + + /** Visible for subclasses. See setRecursionLimit() */ + int recursionDepth; + + int recursionLimit = DEFAULT_RECURSION_LIMIT; + + /** Visible for subclasses. See setSizeLimit() */ + int sizeLimit = DEFAULT_SIZE_LIMIT; + + /** Create a new CodedInputStream wrapping the given InputStream. */ public static CodedInputStream newInstance(final InputStream input) { - return new CodedInputStream(input, BUFFER_SIZE); + return newInstance(input, DEFAULT_BUFFER_SIZE); } - - /** - * Create a new CodedInputStream wrapping the given InputStream. - */ + + /** Create a new CodedInputStream wrapping the given InputStream. */ static CodedInputStream newInstance(final InputStream input, int bufferSize) { - return new CodedInputStream(input, bufferSize); + if (input == null) { + // TODO(nathanmittler): Ideally we should throw here. This is done for backward compatibility. + return newInstance(EMPTY_BYTE_ARRAY); + } + return new StreamDecoder(input, bufferSize); } - /** - * Create a new CodedInputStream wrapping the given byte array. - */ + /** Create a new CodedInputStream wrapping the given byte array. */ public static CodedInputStream newInstance(final byte[] buf) { return newInstance(buf, 0, buf.length); } - /** - * Create a new CodedInputStream wrapping the given byte array slice. - */ - public static CodedInputStream newInstance(final byte[] buf, final int off, - final int len) { + /** Create a new CodedInputStream wrapping the given byte array slice. */ + public static CodedInputStream newInstance(final byte[] buf, final int off, final int len) { return newInstance(buf, off, len, false /* bufferIsImmutable */); } - - /** - * Create a new CodedInputStream wrapping the given byte array slice. - */ + + /** Create a new CodedInputStream wrapping the given byte array slice. */ static CodedInputStream newInstance( final byte[] buf, final int off, final int len, final boolean bufferIsImmutable) { - CodedInputStream result = new CodedInputStream(buf, off, len, bufferIsImmutable); + ArrayDecoder result = new ArrayDecoder(buf, off, len, bufferIsImmutable); try { // Some uses of CodedInputStream can be more efficient if they know // exactly how many bytes are available. By pushing the end point of the @@ -107,821 +119,229 @@ public final class CodedInputStream { } /** - * Create a new CodedInputStream wrapping the given ByteBuffer. The data - * starting from the ByteBuffer's current position to its limit will be read. - * The returned CodedInputStream may or may not share the underlying data - * in the ByteBuffer, therefore the ByteBuffer cannot be changed while the - * CodedInputStream is in use. - * Note that the ByteBuffer's position won't be changed by this function. - * Concurrent calls with the same ByteBuffer object are safe if no other - * thread is trying to alter the ByteBuffer's status. + * Create a new CodedInputStream wrapping the given ByteBuffer. The data starting from the + * ByteBuffer's current position to its limit will be read. The returned CodedInputStream may or + * may not share the underlying data in the ByteBuffer, therefore the ByteBuffer cannot be changed + * while the CodedInputStream is in use. Note that the ByteBuffer's position won't be changed by + * this function. Concurrent calls with the same ByteBuffer object are safe if no other thread is + * trying to alter the ByteBuffer's status. */ public static CodedInputStream newInstance(ByteBuffer buf) { + return newInstance(buf, false /* bufferIsImmutable */); + } + + /** Create a new CodedInputStream wrapping the given buffer. */ + static CodedInputStream newInstance(ByteBuffer buf, boolean bufferIsImmutable) { if (buf.hasArray()) { - return newInstance(buf.array(), buf.arrayOffset() + buf.position(), - buf.remaining()); - } else { - ByteBuffer temp = buf.duplicate(); - byte[] buffer = new byte[temp.remaining()]; - temp.get(buffer); - return newInstance(buffer); + return newInstance( + buf.array(), buf.arrayOffset() + buf.position(), buf.remaining(), bufferIsImmutable); + } + + if (buf.isDirect() && UnsafeDirectNioDecoder.isSupported()) { + return new UnsafeDirectNioDecoder(buf, bufferIsImmutable); } + + // The buffer is non-direct and does not expose the underlying array. Using the ByteBuffer API + // to access individual bytes is very slow, so just copy the buffer to an array. + // TODO(nathanmittler): Re-evaluate with Java 9 + byte[] buffer = new byte[buf.remaining()]; + buf.duplicate().get(buffer); + return newInstance(buffer, 0, buffer.length, true); } + /** Disable construction/inheritance outside of this class. */ + private CodedInputStream() {} + // ----------------------------------------------------------------- /** - * Attempt to read a field tag, returning zero if we have reached EOF. - * Protocol message parsers use this to read tags, since a protocol message - * may legally end wherever a tag occurs, and zero is not a valid tag number. + * Attempt to read a field tag, returning zero if we have reached EOF. Protocol message parsers + * use this to read tags, since a protocol message may legally end wherever a tag occurs, and zero + * is not a valid tag number. */ - public int readTag() throws IOException { - if (isAtEnd()) { - lastTag = 0; - return 0; - } - - lastTag = readRawVarint32(); - if (WireFormat.getTagFieldNumber(lastTag) == 0) { - // If we actually read zero (or any tag number corresponding to field - // number zero), that's not a valid tag. - throw InvalidProtocolBufferException.invalidTag(); - } - return lastTag; - } + public abstract int readTag() throws IOException; /** - * Verifies that the last call to readTag() returned the given tag value. - * This is used to verify that a nested group ended with the correct - * end tag. + * Verifies that the last call to readTag() returned the given tag value. This is used to verify + * that a nested group ended with the correct end tag. * - * @throws InvalidProtocolBufferException {@code value} does not match the - * last tag. + * @throws InvalidProtocolBufferException {@code value} does not match the last tag. */ - public void checkLastTagWas(final int value) - throws InvalidProtocolBufferException { - if (lastTag != value) { - throw InvalidProtocolBufferException.invalidEndTag(); - } - } + public abstract void checkLastTagWas(final int value) throws InvalidProtocolBufferException; - public int getLastTag() { - return lastTag; - } + public abstract int getLastTag(); /** * Reads and discards a single field, given its tag value. * - * @return {@code false} if the tag is an endgroup tag, in which case - * nothing is skipped. Otherwise, returns {@code true}. + * @return {@code false} if the tag is an endgroup tag, in which case nothing is skipped. + * Otherwise, returns {@code true}. */ - public boolean skipField(final int tag) throws IOException { - switch (WireFormat.getTagWireType(tag)) { - case WireFormat.WIRETYPE_VARINT: - skipRawVarint(); - return true; - case WireFormat.WIRETYPE_FIXED64: - skipRawBytes(8); - return true; - case WireFormat.WIRETYPE_LENGTH_DELIMITED: - skipRawBytes(readRawVarint32()); - return true; - case WireFormat.WIRETYPE_START_GROUP: - skipMessage(); - checkLastTagWas( - WireFormat.makeTag(WireFormat.getTagFieldNumber(tag), - WireFormat.WIRETYPE_END_GROUP)); - return true; - case WireFormat.WIRETYPE_END_GROUP: - return false; - case WireFormat.WIRETYPE_FIXED32: - skipRawBytes(4); - return true; - default: - throw InvalidProtocolBufferException.invalidWireType(); - } - } + public abstract boolean skipField(final int tag) throws IOException; /** - * Reads a single field and writes it to output in wire format, - * given its tag value. + * Reads a single field and writes it to output in wire format, given its tag value. * - * @return {@code false} if the tag is an endgroup tag, in which case - * nothing is skipped. Otherwise, returns {@code true}. - */ - public boolean skipField(final int tag, final CodedOutputStream output) - throws IOException { - switch (WireFormat.getTagWireType(tag)) { - case WireFormat.WIRETYPE_VARINT: { - long value = readInt64(); - output.writeRawVarint32(tag); - output.writeUInt64NoTag(value); - return true; - } - case WireFormat.WIRETYPE_FIXED64: { - long value = readRawLittleEndian64(); - output.writeRawVarint32(tag); - output.writeFixed64NoTag(value); - return true; - } - case WireFormat.WIRETYPE_LENGTH_DELIMITED: { - ByteString value = readBytes(); - output.writeRawVarint32(tag); - output.writeBytesNoTag(value); - return true; - } - case WireFormat.WIRETYPE_START_GROUP: { - output.writeRawVarint32(tag); - skipMessage(output); - int endtag = WireFormat.makeTag(WireFormat.getTagFieldNumber(tag), - WireFormat.WIRETYPE_END_GROUP); - checkLastTagWas(endtag); - output.writeRawVarint32(endtag); - return true; - } - case WireFormat.WIRETYPE_END_GROUP: { - return false; - } - case WireFormat.WIRETYPE_FIXED32: { - int value = readRawLittleEndian32(); - output.writeRawVarint32(tag); - output.writeFixed32NoTag(value); - return true; - } - default: - throw InvalidProtocolBufferException.invalidWireType(); - } - } - - /** - * Reads and discards an entire message. This will read either until EOF - * or until an endgroup tag, whichever comes first. + * @return {@code false} if the tag is an endgroup tag, in which case nothing is skipped. + * Otherwise, returns {@code true}. + * @deprecated use {@code UnknownFieldSet} or {@code UnknownFieldSetLite} to skip to an output + * stream. */ - public void skipMessage() throws IOException { - while (true) { - final int tag = readTag(); - if (tag == 0 || !skipField(tag)) { - return; - } - } - } + @Deprecated + public abstract boolean skipField(final int tag, final CodedOutputStream output) + throws IOException; /** - * Reads an entire message and writes it to output in wire format. - * This will read either until EOF or until an endgroup tag, + * Reads and discards an entire message. This will read either until EOF or until an endgroup tag, * whichever comes first. */ - public void skipMessage(CodedOutputStream output) throws IOException { - while (true) { - final int tag = readTag(); - if (tag == 0 || !skipField(tag, output)) { - return; - } - } - } + public abstract void skipMessage() throws IOException; /** - * Collects the bytes skipped and returns the data in a ByteBuffer. + * Reads an entire message and writes it to output in wire format. This will read either until EOF + * or until an endgroup tag, whichever comes first. */ - private class SkippedDataSink implements RefillCallback { - private int lastPos = bufferPos; - private ByteArrayOutputStream byteArrayStream; - - @Override - public void onRefill() { - if (byteArrayStream == null) { - byteArrayStream = new ByteArrayOutputStream(); - } - byteArrayStream.write(buffer, lastPos, bufferPos - lastPos); - lastPos = 0; - } - - /** - * Gets skipped data in a ByteBuffer. This method should only be - * called once. - */ - ByteBuffer getSkippedData() { - if (byteArrayStream == null) { - return ByteBuffer.wrap(buffer, lastPos, bufferPos - lastPos); - } else { - byteArrayStream.write(buffer, lastPos, bufferPos); - return ByteBuffer.wrap(byteArrayStream.toByteArray()); - } - } - } + public abstract void skipMessage(CodedOutputStream output) throws IOException; // ----------------------------------------------------------------- /** Read a {@code double} field value from the stream. */ - public double readDouble() throws IOException { - return Double.longBitsToDouble(readRawLittleEndian64()); - } + public abstract double readDouble() throws IOException; /** Read a {@code float} field value from the stream. */ - public float readFloat() throws IOException { - return Float.intBitsToFloat(readRawLittleEndian32()); - } + public abstract float readFloat() throws IOException; /** Read a {@code uint64} field value from the stream. */ - public long readUInt64() throws IOException { - return readRawVarint64(); - } + public abstract long readUInt64() throws IOException; /** Read an {@code int64} field value from the stream. */ - public long readInt64() throws IOException { - return readRawVarint64(); - } + public abstract long readInt64() throws IOException; /** Read an {@code int32} field value from the stream. */ - public int readInt32() throws IOException { - return readRawVarint32(); - } + public abstract int readInt32() throws IOException; /** Read a {@code fixed64} field value from the stream. */ - public long readFixed64() throws IOException { - return readRawLittleEndian64(); - } + public abstract long readFixed64() throws IOException; /** Read a {@code fixed32} field value from the stream. */ - public int readFixed32() throws IOException { - return readRawLittleEndian32(); - } + public abstract int readFixed32() throws IOException; /** Read a {@code bool} field value from the stream. */ - public boolean readBool() throws IOException { - return readRawVarint64() != 0; - } + public abstract boolean readBool() throws IOException; /** - * Read a {@code string} field value from the stream. - * If the stream contains malformed UTF-8, + * Read a {@code string} field value from the stream. If the stream contains malformed UTF-8, * replace the offending bytes with the standard UTF-8 replacement character. */ - public String readString() throws IOException { - final int size = readRawVarint32(); - if (size <= (bufferSize - bufferPos) && size > 0) { - // Fast path: We already have the bytes in a contiguous buffer, so - // just copy directly from it. - final String result = new String(buffer, bufferPos, size, Internal.UTF_8); - bufferPos += size; - return result; - } else if (size == 0) { - return ""; - } else if (size <= bufferSize) { - refillBuffer(size); - String result = new String(buffer, bufferPos, size, Internal.UTF_8); - bufferPos += size; - return result; - } else { - // Slow path: Build a byte array first then copy it. - return new String(readRawBytesSlowPath(size), Internal.UTF_8); - } - } + public abstract String readString() throws IOException; /** - * Read a {@code string} field value from the stream. - * If the stream contains malformed UTF-8, + * Read a {@code string} field value from the stream. If the stream contains malformed UTF-8, * throw exception {@link InvalidProtocolBufferException}. */ - public String readStringRequireUtf8() throws IOException { - final int size = readRawVarint32(); - final byte[] bytes; - final int oldPos = bufferPos; - final int pos; - if (size <= (bufferSize - oldPos) && size > 0) { - // Fast path: We already have the bytes in a contiguous buffer, so - // just copy directly from it. - bytes = buffer; - bufferPos = oldPos + size; - pos = oldPos; - } else if (size == 0) { - return ""; - } else if (size <= bufferSize) { - refillBuffer(size); - bytes = buffer; - pos = 0; - bufferPos = pos + size; - } else { - // Slow path: Build a byte array first then copy it. - bytes = readRawBytesSlowPath(size); - pos = 0; - } - // TODO(martinrb): We could save a pass by validating while decoding. - if (!Utf8.isValidUtf8(bytes, pos, pos + size)) { - throw InvalidProtocolBufferException.invalidUtf8(); - } - return new String(bytes, pos, size, Internal.UTF_8); - } + public abstract String readStringRequireUtf8() throws IOException; /** Read a {@code group} field value from the stream. */ - public void readGroup(final int fieldNumber, - final MessageLite.Builder builder, - final ExtensionRegistryLite extensionRegistry) - throws IOException { - if (recursionDepth >= recursionLimit) { - throw InvalidProtocolBufferException.recursionLimitExceeded(); - } - ++recursionDepth; - builder.mergeFrom(this, extensionRegistry); - checkLastTagWas( - WireFormat.makeTag(fieldNumber, WireFormat.WIRETYPE_END_GROUP)); - --recursionDepth; - } + public abstract void readGroup( + final int fieldNumber, + final MessageLite.Builder builder, + final ExtensionRegistryLite extensionRegistry) + throws IOException; /** Read a {@code group} field value from the stream. */ - public T readGroup( - final int fieldNumber, - final Parser parser, - final ExtensionRegistryLite extensionRegistry) - throws IOException { - if (recursionDepth >= recursionLimit) { - throw InvalidProtocolBufferException.recursionLimitExceeded(); - } - ++recursionDepth; - T result = parser.parsePartialFrom(this, extensionRegistry); - checkLastTagWas( - WireFormat.makeTag(fieldNumber, WireFormat.WIRETYPE_END_GROUP)); - --recursionDepth; - return result; - } + public abstract T readGroup( + final int fieldNumber, final Parser parser, final ExtensionRegistryLite extensionRegistry) + throws IOException; /** - * Reads a {@code group} field value from the stream and merges it into the - * given {@link UnknownFieldSet}. + * Reads a {@code group} field value from the stream and merges it into the given {@link + * UnknownFieldSet}. * - * @deprecated UnknownFieldSet.Builder now implements MessageLite.Builder, so - * you can just call {@link #readGroup}. + * @deprecated UnknownFieldSet.Builder now implements MessageLite.Builder, so you can just call + * {@link #readGroup}. */ @Deprecated - public void readUnknownGroup(final int fieldNumber, - final MessageLite.Builder builder) - throws IOException { - // We know that UnknownFieldSet will ignore any ExtensionRegistry so it - // is safe to pass null here. (We can't call - // ExtensionRegistry.getEmptyRegistry() because that would make this - // class depend on ExtensionRegistry, which is not part of the lite - // library.) - readGroup(fieldNumber, builder, null); - } + public abstract void readUnknownGroup(final int fieldNumber, final MessageLite.Builder builder) + throws IOException; /** Read an embedded message field value from the stream. */ - public void readMessage(final MessageLite.Builder builder, - final ExtensionRegistryLite extensionRegistry) - throws IOException { - final int length = readRawVarint32(); - if (recursionDepth >= recursionLimit) { - throw InvalidProtocolBufferException.recursionLimitExceeded(); - } - final int oldLimit = pushLimit(length); - ++recursionDepth; - builder.mergeFrom(this, extensionRegistry); - checkLastTagWas(0); - --recursionDepth; - popLimit(oldLimit); - } + public abstract void readMessage( + final MessageLite.Builder builder, final ExtensionRegistryLite extensionRegistry) + throws IOException; /** Read an embedded message field value from the stream. */ - public T readMessage( - final Parser parser, - final ExtensionRegistryLite extensionRegistry) - throws IOException { - int length = readRawVarint32(); - if (recursionDepth >= recursionLimit) { - throw InvalidProtocolBufferException.recursionLimitExceeded(); - } - final int oldLimit = pushLimit(length); - ++recursionDepth; - T result = parser.parsePartialFrom(this, extensionRegistry); - checkLastTagWas(0); - --recursionDepth; - popLimit(oldLimit); - return result; - } + public abstract T readMessage( + final Parser parser, final ExtensionRegistryLite extensionRegistry) throws IOException; /** Read a {@code bytes} field value from the stream. */ - public ByteString readBytes() throws IOException { - final int size = readRawVarint32(); - if (size <= (bufferSize - bufferPos) && size > 0) { - // Fast path: We already have the bytes in a contiguous buffer, so - // just copy directly from it. - final ByteString result = bufferIsImmutable && enableAliasing - ? ByteString.wrap(buffer, bufferPos, size) - : ByteString.copyFrom(buffer, bufferPos, size); - bufferPos += size; - return result; - } else if (size == 0) { - return ByteString.EMPTY; - } else { - // Slow path: Build a byte array first then copy it. - return ByteString.wrap(readRawBytesSlowPath(size)); - } - } + public abstract ByteString readBytes() throws IOException; /** Read a {@code bytes} field value from the stream. */ - public byte[] readByteArray() throws IOException { - final int size = readRawVarint32(); - if (size <= (bufferSize - bufferPos) && size > 0) { - // Fast path: We already have the bytes in a contiguous buffer, so - // just copy directly from it. - final byte[] result = - Arrays.copyOfRange(buffer, bufferPos, bufferPos + size); - bufferPos += size; - return result; - } else { - // Slow path: Build a byte array first then copy it. - return readRawBytesSlowPath(size); - } - } + public abstract byte[] readByteArray() throws IOException; /** Read a {@code bytes} field value from the stream. */ - public ByteBuffer readByteBuffer() throws IOException { - final int size = readRawVarint32(); - if (size <= (bufferSize - bufferPos) && size > 0) { - // Fast path: We already have the bytes in a contiguous buffer. - // When aliasing is enabled, we can return a ByteBuffer pointing directly - // into the underlying byte array without copy if the CodedInputStream is - // constructed from a byte array. If aliasing is disabled or the input is - // from an InputStream or ByteString, we have to make a copy of the bytes. - ByteBuffer result = input == null && !bufferIsImmutable && enableAliasing - ? ByteBuffer.wrap(buffer, bufferPos, size).slice() - : ByteBuffer.wrap(Arrays.copyOfRange( - buffer, bufferPos, bufferPos + size)); - bufferPos += size; - return result; - } else if (size == 0) { - return Internal.EMPTY_BYTE_BUFFER; - } else { - // Slow path: Build a byte array first then copy it. - return ByteBuffer.wrap(readRawBytesSlowPath(size)); - } - } + public abstract ByteBuffer readByteBuffer() throws IOException; /** Read a {@code uint32} field value from the stream. */ - public int readUInt32() throws IOException { - return readRawVarint32(); - } + public abstract int readUInt32() throws IOException; /** - * Read an enum field value from the stream. Caller is responsible - * for converting the numeric value to an actual enum. + * Read an enum field value from the stream. Caller is responsible for converting the numeric + * value to an actual enum. */ - public int readEnum() throws IOException { - return readRawVarint32(); - } + public abstract int readEnum() throws IOException; /** Read an {@code sfixed32} field value from the stream. */ - public int readSFixed32() throws IOException { - return readRawLittleEndian32(); - } + public abstract int readSFixed32() throws IOException; /** Read an {@code sfixed64} field value from the stream. */ - public long readSFixed64() throws IOException { - return readRawLittleEndian64(); - } + public abstract long readSFixed64() throws IOException; /** Read an {@code sint32} field value from the stream. */ - public int readSInt32() throws IOException { - return decodeZigZag32(readRawVarint32()); - } + public abstract int readSInt32() throws IOException; /** Read an {@code sint64} field value from the stream. */ - public long readSInt64() throws IOException { - return decodeZigZag64(readRawVarint64()); - } + public abstract long readSInt64() throws IOException; // ================================================================= - /** - * Read a raw Varint from the stream. If larger than 32 bits, discard the - * upper bits. - */ - public int readRawVarint32() throws IOException { - // See implementation notes for readRawVarint64 - fastpath: { - int pos = bufferPos; - - if (bufferSize == pos) { - break fastpath; - } - - final byte[] buffer = this.buffer; - int x; - if ((x = buffer[pos++]) >= 0) { - bufferPos = pos; - return x; - } else if (bufferSize - pos < 9) { - break fastpath; - } else if ((x ^= (buffer[pos++] << 7)) < 0) { - x ^= (~0 << 7); - } else if ((x ^= (buffer[pos++] << 14)) >= 0) { - x ^= (~0 << 7) ^ (~0 << 14); - } else if ((x ^= (buffer[pos++] << 21)) < 0) { - x ^= (~0 << 7) ^ (~0 << 14) ^ (~0 << 21); - } else { - int y = buffer[pos++]; - x ^= y << 28; - x ^= (~0 << 7) ^ (~0 << 14) ^ (~0 << 21) ^ (~0 << 28); - if (y < 0 && - buffer[pos++] < 0 && - buffer[pos++] < 0 && - buffer[pos++] < 0 && - buffer[pos++] < 0 && - buffer[pos++] < 0) { - break fastpath; // Will throw malformedVarint() - } - } - bufferPos = pos; - return x; - } - return (int) readRawVarint64SlowPath(); - } - - private void skipRawVarint() throws IOException { - if (bufferSize - bufferPos >= 10) { - final byte[] buffer = this.buffer; - int pos = bufferPos; - for (int i = 0; i < 10; i++) { - if (buffer[pos++] >= 0) { - bufferPos = pos; - return; - } - } - } - skipRawVarintSlowPath(); - } - - private void skipRawVarintSlowPath() throws IOException { - for (int i = 0; i < 10; i++) { - if (readRawByte() >= 0) { - return; - } - } - throw InvalidProtocolBufferException.malformedVarint(); - } - - /** - * Reads a varint from the input one byte at a time, so that it does not - * read any bytes after the end of the varint. If you simply wrapped the - * stream in a CodedInputStream and used {@link #readRawVarint32(InputStream)} - * then you would probably end up reading past the end of the varint since - * CodedInputStream buffers its input. - */ - static int readRawVarint32(final InputStream input) throws IOException { - final int firstByte = input.read(); - if (firstByte == -1) { - throw InvalidProtocolBufferException.truncatedMessage(); - } - return readRawVarint32(firstByte, input); - } - - /** - * Like {@link #readRawVarint32(InputStream)}, but expects that the caller - * has already read one byte. This allows the caller to determine if EOF - * has been reached before attempting to read. - */ - public static int readRawVarint32( - final int firstByte, final InputStream input) throws IOException { - if ((firstByte & 0x80) == 0) { - return firstByte; - } - - int result = firstByte & 0x7f; - int offset = 7; - for (; offset < 32; offset += 7) { - final int b = input.read(); - if (b == -1) { - throw InvalidProtocolBufferException.truncatedMessage(); - } - result |= (b & 0x7f) << offset; - if ((b & 0x80) == 0) { - return result; - } - } - // Keep reading up to 64 bits. - for (; offset < 64; offset += 7) { - final int b = input.read(); - if (b == -1) { - throw InvalidProtocolBufferException.truncatedMessage(); - } - if ((b & 0x80) == 0) { - return result; - } - } - throw InvalidProtocolBufferException.malformedVarint(); - } + /** Read a raw Varint from the stream. If larger than 32 bits, discard the upper bits. */ + public abstract int readRawVarint32() throws IOException; /** Read a raw Varint from the stream. */ - public long readRawVarint64() throws IOException { - // Implementation notes: - // - // Optimized for one-byte values, expected to be common. - // The particular code below was selected from various candidates - // empirically, by winning VarintBenchmark. - // - // Sign extension of (signed) Java bytes is usually a nuisance, but - // we exploit it here to more easily obtain the sign of bytes read. - // Instead of cleaning up the sign extension bits by masking eagerly, - // we delay until we find the final (positive) byte, when we clear all - // accumulated bits with one xor. We depend on javac to constant fold. - fastpath: { - int pos = bufferPos; - - if (bufferSize == pos) { - break fastpath; - } - - final byte[] buffer = this.buffer; - long x; - int y; - if ((y = buffer[pos++]) >= 0) { - bufferPos = pos; - return y; - } else if (bufferSize - pos < 9) { - break fastpath; - } else if ((y ^= (buffer[pos++] << 7)) < 0) { - x = y ^ (~0 << 7); - } else if ((y ^= (buffer[pos++] << 14)) >= 0) { - x = y ^ ((~0 << 7) ^ (~0 << 14)); - } else if ((y ^= (buffer[pos++] << 21)) < 0) { - x = y ^ ((~0 << 7) ^ (~0 << 14) ^ (~0 << 21)); - } else if ((x = ((long) y) ^ ((long) buffer[pos++] << 28)) >= 0L) { - x ^= (~0L << 7) ^ (~0L << 14) ^ (~0L << 21) ^ (~0L << 28); - } else if ((x ^= ((long) buffer[pos++] << 35)) < 0L) { - x ^= (~0L << 7) ^ (~0L << 14) ^ (~0L << 21) ^ (~0L << 28) ^ (~0L << 35); - } else if ((x ^= ((long) buffer[pos++] << 42)) >= 0L) { - x ^= (~0L << 7) ^ (~0L << 14) ^ (~0L << 21) ^ (~0L << 28) ^ (~0L << 35) ^ (~0L << 42); - } else if ((x ^= ((long) buffer[pos++] << 49)) < 0L) { - x ^= (~0L << 7) ^ (~0L << 14) ^ (~0L << 21) ^ (~0L << 28) ^ (~0L << 35) ^ (~0L << 42) - ^ (~0L << 49); - } else { - x ^= ((long) buffer[pos++] << 56); - x ^= (~0L << 7) ^ (~0L << 14) ^ (~0L << 21) ^ (~0L << 28) ^ (~0L << 35) ^ (~0L << 42) - ^ (~0L << 49) ^ (~0L << 56); - if (x < 0L) { - if (buffer[pos++] < 0L) { - break fastpath; // Will throw malformedVarint() - } - } - } - bufferPos = pos; - return x; - } - return readRawVarint64SlowPath(); - } + public abstract long readRawVarint64() throws IOException; /** Variant of readRawVarint64 for when uncomfortably close to the limit. */ /* Visible for testing */ - long readRawVarint64SlowPath() throws IOException { - long result = 0; - for (int shift = 0; shift < 64; shift += 7) { - final byte b = readRawByte(); - result |= (long) (b & 0x7F) << shift; - if ((b & 0x80) == 0) { - return result; - } - } - throw InvalidProtocolBufferException.malformedVarint(); - } + abstract long readRawVarint64SlowPath() throws IOException; /** Read a 32-bit little-endian integer from the stream. */ - public int readRawLittleEndian32() throws IOException { - int pos = bufferPos; - - // hand-inlined ensureAvailable(4); - if (bufferSize - pos < 4) { - refillBuffer(4); - pos = bufferPos; - } - - final byte[] buffer = this.buffer; - bufferPos = pos + 4; - return (((buffer[pos] & 0xff)) | - ((buffer[pos + 1] & 0xff) << 8) | - ((buffer[pos + 2] & 0xff) << 16) | - ((buffer[pos + 3] & 0xff) << 24)); - } + public abstract int readRawLittleEndian32() throws IOException; /** Read a 64-bit little-endian integer from the stream. */ - public long readRawLittleEndian64() throws IOException { - int pos = bufferPos; - - // hand-inlined ensureAvailable(8); - if (bufferSize - pos < 8) { - refillBuffer(8); - pos = bufferPos; - } - - final byte[] buffer = this.buffer; - bufferPos = pos + 8; - return ((((long) buffer[pos] & 0xffL)) | - (((long) buffer[pos + 1] & 0xffL) << 8) | - (((long) buffer[pos + 2] & 0xffL) << 16) | - (((long) buffer[pos + 3] & 0xffL) << 24) | - (((long) buffer[pos + 4] & 0xffL) << 32) | - (((long) buffer[pos + 5] & 0xffL) << 40) | - (((long) buffer[pos + 6] & 0xffL) << 48) | - (((long) buffer[pos + 7] & 0xffL) << 56)); - } - - /** - * Decode a ZigZag-encoded 32-bit value. ZigZag encodes signed integers - * into values that can be efficiently encoded with varint. (Otherwise, - * negative values must be sign-extended to 64 bits to be varint encoded, - * thus always taking 10 bytes on the wire.) - * - * @param n An unsigned 32-bit integer, stored in a signed int because - * Java has no explicit unsigned support. - * @return A signed 32-bit integer. - */ - public static int decodeZigZag32(final int n) { - return (n >>> 1) ^ -(n & 1); - } - - /** - * Decode a ZigZag-encoded 64-bit value. ZigZag encodes signed integers - * into values that can be efficiently encoded with varint. (Otherwise, - * negative values must be sign-extended to 64 bits to be varint encoded, - * thus always taking 10 bytes on the wire.) - * - * @param n An unsigned 64-bit integer, stored in a signed int because - * Java has no explicit unsigned support. - * @return A signed 64-bit integer. - */ - public static long decodeZigZag64(final long n) { - return (n >>> 1) ^ -(n & 1); - } + public abstract long readRawLittleEndian64() throws IOException; // ----------------------------------------------------------------- - private final byte[] buffer; - private final boolean bufferIsImmutable; - private int bufferSize; - private int bufferSizeAfterLimit; - private int bufferPos; - private final InputStream input; - private int lastTag; - private boolean enableAliasing = false; - /** - * The total number of bytes read before the current buffer. The total - * bytes read up to the current position can be computed as - * {@code totalBytesRetired + bufferPos}. This value may be negative if - * reading started in the middle of the current buffer (e.g. if the - * constructor that takes a byte array and an offset was used). + * Enables {@link ByteString} aliasing of the underlying buffer, trading off on buffer pinning for + * data copies. Only valid for buffer-backed streams. */ - private int totalBytesRetired; - - /** The absolute position of the end of the current message. */ - private int currentLimit = Integer.MAX_VALUE; - - /** See setRecursionLimit() */ - private int recursionDepth; - private int recursionLimit = DEFAULT_RECURSION_LIMIT; - - /** See setSizeLimit() */ - private int sizeLimit = DEFAULT_SIZE_LIMIT; - - private static final int DEFAULT_RECURSION_LIMIT = 100; - private static final int DEFAULT_SIZE_LIMIT = 64 << 20; // 64MB - private static final int BUFFER_SIZE = 4096; - - private CodedInputStream( - final byte[] buffer, final int off, final int len, boolean bufferIsImmutable) { - this.buffer = buffer; - bufferSize = off + len; - bufferPos = off; - totalBytesRetired = -off; - input = null; - this.bufferIsImmutable = bufferIsImmutable; - } - - private CodedInputStream(final InputStream input, int bufferSize) { - buffer = new byte[bufferSize]; - bufferSize = 0; - bufferPos = 0; - totalBytesRetired = 0; - this.input = input; - bufferIsImmutable = false; - } - - public void enableAliasing(boolean enabled) { - this.enableAliasing = enabled; - } + public abstract void enableAliasing(boolean enabled); /** - * Set the maximum message recursion depth. In order to prevent malicious - * messages from causing stack overflows, {@code CodedInputStream} limits - * how deeply messages may be nested. The default limit is 64. + * Set the maximum message recursion depth. In order to prevent malicious messages from causing + * stack overflows, {@code CodedInputStream} limits how deeply messages may be nested. The default + * limit is 64. * * @return the old limit. */ - public int setRecursionLimit(final int limit) { + public final int setRecursionLimit(final int limit) { if (limit < 0) { - throw new IllegalArgumentException( - "Recursion limit cannot be negative: " + limit); + throw new IllegalArgumentException("Recursion limit cannot be negative: " + limit); } final int oldLimit = recursionLimit; recursionLimit = limit; @@ -929,25 +349,22 @@ public final class CodedInputStream { } /** - * Set the maximum message size. In order to prevent malicious - * messages from exhausting memory or causing integer overflows, - * {@code CodedInputStream} limits how large a message may be. - * The default limit is 64MB. You should set this limit as small - * as you can without harming your app's functionality. Note that - * size limits only apply when reading from an {@code InputStream}, not - * when constructed around a raw byte array (nor with - * {@link ByteString#newCodedInput}). - *

- * If you want to read several messages from a single CodedInputStream, you - * could call {@link #resetSizeCounter()} after each one to avoid hitting the - * size limit. + * Only valid for {@link InputStream}-backed streams. + * + *

Set the maximum message size. In order to prevent malicious messages from exhausting memory + * or causing integer overflows, {@code CodedInputStream} limits how large a message may be. The + * default limit is 64MB. You should set this limit as small as you can without harming your app's + * functionality. Note that size limits only apply when reading from an {@code InputStream}, not + * when constructed around a raw byte array (nor with {@link ByteString#newCodedInput}). + * + *

If you want to read several messages from a single CodedInputStream, you could call {@link + * #resetSizeCounter()} after each one to avoid hitting the size limit. * * @return the old limit. */ - public int setSizeLimit(final int limit) { + public final int setSizeLimit(final int limit) { if (limit < 0) { - throw new IllegalArgumentException( - "Size limit cannot be negative: " + limit); + throw new IllegalArgumentException("Size limit cannot be negative: " + limit); } final int oldLimit = sizeLimit; sizeLimit = limit; @@ -955,348 +372,2524 @@ public final class CodedInputStream { } /** - * Resets the current size counter to zero (see {@link #setSizeLimit(int)}). + * Resets the current size counter to zero (see {@link #setSizeLimit(int)}). Only valid for {@link + * InputStream}-backed streams. */ - public void resetSizeCounter() { - totalBytesRetired = -bufferPos; - } + public abstract void resetSizeCounter(); /** - * Sets {@code currentLimit} to (current position) + {@code byteLimit}. This - * is called when descending into a length-delimited embedded message. + * Sets {@code currentLimit} to (current position) + {@code byteLimit}. This is called when + * descending into a length-delimited embedded message. * - *

Note that {@code pushLimit()} does NOT affect how many bytes the - * {@code CodedInputStream} reads from an underlying {@code InputStream} when - * refreshing its buffer. If you need to prevent reading past a certain - * point in the underlying {@code InputStream} (e.g. because you expect it to - * contain more data after the end of the message which you need to handle - * differently) then you must place a wrapper around your {@code InputStream} - * which limits the amount of data that can be read from it. + *

Note that {@code pushLimit()} does NOT affect how many bytes the {@code CodedInputStream} + * reads from an underlying {@code InputStream} when refreshing its buffer. If you need to prevent + * reading past a certain point in the underlying {@code InputStream} (e.g. because you expect it + * to contain more data after the end of the message which you need to handle differently) then + * you must place a wrapper around your {@code InputStream} which limits the amount of data that + * can be read from it. * * @return the old limit. */ - public int pushLimit(int byteLimit) throws InvalidProtocolBufferException { - if (byteLimit < 0) { - throw InvalidProtocolBufferException.negativeSize(); - } - byteLimit += totalBytesRetired + bufferPos; - final int oldLimit = currentLimit; - if (byteLimit > oldLimit) { - throw InvalidProtocolBufferException.truncatedMessage(); - } - currentLimit = byteLimit; - - recomputeBufferSizeAfterLimit(); - - return oldLimit; - } - - private void recomputeBufferSizeAfterLimit() { - bufferSize += bufferSizeAfterLimit; - final int bufferEnd = totalBytesRetired + bufferSize; - if (bufferEnd > currentLimit) { - // Limit is in current buffer. - bufferSizeAfterLimit = bufferEnd - currentLimit; - bufferSize -= bufferSizeAfterLimit; - } else { - bufferSizeAfterLimit = 0; - } - } + public abstract int pushLimit(int byteLimit) throws InvalidProtocolBufferException; /** * Discards the current limit, returning to the previous limit. * * @param oldLimit The old limit, as returned by {@code pushLimit}. */ - public void popLimit(final int oldLimit) { - currentLimit = oldLimit; - recomputeBufferSizeAfterLimit(); - } + public abstract void popLimit(final int oldLimit); /** - * Returns the number of bytes to be read before the current limit. - * If no limit is set, returns -1. + * Returns the number of bytes to be read before the current limit. If no limit is set, returns + * -1. */ - public int getBytesUntilLimit() { - if (currentLimit == Integer.MAX_VALUE) { - return -1; - } - - final int currentAbsolutePosition = totalBytesRetired + bufferPos; - return currentLimit - currentAbsolutePosition; - } + public abstract int getBytesUntilLimit(); /** - * Returns true if the stream has reached the end of the input. This is the - * case if either the end of the underlying input source has been reached or - * if the stream has reached a limit created using {@link #pushLimit(int)}. + * Returns true if the stream has reached the end of the input. This is the case if either the end + * of the underlying input source has been reached or if the stream has reached a limit created + * using {@link #pushLimit(int)}. */ - public boolean isAtEnd() throws IOException { - return bufferPos == bufferSize && !tryRefillBuffer(1); - } + public abstract boolean isAtEnd() throws IOException; /** - * The total bytes read up to the current position. Calling - * {@link #resetSizeCounter()} resets this value to zero. + * The total bytes read up to the current position. Calling {@link #resetSizeCounter()} resets + * this value to zero. */ - public int getTotalBytesRead() { - return totalBytesRetired + bufferPos; - } + public abstract int getTotalBytesRead(); - private interface RefillCallback { - void onRefill(); - } + /** + * Read one byte from the input. + * + * @throws InvalidProtocolBufferException The end of the stream or the current limit was reached. + */ + public abstract byte readRawByte() throws IOException; - private RefillCallback refillCallback = null; + /** + * Read a fixed size of bytes from the input. + * + * @throws InvalidProtocolBufferException The end of the stream or the current limit was reached. + */ + public abstract byte[] readRawBytes(final int size) throws IOException; /** - * Reads more bytes from the input, making at least {@code n} bytes available - * in the buffer. Caller must ensure that the requested space is not yet - * available, and that the requested space is less than BUFFER_SIZE. + * Reads and discards {@code size} bytes. * - * @throws InvalidProtocolBufferException The end of the stream or the current - * limit was reached. + * @throws InvalidProtocolBufferException The end of the stream or the current limit was reached. */ - private void refillBuffer(int n) throws IOException { - if (!tryRefillBuffer(n)) { - throw InvalidProtocolBufferException.truncatedMessage(); - } + public abstract void skipRawBytes(final int size) throws IOException; + + /** + * Decode a ZigZag-encoded 32-bit value. ZigZag encodes signed integers into values that can be + * efficiently encoded with varint. (Otherwise, negative values must be sign-extended to 64 bits + * to be varint encoded, thus always taking 10 bytes on the wire.) + * + * @param n An unsigned 32-bit integer, stored in a signed int because Java has no explicit + * unsigned support. + * @return A signed 32-bit integer. + */ + public static int decodeZigZag32(final int n) { + return (n >>> 1) ^ -(n & 1); } /** - * Tries to read more bytes from the input, making at least {@code n} bytes - * available in the buffer. Caller must ensure that the requested space is - * not yet available, and that the requested space is less than BUFFER_SIZE. + * Decode a ZigZag-encoded 64-bit value. ZigZag encodes signed integers into values that can be + * efficiently encoded with varint. (Otherwise, negative values must be sign-extended to 64 bits + * to be varint encoded, thus always taking 10 bytes on the wire.) * - * @return {@code true} if the bytes could be made available; {@code false} - * if the end of the stream or the current limit was reached. + * @param n An unsigned 64-bit integer, stored in a signed int because Java has no explicit + * unsigned support. + * @return A signed 64-bit integer. + */ + public static long decodeZigZag64(final long n) { + return (n >>> 1) ^ -(n & 1); + } + + /** + * Like {@link #readRawVarint32(InputStream)}, but expects that the caller has already read one + * byte. This allows the caller to determine if EOF has been reached before attempting to read. */ - private boolean tryRefillBuffer(int n) throws IOException { - if (bufferPos + n <= bufferSize) { - throw new IllegalStateException( - "refillBuffer() called when " + n + - " bytes were already available in buffer"); + public static int readRawVarint32(final int firstByte, final InputStream input) + throws IOException { + if ((firstByte & 0x80) == 0) { + return firstByte; } - if (totalBytesRetired + bufferPos + n > currentLimit) { - // Oops, we hit a limit. - return false; + int result = firstByte & 0x7f; + int offset = 7; + for (; offset < 32; offset += 7) { + final int b = input.read(); + if (b == -1) { + throw InvalidProtocolBufferException.truncatedMessage(); + } + result |= (b & 0x7f) << offset; + if ((b & 0x80) == 0) { + return result; + } + } + // Keep reading up to 64 bits. + for (; offset < 64; offset += 7) { + final int b = input.read(); + if (b == -1) { + throw InvalidProtocolBufferException.truncatedMessage(); + } + if ((b & 0x80) == 0) { + return result; + } + } + throw InvalidProtocolBufferException.malformedVarint(); + } + + /** + * Reads a varint from the input one byte at a time, so that it does not read any bytes after the + * end of the varint. If you simply wrapped the stream in a CodedInputStream and used {@link + * #readRawVarint32(InputStream)} then you would probably end up reading past the end of the + * varint since CodedInputStream buffers its input. + */ + static int readRawVarint32(final InputStream input) throws IOException { + final int firstByte = input.read(); + if (firstByte == -1) { + throw InvalidProtocolBufferException.truncatedMessage(); } + return readRawVarint32(firstByte, input); + } - if (refillCallback != null) { - refillCallback.onRefill(); + /** A {@link CodedInputStream} implementation that uses a backing array as the input. */ + private static final class ArrayDecoder extends CodedInputStream { + private final byte[] buffer; + private final boolean immutable; + private int limit; + private int bufferSizeAfterLimit; + private int pos; + private int startPos; + private int lastTag; + private boolean enableAliasing; + + /** The absolute position of the end of the current message. */ + private int currentLimit = Integer.MAX_VALUE; + + private ArrayDecoder(final byte[] buffer, final int offset, final int len, boolean immutable) { + this.buffer = buffer; + limit = offset + len; + pos = offset; + startPos = pos; + this.immutable = immutable; } - if (input != null) { - int pos = bufferPos; - if (pos > 0) { - if (bufferSize > pos) { - System.arraycopy(buffer, pos, buffer, 0, bufferSize - pos); - } - totalBytesRetired += pos; - bufferSize -= pos; - bufferPos = 0; + @Override + public int readTag() throws IOException { + if (isAtEnd()) { + lastTag = 0; + return 0; } - int bytesRead = input.read(buffer, bufferSize, buffer.length - bufferSize); - if (bytesRead == 0 || bytesRead < -1 || bytesRead > buffer.length) { - throw new IllegalStateException( - "InputStream#read(byte[]) returned invalid result: " + bytesRead + - "\nThe InputStream implementation is buggy."); + lastTag = readRawVarint32(); + if (WireFormat.getTagFieldNumber(lastTag) == 0) { + // If we actually read zero (or any tag number corresponding to field + // number zero), that's not a valid tag. + throw InvalidProtocolBufferException.invalidTag(); } - if (bytesRead > 0) { - bufferSize += bytesRead; - // Integer-overflow-conscious check against sizeLimit - if (totalBytesRetired + n - sizeLimit > 0) { - throw InvalidProtocolBufferException.sizeLimitExceeded(); + return lastTag; + } + + @Override + public void checkLastTagWas(final int value) throws InvalidProtocolBufferException { + if (lastTag != value) { + throw InvalidProtocolBufferException.invalidEndTag(); + } + } + + @Override + public int getLastTag() { + return lastTag; + } + + @Override + public boolean skipField(final int tag) throws IOException { + switch (WireFormat.getTagWireType(tag)) { + case WireFormat.WIRETYPE_VARINT: + skipRawVarint(); + return true; + case WireFormat.WIRETYPE_FIXED64: + skipRawBytes(FIXED_64_SIZE); + return true; + case WireFormat.WIRETYPE_LENGTH_DELIMITED: + skipRawBytes(readRawVarint32()); + return true; + case WireFormat.WIRETYPE_START_GROUP: + skipMessage(); + checkLastTagWas( + WireFormat.makeTag(WireFormat.getTagFieldNumber(tag), WireFormat.WIRETYPE_END_GROUP)); + return true; + case WireFormat.WIRETYPE_END_GROUP: + return false; + case WireFormat.WIRETYPE_FIXED32: + skipRawBytes(FIXED_32_SIZE); + return true; + default: + throw InvalidProtocolBufferException.invalidWireType(); + } + } + + @Override + public boolean skipField(final int tag, final CodedOutputStream output) throws IOException { + switch (WireFormat.getTagWireType(tag)) { + case WireFormat.WIRETYPE_VARINT: + { + long value = readInt64(); + output.writeRawVarint32(tag); + output.writeUInt64NoTag(value); + return true; + } + case WireFormat.WIRETYPE_FIXED64: + { + long value = readRawLittleEndian64(); + output.writeRawVarint32(tag); + output.writeFixed64NoTag(value); + return true; + } + case WireFormat.WIRETYPE_LENGTH_DELIMITED: + { + ByteString value = readBytes(); + output.writeRawVarint32(tag); + output.writeBytesNoTag(value); + return true; + } + case WireFormat.WIRETYPE_START_GROUP: + { + output.writeRawVarint32(tag); + skipMessage(output); + int endtag = + WireFormat.makeTag( + WireFormat.getTagFieldNumber(tag), WireFormat.WIRETYPE_END_GROUP); + checkLastTagWas(endtag); + output.writeRawVarint32(endtag); + return true; + } + case WireFormat.WIRETYPE_END_GROUP: + { + return false; + } + case WireFormat.WIRETYPE_FIXED32: + { + int value = readRawLittleEndian32(); + output.writeRawVarint32(tag); + output.writeFixed32NoTag(value); + return true; + } + default: + throw InvalidProtocolBufferException.invalidWireType(); + } + } + + @Override + public void skipMessage() throws IOException { + while (true) { + final int tag = readTag(); + if (tag == 0 || !skipField(tag)) { + return; } - recomputeBufferSizeAfterLimit(); - return (bufferSize >= n) ? true : tryRefillBuffer(n); } } - return false; - } + @Override + public void skipMessage(CodedOutputStream output) throws IOException { + while (true) { + final int tag = readTag(); + if (tag == 0 || !skipField(tag, output)) { + return; + } + } + } - /** - * Read one byte from the input. - * - * @throws InvalidProtocolBufferException The end of the stream or the current - * limit was reached. - */ - public byte readRawByte() throws IOException { - if (bufferPos == bufferSize) { - refillBuffer(1); + + // ----------------------------------------------------------------- + + @Override + public double readDouble() throws IOException { + return Double.longBitsToDouble(readRawLittleEndian64()); } - return buffer[bufferPos++]; - } - /** - * Read a fixed size of bytes from the input. - * - * @throws InvalidProtocolBufferException The end of the stream or the current - * limit was reached. - */ - public byte[] readRawBytes(final int size) throws IOException { - final int pos = bufferPos; - if (size <= (bufferSize - pos) && size > 0) { - bufferPos = pos + size; - return Arrays.copyOfRange(buffer, pos, pos + size); - } else { - return readRawBytesSlowPath(size); + @Override + public float readFloat() throws IOException { + return Float.intBitsToFloat(readRawLittleEndian32()); } - } - /** - * Exactly like readRawBytes, but caller must have already checked the fast - * path: (size <= (bufferSize - pos) && size > 0) - */ - private byte[] readRawBytesSlowPath(final int size) throws IOException { - if (size <= 0) { + @Override + public long readUInt64() throws IOException { + return readRawVarint64(); + } + + @Override + public long readInt64() throws IOException { + return readRawVarint64(); + } + + @Override + public int readInt32() throws IOException { + return readRawVarint32(); + } + + @Override + public long readFixed64() throws IOException { + return readRawLittleEndian64(); + } + + @Override + public int readFixed32() throws IOException { + return readRawLittleEndian32(); + } + + @Override + public boolean readBool() throws IOException { + return readRawVarint64() != 0; + } + + @Override + public String readString() throws IOException { + final int size = readRawVarint32(); + if (size > 0 && size <= (limit - pos)) { + // Fast path: We already have the bytes in a contiguous buffer, so + // just copy directly from it. + final String result = new String(buffer, pos, size, UTF_8); + pos += size; + return result; + } + if (size == 0) { - return Internal.EMPTY_BYTE_ARRAY; - } else { + return ""; + } + if (size < 0) { throw InvalidProtocolBufferException.negativeSize(); } + throw InvalidProtocolBufferException.truncatedMessage(); } - // Verify that the message size so far has not exceeded sizeLimit. - int currentMessageSize = totalBytesRetired + bufferPos + size; - if (currentMessageSize > sizeLimit) { - throw InvalidProtocolBufferException.sizeLimitExceeded(); - } + @Override + public String readStringRequireUtf8() throws IOException { + final int size = readRawVarint32(); + if (size > 0 && size <= (limit - pos)) { + // TODO(martinrb): We could save a pass by validating while decoding. + if (!Utf8.isValidUtf8(buffer, pos, pos + size)) { + throw InvalidProtocolBufferException.invalidUtf8(); + } + final int tempPos = pos; + pos += size; + return new String(buffer, tempPos, size, UTF_8); + } - // Verify that the message size so far has not exceeded currentLimit. - if (currentMessageSize > currentLimit) { - // Read to the end of the stream anyway. - skipRawBytes(currentLimit - totalBytesRetired - bufferPos); + if (size == 0) { + return ""; + } + if (size <= 0) { + throw InvalidProtocolBufferException.negativeSize(); + } throw InvalidProtocolBufferException.truncatedMessage(); } - // We need the input stream to proceed. - if (input == null) { - throw InvalidProtocolBufferException.truncatedMessage(); + @Override + public void readGroup( + final int fieldNumber, + final MessageLite.Builder builder, + final ExtensionRegistryLite extensionRegistry) + throws IOException { + if (recursionDepth >= recursionLimit) { + throw InvalidProtocolBufferException.recursionLimitExceeded(); + } + ++recursionDepth; + builder.mergeFrom(this, extensionRegistry); + checkLastTagWas(WireFormat.makeTag(fieldNumber, WireFormat.WIRETYPE_END_GROUP)); + --recursionDepth; } - final int originalBufferPos = bufferPos; - final int bufferedBytes = bufferSize - bufferPos; - // Mark the current buffer consumed. - totalBytesRetired += bufferSize; - bufferPos = 0; - bufferSize = 0; + @Override + public T readGroup( + final int fieldNumber, + final Parser parser, + final ExtensionRegistryLite extensionRegistry) + throws IOException { + if (recursionDepth >= recursionLimit) { + throw InvalidProtocolBufferException.recursionLimitExceeded(); + } + ++recursionDepth; + T result = parser.parsePartialFrom(this, extensionRegistry); + checkLastTagWas(WireFormat.makeTag(fieldNumber, WireFormat.WIRETYPE_END_GROUP)); + --recursionDepth; + return result; + } - // Determine the number of bytes we need to read from the input stream. - int sizeLeft = size - bufferedBytes; - // TODO(nathanmittler): Consider using a value larger than BUFFER_SIZE. - if (sizeLeft < BUFFER_SIZE || sizeLeft <= input.available()) { - // Either the bytes we need are known to be available, or the required buffer is - // within an allowed threshold - go ahead and allocate the buffer now. - final byte[] bytes = new byte[size]; + @Deprecated + @Override + public void readUnknownGroup(final int fieldNumber, final MessageLite.Builder builder) + throws IOException { + readGroup(fieldNumber, builder, ExtensionRegistryLite.getEmptyRegistry()); + } - // Copy all of the buffered bytes to the result buffer. - System.arraycopy(buffer, originalBufferPos, bytes, 0, bufferedBytes); + @Override + public void readMessage( + final MessageLite.Builder builder, final ExtensionRegistryLite extensionRegistry) + throws IOException { + final int length = readRawVarint32(); + if (recursionDepth >= recursionLimit) { + throw InvalidProtocolBufferException.recursionLimitExceeded(); + } + final int oldLimit = pushLimit(length); + ++recursionDepth; + builder.mergeFrom(this, extensionRegistry); + checkLastTagWas(0); + --recursionDepth; + popLimit(oldLimit); + } - // Fill the remaining bytes from the input stream. - int pos = bufferedBytes; - while (pos < bytes.length) { - int n = input.read(bytes, pos, size - pos); - if (n == -1) { - throw InvalidProtocolBufferException.truncatedMessage(); - } - totalBytesRetired += n; - pos += n; + + @Override + public T readMessage( + final Parser parser, final ExtensionRegistryLite extensionRegistry) throws IOException { + int length = readRawVarint32(); + if (recursionDepth >= recursionLimit) { + throw InvalidProtocolBufferException.recursionLimitExceeded(); + } + final int oldLimit = pushLimit(length); + ++recursionDepth; + T result = parser.parsePartialFrom(this, extensionRegistry); + checkLastTagWas(0); + --recursionDepth; + popLimit(oldLimit); + return result; + } + + @Override + public ByteString readBytes() throws IOException { + final int size = readRawVarint32(); + if (size > 0 && size <= (limit - pos)) { + // Fast path: We already have the bytes in a contiguous buffer, so + // just copy directly from it. + final ByteString result = + immutable && enableAliasing + ? ByteString.wrap(buffer, pos, size) + : ByteString.copyFrom(buffer, pos, size); + pos += size; + return result; + } + if (size == 0) { + return ByteString.EMPTY; } + // Slow path: Build a byte array first then copy it. + return ByteString.wrap(readRawBytes(size)); + } - return bytes; + @Override + public byte[] readByteArray() throws IOException { + final int size = readRawVarint32(); + return readRawBytes(size); } - // The size is very large. For security reasons, we can't allocate the - // entire byte array yet. The size comes directly from the input, so a - // maliciously-crafted message could provide a bogus very large size in - // order to trick the app into allocating a lot of memory. We avoid this - // by allocating and reading only a small chunk at a time, so that the - // malicious message must actually *be* extremely large to cause - // problems. Meanwhile, we limit the allowed size of a message elsewhere. - final List chunks = new ArrayList(); - - while (sizeLeft > 0) { - // TODO(nathanmittler): Consider using a value larger than BUFFER_SIZE. - final byte[] chunk = new byte[Math.min(sizeLeft, BUFFER_SIZE)]; - int pos = 0; - while (pos < chunk.length) { - final int n = input.read(chunk, pos, chunk.length - pos); - if (n == -1) { - throw InvalidProtocolBufferException.truncatedMessage(); - } - totalBytesRetired += n; - pos += n; + @Override + public ByteBuffer readByteBuffer() throws IOException { + final int size = readRawVarint32(); + if (size > 0 && size <= (limit - pos)) { + // Fast path: We already have the bytes in a contiguous buffer. + // When aliasing is enabled, we can return a ByteBuffer pointing directly + // into the underlying byte array without copy if the CodedInputStream is + // constructed from a byte array. If aliasing is disabled or the input is + // from an InputStream or ByteString, we have to make a copy of the bytes. + ByteBuffer result = + !immutable && enableAliasing + ? ByteBuffer.wrap(buffer, pos, size).slice() + : ByteBuffer.wrap(Arrays.copyOfRange(buffer, pos, pos + size)); + pos += size; + // TODO(nathanmittler): Investigate making the ByteBuffer be made read-only + return result; + } + + if (size == 0) { + return EMPTY_BYTE_BUFFER; + } + if (size < 0) { + throw InvalidProtocolBufferException.negativeSize(); } - sizeLeft -= chunk.length; - chunks.add(chunk); + throw InvalidProtocolBufferException.truncatedMessage(); } - // OK, got everything. Now concatenate it all into one buffer. - final byte[] bytes = new byte[size]; + @Override + public int readUInt32() throws IOException { + return readRawVarint32(); + } - // Start by copying the leftover bytes from this.buffer. - System.arraycopy(buffer, originalBufferPos, bytes, 0, bufferedBytes); + @Override + public int readEnum() throws IOException { + return readRawVarint32(); + } - // And now all the chunks. - int pos = bufferedBytes; - for (final byte[] chunk : chunks) { - System.arraycopy(chunk, 0, bytes, pos, chunk.length); - pos += chunk.length; + @Override + public int readSFixed32() throws IOException { + return readRawLittleEndian32(); } - // Done. - return bytes; - } + @Override + public long readSFixed64() throws IOException { + return readRawLittleEndian64(); + } - /** - * Reads and discards {@code size} bytes. - * - * @throws InvalidProtocolBufferException The end of the stream or the current - * limit was reached. - */ - public void skipRawBytes(final int size) throws IOException { - if (size <= (bufferSize - bufferPos) && size >= 0) { - // We have all the bytes we need already. - bufferPos += size; - } else { - skipRawBytesSlowPath(size); + @Override + public int readSInt32() throws IOException { + return decodeZigZag32(readRawVarint32()); } - } - /** - * Exactly like skipRawBytes, but caller must have already checked the fast - * path: (size <= (bufferSize - pos) && size >= 0) - */ - private void skipRawBytesSlowPath(final int size) throws IOException { - if (size < 0) { - throw InvalidProtocolBufferException.negativeSize(); + @Override + public long readSInt64() throws IOException { + return decodeZigZag64(readRawVarint64()); } - if (totalBytesRetired + bufferPos + size > currentLimit) { - // Read to the end of the stream anyway. - skipRawBytes(currentLimit - totalBytesRetired - bufferPos); - // Then fail. - throw InvalidProtocolBufferException.truncatedMessage(); + // ================================================================= + + @Override + public int readRawVarint32() throws IOException { + // See implementation notes for readRawVarint64 + fastpath: + { + int tempPos = pos; + + if (limit == tempPos) { + break fastpath; + } + + final byte[] buffer = this.buffer; + int x; + if ((x = buffer[tempPos++]) >= 0) { + pos = tempPos; + return x; + } else if (limit - tempPos < 9) { + break fastpath; + } else if ((x ^= (buffer[tempPos++] << 7)) < 0) { + x ^= (~0 << 7); + } else if ((x ^= (buffer[tempPos++] << 14)) >= 0) { + x ^= (~0 << 7) ^ (~0 << 14); + } else if ((x ^= (buffer[tempPos++] << 21)) < 0) { + x ^= (~0 << 7) ^ (~0 << 14) ^ (~0 << 21); + } else { + int y = buffer[tempPos++]; + x ^= y << 28; + x ^= (~0 << 7) ^ (~0 << 14) ^ (~0 << 21) ^ (~0 << 28); + if (y < 0 + && buffer[tempPos++] < 0 + && buffer[tempPos++] < 0 + && buffer[tempPos++] < 0 + && buffer[tempPos++] < 0 + && buffer[tempPos++] < 0) { + break fastpath; // Will throw malformedVarint() + } + } + pos = tempPos; + return x; + } + return (int) readRawVarint64SlowPath(); + } + + private void skipRawVarint() throws IOException { + if (limit - pos >= MAX_VARINT_SIZE) { + skipRawVarintFastPath(); + } else { + skipRawVarintSlowPath(); + } } - // Skipping more bytes than are in the buffer. First skip what we have. - int pos = bufferSize - bufferPos; - bufferPos = bufferSize; + private void skipRawVarintFastPath() throws IOException { + for (int i = 0; i < MAX_VARINT_SIZE; i++) { + if (buffer[pos++] >= 0) { + return; + } + } + throw InvalidProtocolBufferException.malformedVarint(); + } - // Keep refilling the buffer until we get to the point we wanted to skip to. - // This has the side effect of ensuring the limits are updated correctly. - refillBuffer(1); - while (size - pos > bufferSize) { - pos += bufferSize; - bufferPos = bufferSize; - refillBuffer(1); + private void skipRawVarintSlowPath() throws IOException { + for (int i = 0; i < MAX_VARINT_SIZE; i++) { + if (readRawByte() >= 0) { + return; + } + } + throw InvalidProtocolBufferException.malformedVarint(); + } + + @Override + public long readRawVarint64() throws IOException { + // Implementation notes: + // + // Optimized for one-byte values, expected to be common. + // The particular code below was selected from various candidates + // empirically, by winning VarintBenchmark. + // + // Sign extension of (signed) Java bytes is usually a nuisance, but + // we exploit it here to more easily obtain the sign of bytes read. + // Instead of cleaning up the sign extension bits by masking eagerly, + // we delay until we find the final (positive) byte, when we clear all + // accumulated bits with one xor. We depend on javac to constant fold. + fastpath: + { + int tempPos = pos; + + if (limit == tempPos) { + break fastpath; + } + + final byte[] buffer = this.buffer; + long x; + int y; + if ((y = buffer[tempPos++]) >= 0) { + pos = tempPos; + return y; + } else if (limit - tempPos < 9) { + break fastpath; + } else if ((y ^= (buffer[tempPos++] << 7)) < 0) { + x = y ^ (~0 << 7); + } else if ((y ^= (buffer[tempPos++] << 14)) >= 0) { + x = y ^ ((~0 << 7) ^ (~0 << 14)); + } else if ((y ^= (buffer[tempPos++] << 21)) < 0) { + x = y ^ ((~0 << 7) ^ (~0 << 14) ^ (~0 << 21)); + } else if ((x = y ^ ((long) buffer[tempPos++] << 28)) >= 0L) { + x ^= (~0L << 7) ^ (~0L << 14) ^ (~0L << 21) ^ (~0L << 28); + } else if ((x ^= ((long) buffer[tempPos++] << 35)) < 0L) { + x ^= (~0L << 7) ^ (~0L << 14) ^ (~0L << 21) ^ (~0L << 28) ^ (~0L << 35); + } else if ((x ^= ((long) buffer[tempPos++] << 42)) >= 0L) { + x ^= (~0L << 7) ^ (~0L << 14) ^ (~0L << 21) ^ (~0L << 28) ^ (~0L << 35) ^ (~0L << 42); + } else if ((x ^= ((long) buffer[tempPos++] << 49)) < 0L) { + x ^= + (~0L << 7) + ^ (~0L << 14) + ^ (~0L << 21) + ^ (~0L << 28) + ^ (~0L << 35) + ^ (~0L << 42) + ^ (~0L << 49); + } else { + x ^= ((long) buffer[tempPos++] << 56); + x ^= + (~0L << 7) + ^ (~0L << 14) + ^ (~0L << 21) + ^ (~0L << 28) + ^ (~0L << 35) + ^ (~0L << 42) + ^ (~0L << 49) + ^ (~0L << 56); + if (x < 0L) { + if (buffer[tempPos++] < 0L) { + break fastpath; // Will throw malformedVarint() + } + } + } + pos = tempPos; + return x; + } + return readRawVarint64SlowPath(); + } + + @Override + long readRawVarint64SlowPath() throws IOException { + long result = 0; + for (int shift = 0; shift < 64; shift += 7) { + final byte b = readRawByte(); + result |= (long) (b & 0x7F) << shift; + if ((b & 0x80) == 0) { + return result; + } + } + throw InvalidProtocolBufferException.malformedVarint(); } - bufferPos = size - pos; + @Override + public int readRawLittleEndian32() throws IOException { + int tempPos = pos; + + if (limit - tempPos < FIXED_32_SIZE) { + throw InvalidProtocolBufferException.truncatedMessage(); + } + + final byte[] buffer = this.buffer; + pos = tempPos + FIXED_32_SIZE; + return (((buffer[tempPos] & 0xff)) + | ((buffer[tempPos + 1] & 0xff) << 8) + | ((buffer[tempPos + 2] & 0xff) << 16) + | ((buffer[tempPos + 3] & 0xff) << 24)); + } + + @Override + public long readRawLittleEndian64() throws IOException { + int tempPos = pos; + + if (limit - tempPos < FIXED_64_SIZE) { + throw InvalidProtocolBufferException.truncatedMessage(); + } + + final byte[] buffer = this.buffer; + pos = tempPos + FIXED_64_SIZE; + return (((buffer[tempPos] & 0xffL)) + | ((buffer[tempPos + 1] & 0xffL) << 8) + | ((buffer[tempPos + 2] & 0xffL) << 16) + | ((buffer[tempPos + 3] & 0xffL) << 24) + | ((buffer[tempPos + 4] & 0xffL) << 32) + | ((buffer[tempPos + 5] & 0xffL) << 40) + | ((buffer[tempPos + 6] & 0xffL) << 48) + | ((buffer[tempPos + 7] & 0xffL) << 56)); + } + + @Override + public void enableAliasing(boolean enabled) { + this.enableAliasing = enabled; + } + + @Override + public void resetSizeCounter() { + startPos = pos; + } + + @Override + public int pushLimit(int byteLimit) throws InvalidProtocolBufferException { + if (byteLimit < 0) { + throw InvalidProtocolBufferException.negativeSize(); + } + byteLimit += getTotalBytesRead(); + final int oldLimit = currentLimit; + if (byteLimit > oldLimit) { + throw InvalidProtocolBufferException.truncatedMessage(); + } + currentLimit = byteLimit; + + recomputeBufferSizeAfterLimit(); + + return oldLimit; + } + + private void recomputeBufferSizeAfterLimit() { + limit += bufferSizeAfterLimit; + final int bufferEnd = limit - startPos; + if (bufferEnd > currentLimit) { + // Limit is in current buffer. + bufferSizeAfterLimit = bufferEnd - currentLimit; + limit -= bufferSizeAfterLimit; + } else { + bufferSizeAfterLimit = 0; + } + } + + @Override + public void popLimit(final int oldLimit) { + currentLimit = oldLimit; + recomputeBufferSizeAfterLimit(); + } + + @Override + public int getBytesUntilLimit() { + if (currentLimit == Integer.MAX_VALUE) { + return -1; + } + + return currentLimit - getTotalBytesRead(); + } + + @Override + public boolean isAtEnd() throws IOException { + return pos == limit; + } + + @Override + public int getTotalBytesRead() { + return pos - startPos; + } + + @Override + public byte readRawByte() throws IOException { + if (pos == limit) { + throw InvalidProtocolBufferException.truncatedMessage(); + } + return buffer[pos++]; + } + + @Override + public byte[] readRawBytes(final int length) throws IOException { + if (length > 0 && length <= (limit - pos)) { + final int tempPos = pos; + pos += length; + return Arrays.copyOfRange(buffer, tempPos, pos); + } + + if (length <= 0) { + if (length == 0) { + return Internal.EMPTY_BYTE_ARRAY; + } else { + throw InvalidProtocolBufferException.negativeSize(); + } + } + throw InvalidProtocolBufferException.truncatedMessage(); + } + + @Override + public void skipRawBytes(final int length) throws IOException { + if (length >= 0 && length <= (limit - pos)) { + // We have all the bytes we need already. + pos += length; + return; + } + + if (length < 0) { + throw InvalidProtocolBufferException.negativeSize(); + } + throw InvalidProtocolBufferException.truncatedMessage(); + } + } + + /** + * A {@link CodedInputStream} implementation that uses a backing direct ByteBuffer as the input. + * Requires the use of {@code sun.misc.Unsafe} to perform fast reads on the buffer. + */ + private static final class UnsafeDirectNioDecoder extends CodedInputStream { + /** The direct buffer that is backing this stream. */ + private final ByteBuffer buffer; + + /** + * If {@code true}, indicates that the buffer is backing a {@link ByteString} and is therefore + * considered to be an immutable input source. + */ + private final boolean immutable; + + /** The unsafe address of the content of {@link #buffer}. */ + private final long address; + + /** The unsafe address of the current read limit of the buffer. */ + private long limit; + + /** The unsafe address of the current read position of the buffer. */ + private long pos; + + /** The unsafe address of the starting read position. */ + private long startPos; + + /** The amount of available data in the buffer beyond {@link #limit}. */ + private int bufferSizeAfterLimit; + + /** The last tag that was read from this stream. */ + private int lastTag; + + /** + * If {@code true}, indicates that calls to read {@link ByteString} or {@code byte[]} + * may return slices of the underlying buffer, rather than copies. + */ + private boolean enableAliasing; + + /** The absolute position of the end of the current message. */ + private int currentLimit = Integer.MAX_VALUE; + + static boolean isSupported() { + return UnsafeUtil.hasUnsafeByteBufferOperations(); + } + + private UnsafeDirectNioDecoder(ByteBuffer buffer, boolean immutable) { + this.buffer = buffer; + address = UnsafeUtil.addressOffset(buffer); + limit = address + buffer.limit(); + pos = address + buffer.position(); + startPos = pos; + this.immutable = immutable; + } + + @Override + public int readTag() throws IOException { + if (isAtEnd()) { + lastTag = 0; + return 0; + } + + lastTag = readRawVarint32(); + if (WireFormat.getTagFieldNumber(lastTag) == 0) { + // If we actually read zero (or any tag number corresponding to field + // number zero), that's not a valid tag. + throw InvalidProtocolBufferException.invalidTag(); + } + return lastTag; + } + + @Override + public void checkLastTagWas(final int value) throws InvalidProtocolBufferException { + if (lastTag != value) { + throw InvalidProtocolBufferException.invalidEndTag(); + } + } + + @Override + public int getLastTag() { + return lastTag; + } + + @Override + public boolean skipField(final int tag) throws IOException { + switch (WireFormat.getTagWireType(tag)) { + case WireFormat.WIRETYPE_VARINT: + skipRawVarint(); + return true; + case WireFormat.WIRETYPE_FIXED64: + skipRawBytes(FIXED_64_SIZE); + return true; + case WireFormat.WIRETYPE_LENGTH_DELIMITED: + skipRawBytes(readRawVarint32()); + return true; + case WireFormat.WIRETYPE_START_GROUP: + skipMessage(); + checkLastTagWas( + WireFormat.makeTag(WireFormat.getTagFieldNumber(tag), WireFormat.WIRETYPE_END_GROUP)); + return true; + case WireFormat.WIRETYPE_END_GROUP: + return false; + case WireFormat.WIRETYPE_FIXED32: + skipRawBytes(FIXED_32_SIZE); + return true; + default: + throw InvalidProtocolBufferException.invalidWireType(); + } + } + + @Override + public boolean skipField(final int tag, final CodedOutputStream output) throws IOException { + switch (WireFormat.getTagWireType(tag)) { + case WireFormat.WIRETYPE_VARINT: + { + long value = readInt64(); + output.writeRawVarint32(tag); + output.writeUInt64NoTag(value); + return true; + } + case WireFormat.WIRETYPE_FIXED64: + { + long value = readRawLittleEndian64(); + output.writeRawVarint32(tag); + output.writeFixed64NoTag(value); + return true; + } + case WireFormat.WIRETYPE_LENGTH_DELIMITED: + { + ByteString value = readBytes(); + output.writeRawVarint32(tag); + output.writeBytesNoTag(value); + return true; + } + case WireFormat.WIRETYPE_START_GROUP: + { + output.writeRawVarint32(tag); + skipMessage(output); + int endtag = + WireFormat.makeTag( + WireFormat.getTagFieldNumber(tag), WireFormat.WIRETYPE_END_GROUP); + checkLastTagWas(endtag); + output.writeRawVarint32(endtag); + return true; + } + case WireFormat.WIRETYPE_END_GROUP: + { + return false; + } + case WireFormat.WIRETYPE_FIXED32: + { + int value = readRawLittleEndian32(); + output.writeRawVarint32(tag); + output.writeFixed32NoTag(value); + return true; + } + default: + throw InvalidProtocolBufferException.invalidWireType(); + } + } + + @Override + public void skipMessage() throws IOException { + while (true) { + final int tag = readTag(); + if (tag == 0 || !skipField(tag)) { + return; + } + } + } + + @Override + public void skipMessage(CodedOutputStream output) throws IOException { + while (true) { + final int tag = readTag(); + if (tag == 0 || !skipField(tag, output)) { + return; + } + } + } + + + // ----------------------------------------------------------------- + + @Override + public double readDouble() throws IOException { + return Double.longBitsToDouble(readRawLittleEndian64()); + } + + @Override + public float readFloat() throws IOException { + return Float.intBitsToFloat(readRawLittleEndian32()); + } + + @Override + public long readUInt64() throws IOException { + return readRawVarint64(); + } + + @Override + public long readInt64() throws IOException { + return readRawVarint64(); + } + + @Override + public int readInt32() throws IOException { + return readRawVarint32(); + } + + @Override + public long readFixed64() throws IOException { + return readRawLittleEndian64(); + } + + @Override + public int readFixed32() throws IOException { + return readRawLittleEndian32(); + } + + @Override + public boolean readBool() throws IOException { + return readRawVarint64() != 0; + } + + @Override + public String readString() throws IOException { + final int size = readRawVarint32(); + if (size > 0 && size <= remaining()) { + // TODO(nathanmittler): Is there a way to avoid this copy? + byte[] bytes = copyToArray(pos, pos + size); + String result = new String(bytes, UTF_8); + pos += size; + return result; + } + + if (size == 0) { + return ""; + } + if (size < 0) { + throw InvalidProtocolBufferException.negativeSize(); + } + throw InvalidProtocolBufferException.truncatedMessage(); + } + + @Override + public String readStringRequireUtf8() throws IOException { + final int size = readRawVarint32(); + if (size >= 0 && size <= remaining()) { + // TODO(nathanmittler): Is there a way to avoid this copy? + byte[] bytes = copyToArray(pos, pos + size); + // TODO(martinrb): We could save a pass by validating while decoding. + if (!Utf8.isValidUtf8(bytes)) { + throw InvalidProtocolBufferException.invalidUtf8(); + } + + String result = new String(bytes, UTF_8); + pos += size; + return result; + } + + if (size == 0) { + return ""; + } + if (size <= 0) { + throw InvalidProtocolBufferException.negativeSize(); + } + throw InvalidProtocolBufferException.truncatedMessage(); + } + + @Override + public void readGroup( + final int fieldNumber, + final MessageLite.Builder builder, + final ExtensionRegistryLite extensionRegistry) + throws IOException { + if (recursionDepth >= recursionLimit) { + throw InvalidProtocolBufferException.recursionLimitExceeded(); + } + ++recursionDepth; + builder.mergeFrom(this, extensionRegistry); + checkLastTagWas(WireFormat.makeTag(fieldNumber, WireFormat.WIRETYPE_END_GROUP)); + --recursionDepth; + } + + + @Override + public T readGroup( + final int fieldNumber, + final Parser parser, + final ExtensionRegistryLite extensionRegistry) + throws IOException { + if (recursionDepth >= recursionLimit) { + throw InvalidProtocolBufferException.recursionLimitExceeded(); + } + ++recursionDepth; + T result = parser.parsePartialFrom(this, extensionRegistry); + checkLastTagWas(WireFormat.makeTag(fieldNumber, WireFormat.WIRETYPE_END_GROUP)); + --recursionDepth; + return result; + } + + @Deprecated + @Override + public void readUnknownGroup(final int fieldNumber, final MessageLite.Builder builder) + throws IOException { + readGroup(fieldNumber, builder, ExtensionRegistryLite.getEmptyRegistry()); + } + + @Override + public void readMessage( + final MessageLite.Builder builder, final ExtensionRegistryLite extensionRegistry) + throws IOException { + final int length = readRawVarint32(); + if (recursionDepth >= recursionLimit) { + throw InvalidProtocolBufferException.recursionLimitExceeded(); + } + final int oldLimit = pushLimit(length); + ++recursionDepth; + builder.mergeFrom(this, extensionRegistry); + checkLastTagWas(0); + --recursionDepth; + popLimit(oldLimit); + } + + + @Override + public T readMessage( + final Parser parser, final ExtensionRegistryLite extensionRegistry) throws IOException { + int length = readRawVarint32(); + if (recursionDepth >= recursionLimit) { + throw InvalidProtocolBufferException.recursionLimitExceeded(); + } + final int oldLimit = pushLimit(length); + ++recursionDepth; + T result = parser.parsePartialFrom(this, extensionRegistry); + checkLastTagWas(0); + --recursionDepth; + popLimit(oldLimit); + return result; + } + + @Override + public ByteString readBytes() throws IOException { + final int size = readRawVarint32(); + if (size > 0 && size <= remaining()) { + ByteBuffer result; + if (immutable && enableAliasing) { + result = slice(pos, pos + size); + } else { + result = copy(pos, pos + size); + } + pos += size; + return ByteString.wrap(result); + } + + if (size == 0) { + return ByteString.EMPTY; + } + if (size < 0) { + throw InvalidProtocolBufferException.negativeSize(); + } + throw InvalidProtocolBufferException.truncatedMessage(); + } + + @Override + public byte[] readByteArray() throws IOException { + return readRawBytes(readRawVarint32()); + } + + @Override + public ByteBuffer readByteBuffer() throws IOException { + final int size = readRawVarint32(); + if (size > 0 && size <= remaining()) { + ByteBuffer result; + // "Immutable" implies that buffer is backing a ByteString. + // Disallow slicing in this case to prevent the caller from modifying the contents + // of the ByteString. + if (!immutable && enableAliasing) { + result = slice(pos, pos + size); + } else { + result = copy(pos, pos + size); + } + pos += size; + // TODO(nathanmittler): Investigate making the ByteBuffer be made read-only + return result; + } + + if (size == 0) { + return EMPTY_BYTE_BUFFER; + } + if (size < 0) { + throw InvalidProtocolBufferException.negativeSize(); + } + throw InvalidProtocolBufferException.truncatedMessage(); + } + + @Override + public int readUInt32() throws IOException { + return readRawVarint32(); + } + + @Override + public int readEnum() throws IOException { + return readRawVarint32(); + } + + @Override + public int readSFixed32() throws IOException { + return readRawLittleEndian32(); + } + + @Override + public long readSFixed64() throws IOException { + return readRawLittleEndian64(); + } + + @Override + public int readSInt32() throws IOException { + return decodeZigZag32(readRawVarint32()); + } + + @Override + public long readSInt64() throws IOException { + return decodeZigZag64(readRawVarint64()); + } + + // ================================================================= + + @Override + public int readRawVarint32() throws IOException { + // See implementation notes for readRawVarint64 + fastpath: + { + long tempPos = pos; + + if (limit == tempPos) { + break fastpath; + } + + int x; + if ((x = UnsafeUtil.getByte(tempPos++)) >= 0) { + pos = tempPos; + return x; + } else if (limit - tempPos < 9) { + break fastpath; + } else if ((x ^= (UnsafeUtil.getByte(tempPos++) << 7)) < 0) { + x ^= (~0 << 7); + } else if ((x ^= (UnsafeUtil.getByte(tempPos++) << 14)) >= 0) { + x ^= (~0 << 7) ^ (~0 << 14); + } else if ((x ^= (UnsafeUtil.getByte(tempPos++) << 21)) < 0) { + x ^= (~0 << 7) ^ (~0 << 14) ^ (~0 << 21); + } else { + int y = UnsafeUtil.getByte(tempPos++); + x ^= y << 28; + x ^= (~0 << 7) ^ (~0 << 14) ^ (~0 << 21) ^ (~0 << 28); + if (y < 0 + && UnsafeUtil.getByte(tempPos++) < 0 + && UnsafeUtil.getByte(tempPos++) < 0 + && UnsafeUtil.getByte(tempPos++) < 0 + && UnsafeUtil.getByte(tempPos++) < 0 + && UnsafeUtil.getByte(tempPos++) < 0) { + break fastpath; // Will throw malformedVarint() + } + } + pos = tempPos; + return x; + } + return (int) readRawVarint64SlowPath(); + } + + private void skipRawVarint() throws IOException { + if (remaining() >= MAX_VARINT_SIZE) { + skipRawVarintFastPath(); + } else { + skipRawVarintSlowPath(); + } + } + + private void skipRawVarintFastPath() throws IOException { + for (int i = 0; i < MAX_VARINT_SIZE; i++) { + if (UnsafeUtil.getByte(pos++) >= 0) { + return; + } + } + throw InvalidProtocolBufferException.malformedVarint(); + } + + private void skipRawVarintSlowPath() throws IOException { + for (int i = 0; i < MAX_VARINT_SIZE; i++) { + if (readRawByte() >= 0) { + return; + } + } + throw InvalidProtocolBufferException.malformedVarint(); + } + + @Override + public long readRawVarint64() throws IOException { + // Implementation notes: + // + // Optimized for one-byte values, expected to be common. + // The particular code below was selected from various candidates + // empirically, by winning VarintBenchmark. + // + // Sign extension of (signed) Java bytes is usually a nuisance, but + // we exploit it here to more easily obtain the sign of bytes read. + // Instead of cleaning up the sign extension bits by masking eagerly, + // we delay until we find the final (positive) byte, when we clear all + // accumulated bits with one xor. We depend on javac to constant fold. + fastpath: + { + long tempPos = pos; + + if (limit == tempPos) { + break fastpath; + } + + long x; + int y; + if ((y = UnsafeUtil.getByte(tempPos++)) >= 0) { + pos = tempPos; + return y; + } else if (limit - tempPos < 9) { + break fastpath; + } else if ((y ^= (UnsafeUtil.getByte(tempPos++) << 7)) < 0) { + x = y ^ (~0 << 7); + } else if ((y ^= (UnsafeUtil.getByte(tempPos++) << 14)) >= 0) { + x = y ^ ((~0 << 7) ^ (~0 << 14)); + } else if ((y ^= (UnsafeUtil.getByte(tempPos++) << 21)) < 0) { + x = y ^ ((~0 << 7) ^ (~0 << 14) ^ (~0 << 21)); + } else if ((x = y ^ ((long) UnsafeUtil.getByte(tempPos++) << 28)) >= 0L) { + x ^= (~0L << 7) ^ (~0L << 14) ^ (~0L << 21) ^ (~0L << 28); + } else if ((x ^= ((long) UnsafeUtil.getByte(tempPos++) << 35)) < 0L) { + x ^= (~0L << 7) ^ (~0L << 14) ^ (~0L << 21) ^ (~0L << 28) ^ (~0L << 35); + } else if ((x ^= ((long) UnsafeUtil.getByte(tempPos++) << 42)) >= 0L) { + x ^= (~0L << 7) ^ (~0L << 14) ^ (~0L << 21) ^ (~0L << 28) ^ (~0L << 35) ^ (~0L << 42); + } else if ((x ^= ((long) UnsafeUtil.getByte(tempPos++) << 49)) < 0L) { + x ^= + (~0L << 7) + ^ (~0L << 14) + ^ (~0L << 21) + ^ (~0L << 28) + ^ (~0L << 35) + ^ (~0L << 42) + ^ (~0L << 49); + } else { + x ^= ((long) UnsafeUtil.getByte(tempPos++) << 56); + x ^= + (~0L << 7) + ^ (~0L << 14) + ^ (~0L << 21) + ^ (~0L << 28) + ^ (~0L << 35) + ^ (~0L << 42) + ^ (~0L << 49) + ^ (~0L << 56); + if (x < 0L) { + if (UnsafeUtil.getByte(tempPos++) < 0L) { + break fastpath; // Will throw malformedVarint() + } + } + } + pos = tempPos; + return x; + } + return readRawVarint64SlowPath(); + } + + @Override + long readRawVarint64SlowPath() throws IOException { + long result = 0; + for (int shift = 0; shift < 64; shift += 7) { + final byte b = readRawByte(); + result |= (long) (b & 0x7F) << shift; + if ((b & 0x80) == 0) { + return result; + } + } + throw InvalidProtocolBufferException.malformedVarint(); + } + + @Override + public int readRawLittleEndian32() throws IOException { + long tempPos = pos; + + if (limit - tempPos < FIXED_32_SIZE) { + throw InvalidProtocolBufferException.truncatedMessage(); + } + + pos = tempPos + FIXED_32_SIZE; + return (((UnsafeUtil.getByte(tempPos) & 0xff)) + | ((UnsafeUtil.getByte(tempPos + 1) & 0xff) << 8) + | ((UnsafeUtil.getByte(tempPos + 2) & 0xff) << 16) + | ((UnsafeUtil.getByte(tempPos + 3) & 0xff) << 24)); + } + + @Override + public long readRawLittleEndian64() throws IOException { + long tempPos = pos; + + if (limit - tempPos < FIXED_64_SIZE) { + throw InvalidProtocolBufferException.truncatedMessage(); + } + + pos = tempPos + FIXED_64_SIZE; + return (((UnsafeUtil.getByte(tempPos) & 0xffL)) + | ((UnsafeUtil.getByte(tempPos + 1) & 0xffL) << 8) + | ((UnsafeUtil.getByte(tempPos + 2) & 0xffL) << 16) + | ((UnsafeUtil.getByte(tempPos + 3) & 0xffL) << 24) + | ((UnsafeUtil.getByte(tempPos + 4) & 0xffL) << 32) + | ((UnsafeUtil.getByte(tempPos + 5) & 0xffL) << 40) + | ((UnsafeUtil.getByte(tempPos + 6) & 0xffL) << 48) + | ((UnsafeUtil.getByte(tempPos + 7) & 0xffL) << 56)); + } + + @Override + public void enableAliasing(boolean enabled) { + this.enableAliasing = enabled; + } + + @Override + public void resetSizeCounter() { + startPos = pos; + } + + @Override + public int pushLimit(int byteLimit) throws InvalidProtocolBufferException { + if (byteLimit < 0) { + throw InvalidProtocolBufferException.negativeSize(); + } + byteLimit += getTotalBytesRead(); + final int oldLimit = currentLimit; + if (byteLimit > oldLimit) { + throw InvalidProtocolBufferException.truncatedMessage(); + } + currentLimit = byteLimit; + + recomputeBufferSizeAfterLimit(); + + return oldLimit; + } + + @Override + public void popLimit(final int oldLimit) { + currentLimit = oldLimit; + recomputeBufferSizeAfterLimit(); + } + + @Override + public int getBytesUntilLimit() { + if (currentLimit == Integer.MAX_VALUE) { + return -1; + } + + return currentLimit - getTotalBytesRead(); + } + + @Override + public boolean isAtEnd() throws IOException { + return pos == limit; + } + + @Override + public int getTotalBytesRead() { + return (int) (pos - startPos); + } + + @Override + public byte readRawByte() throws IOException { + if (pos == limit) { + throw InvalidProtocolBufferException.truncatedMessage(); + } + return UnsafeUtil.getByte(pos++); + } + + @Override + public byte[] readRawBytes(final int length) throws IOException { + if (length >= 0 && length <= remaining()) { + byte[] bytes = new byte[length]; + slice(pos, pos + length).get(bytes); + pos += length; + return bytes; + } + + if (length <= 0) { + if (length == 0) { + return EMPTY_BYTE_ARRAY; + } else { + throw InvalidProtocolBufferException.negativeSize(); + } + } + + throw InvalidProtocolBufferException.truncatedMessage(); + } + + @Override + public void skipRawBytes(final int length) throws IOException { + if (length >= 0 && length <= remaining()) { + // We have all the bytes we need already. + pos += length; + return; + } + + if (length < 0) { + throw InvalidProtocolBufferException.negativeSize(); + } + throw InvalidProtocolBufferException.truncatedMessage(); + } + + private void recomputeBufferSizeAfterLimit() { + limit += bufferSizeAfterLimit; + final int bufferEnd = (int) (limit - startPos); + if (bufferEnd > currentLimit) { + // Limit is in current buffer. + bufferSizeAfterLimit = bufferEnd - currentLimit; + limit -= bufferSizeAfterLimit; + } else { + bufferSizeAfterLimit = 0; + } + } + + private int remaining() { + return (int) (limit - pos); + } + + private int bufferPos(long pos) { + return (int) (pos - address); + } + + private ByteBuffer slice(long begin, long end) throws IOException { + int prevPos = buffer.position(); + int prevLimit = buffer.limit(); + try { + buffer.position(bufferPos(begin)); + buffer.limit(bufferPos(end)); + return buffer.slice(); + } catch (IllegalArgumentException e) { + throw InvalidProtocolBufferException.truncatedMessage(); + } finally { + buffer.position(prevPos); + buffer.limit(prevLimit); + } + } + + private ByteBuffer copy(long begin, long end) throws IOException { + return ByteBuffer.wrap(copyToArray(begin, end)); + } + + private byte[] copyToArray(long begin, long end) throws IOException { + int prevPos = buffer.position(); + int prevLimit = buffer.limit(); + try { + buffer.position(bufferPos(begin)); + buffer.limit(bufferPos(end)); + byte[] bytes = new byte[(int) (end - begin)]; + buffer.get(bytes); + return bytes; + } catch (IllegalArgumentException e) { + throw InvalidProtocolBufferException.truncatedMessage(); + } finally { + buffer.position(prevPos); + buffer.limit(prevLimit); + } + } + } + + /** + * Implementation of {@link CodedInputStream} that uses an {@link InputStream} as the data source. + */ + private static final class StreamDecoder extends CodedInputStream { + private final InputStream input; + private final byte[] buffer; + /** bufferSize represents how many bytes are currently filled in the buffer */ + private int bufferSize; + + private int bufferSizeAfterLimit; + private int pos; + private int lastTag; + + /** + * The total number of bytes read before the current buffer. The total bytes read up to the + * current position can be computed as {@code totalBytesRetired + pos}. This value may be + * negative if reading started in the middle of the current buffer (e.g. if the constructor that + * takes a byte array and an offset was used). + */ + private int totalBytesRetired; + + /** The absolute position of the end of the current message. */ + private int currentLimit = Integer.MAX_VALUE; + + private StreamDecoder(final InputStream input, int bufferSize) { + checkNotNull(input, "input"); + this.input = input; + this.buffer = new byte[bufferSize]; + this.bufferSize = 0; + pos = 0; + totalBytesRetired = 0; + } + + @Override + public int readTag() throws IOException { + if (isAtEnd()) { + lastTag = 0; + return 0; + } + + lastTag = readRawVarint32(); + if (WireFormat.getTagFieldNumber(lastTag) == 0) { + // If we actually read zero (or any tag number corresponding to field + // number zero), that's not a valid tag. + throw InvalidProtocolBufferException.invalidTag(); + } + return lastTag; + } + + @Override + public void checkLastTagWas(final int value) throws InvalidProtocolBufferException { + if (lastTag != value) { + throw InvalidProtocolBufferException.invalidEndTag(); + } + } + + @Override + public int getLastTag() { + return lastTag; + } + + @Override + public boolean skipField(final int tag) throws IOException { + switch (WireFormat.getTagWireType(tag)) { + case WireFormat.WIRETYPE_VARINT: + skipRawVarint(); + return true; + case WireFormat.WIRETYPE_FIXED64: + skipRawBytes(FIXED_64_SIZE); + return true; + case WireFormat.WIRETYPE_LENGTH_DELIMITED: + skipRawBytes(readRawVarint32()); + return true; + case WireFormat.WIRETYPE_START_GROUP: + skipMessage(); + checkLastTagWas( + WireFormat.makeTag(WireFormat.getTagFieldNumber(tag), WireFormat.WIRETYPE_END_GROUP)); + return true; + case WireFormat.WIRETYPE_END_GROUP: + return false; + case WireFormat.WIRETYPE_FIXED32: + skipRawBytes(FIXED_32_SIZE); + return true; + default: + throw InvalidProtocolBufferException.invalidWireType(); + } + } + + @Override + public boolean skipField(final int tag, final CodedOutputStream output) throws IOException { + switch (WireFormat.getTagWireType(tag)) { + case WireFormat.WIRETYPE_VARINT: + { + long value = readInt64(); + output.writeRawVarint32(tag); + output.writeUInt64NoTag(value); + return true; + } + case WireFormat.WIRETYPE_FIXED64: + { + long value = readRawLittleEndian64(); + output.writeRawVarint32(tag); + output.writeFixed64NoTag(value); + return true; + } + case WireFormat.WIRETYPE_LENGTH_DELIMITED: + { + ByteString value = readBytes(); + output.writeRawVarint32(tag); + output.writeBytesNoTag(value); + return true; + } + case WireFormat.WIRETYPE_START_GROUP: + { + output.writeRawVarint32(tag); + skipMessage(output); + int endtag = + WireFormat.makeTag( + WireFormat.getTagFieldNumber(tag), WireFormat.WIRETYPE_END_GROUP); + checkLastTagWas(endtag); + output.writeRawVarint32(endtag); + return true; + } + case WireFormat.WIRETYPE_END_GROUP: + { + return false; + } + case WireFormat.WIRETYPE_FIXED32: + { + int value = readRawLittleEndian32(); + output.writeRawVarint32(tag); + output.writeFixed32NoTag(value); + return true; + } + default: + throw InvalidProtocolBufferException.invalidWireType(); + } + } + + @Override + public void skipMessage() throws IOException { + while (true) { + final int tag = readTag(); + if (tag == 0 || !skipField(tag)) { + return; + } + } + } + + @Override + public void skipMessage(CodedOutputStream output) throws IOException { + while (true) { + final int tag = readTag(); + if (tag == 0 || !skipField(tag, output)) { + return; + } + } + } + + /** Collects the bytes skipped and returns the data in a ByteBuffer. */ + private class SkippedDataSink implements RefillCallback { + private int lastPos = pos; + private ByteArrayOutputStream byteArrayStream; + + @Override + public void onRefill() { + if (byteArrayStream == null) { + byteArrayStream = new ByteArrayOutputStream(); + } + byteArrayStream.write(buffer, lastPos, pos - lastPos); + lastPos = 0; + } + + /** Gets skipped data in a ByteBuffer. This method should only be called once. */ + ByteBuffer getSkippedData() { + if (byteArrayStream == null) { + return ByteBuffer.wrap(buffer, lastPos, pos - lastPos); + } else { + byteArrayStream.write(buffer, lastPos, pos); + return ByteBuffer.wrap(byteArrayStream.toByteArray()); + } + } + } + + + // ----------------------------------------------------------------- + + @Override + public double readDouble() throws IOException { + return Double.longBitsToDouble(readRawLittleEndian64()); + } + + @Override + public float readFloat() throws IOException { + return Float.intBitsToFloat(readRawLittleEndian32()); + } + + @Override + public long readUInt64() throws IOException { + return readRawVarint64(); + } + + @Override + public long readInt64() throws IOException { + return readRawVarint64(); + } + + @Override + public int readInt32() throws IOException { + return readRawVarint32(); + } + + @Override + public long readFixed64() throws IOException { + return readRawLittleEndian64(); + } + + @Override + public int readFixed32() throws IOException { + return readRawLittleEndian32(); + } + + @Override + public boolean readBool() throws IOException { + return readRawVarint64() != 0; + } + + @Override + public String readString() throws IOException { + final int size = readRawVarint32(); + if (size > 0 && size <= (bufferSize - pos)) { + // Fast path: We already have the bytes in a contiguous buffer, so + // just copy directly from it. + final String result = new String(buffer, pos, size, UTF_8); + pos += size; + return result; + } + if (size == 0) { + return ""; + } + if (size <= bufferSize) { + refillBuffer(size); + String result = new String(buffer, pos, size, UTF_8); + pos += size; + return result; + } + // Slow path: Build a byte array first then copy it. + return new String(readRawBytesSlowPath(size), UTF_8); + } + + @Override + public String readStringRequireUtf8() throws IOException { + final int size = readRawVarint32(); + final byte[] bytes; + final int oldPos = pos; + final int tempPos; + if (size <= (bufferSize - oldPos) && size > 0) { + // Fast path: We already have the bytes in a contiguous buffer, so + // just copy directly from it. + bytes = buffer; + pos = oldPos + size; + tempPos = oldPos; + } else if (size == 0) { + return ""; + } else if (size <= bufferSize) { + refillBuffer(size); + bytes = buffer; + tempPos = 0; + pos = tempPos + size; + } else { + // Slow path: Build a byte array first then copy it. + bytes = readRawBytesSlowPath(size); + tempPos = 0; + } + // TODO(martinrb): We could save a pass by validating while decoding. + if (!Utf8.isValidUtf8(bytes, tempPos, tempPos + size)) { + throw InvalidProtocolBufferException.invalidUtf8(); + } + return new String(bytes, tempPos, size, UTF_8); + } + + @Override + public void readGroup( + final int fieldNumber, + final MessageLite.Builder builder, + final ExtensionRegistryLite extensionRegistry) + throws IOException { + if (recursionDepth >= recursionLimit) { + throw InvalidProtocolBufferException.recursionLimitExceeded(); + } + ++recursionDepth; + builder.mergeFrom(this, extensionRegistry); + checkLastTagWas(WireFormat.makeTag(fieldNumber, WireFormat.WIRETYPE_END_GROUP)); + --recursionDepth; + } + + + @Override + public T readGroup( + final int fieldNumber, + final Parser parser, + final ExtensionRegistryLite extensionRegistry) + throws IOException { + if (recursionDepth >= recursionLimit) { + throw InvalidProtocolBufferException.recursionLimitExceeded(); + } + ++recursionDepth; + T result = parser.parsePartialFrom(this, extensionRegistry); + checkLastTagWas(WireFormat.makeTag(fieldNumber, WireFormat.WIRETYPE_END_GROUP)); + --recursionDepth; + return result; + } + + @Deprecated + @Override + public void readUnknownGroup(final int fieldNumber, final MessageLite.Builder builder) + throws IOException { + readGroup(fieldNumber, builder, ExtensionRegistryLite.getEmptyRegistry()); + } + + @Override + public void readMessage( + final MessageLite.Builder builder, final ExtensionRegistryLite extensionRegistry) + throws IOException { + final int length = readRawVarint32(); + if (recursionDepth >= recursionLimit) { + throw InvalidProtocolBufferException.recursionLimitExceeded(); + } + final int oldLimit = pushLimit(length); + ++recursionDepth; + builder.mergeFrom(this, extensionRegistry); + checkLastTagWas(0); + --recursionDepth; + popLimit(oldLimit); + } + + + @Override + public T readMessage( + final Parser parser, final ExtensionRegistryLite extensionRegistry) throws IOException { + int length = readRawVarint32(); + if (recursionDepth >= recursionLimit) { + throw InvalidProtocolBufferException.recursionLimitExceeded(); + } + final int oldLimit = pushLimit(length); + ++recursionDepth; + T result = parser.parsePartialFrom(this, extensionRegistry); + checkLastTagWas(0); + --recursionDepth; + popLimit(oldLimit); + return result; + } + + @Override + public ByteString readBytes() throws IOException { + final int size = readRawVarint32(); + if (size <= (bufferSize - pos) && size > 0) { + // Fast path: We already have the bytes in a contiguous buffer, so + // just copy directly from it. + final ByteString result = ByteString.copyFrom(buffer, pos, size); + pos += size; + return result; + } + if (size == 0) { + return ByteString.EMPTY; + } + // Slow path: Build a byte array first then copy it. + return ByteString.wrap(readRawBytesSlowPath(size)); + } + + @Override + public byte[] readByteArray() throws IOException { + final int size = readRawVarint32(); + if (size <= (bufferSize - pos) && size > 0) { + // Fast path: We already have the bytes in a contiguous buffer, so + // just copy directly from it. + final byte[] result = Arrays.copyOfRange(buffer, pos, pos + size); + pos += size; + return result; + } else { + // Slow path: Build a byte array first then copy it. + return readRawBytesSlowPath(size); + } + } + + @Override + public ByteBuffer readByteBuffer() throws IOException { + final int size = readRawVarint32(); + if (size <= (bufferSize - pos) && size > 0) { + // Fast path: We already have the bytes in a contiguous buffer. + ByteBuffer result = ByteBuffer.wrap(Arrays.copyOfRange(buffer, pos, pos + size)); + pos += size; + return result; + } + if (size == 0) { + return Internal.EMPTY_BYTE_BUFFER; + } + // Slow path: Build a byte array first then copy it. + return ByteBuffer.wrap(readRawBytesSlowPath(size)); + } + + @Override + public int readUInt32() throws IOException { + return readRawVarint32(); + } + + @Override + public int readEnum() throws IOException { + return readRawVarint32(); + } + + @Override + public int readSFixed32() throws IOException { + return readRawLittleEndian32(); + } + + @Override + public long readSFixed64() throws IOException { + return readRawLittleEndian64(); + } + + @Override + public int readSInt32() throws IOException { + return decodeZigZag32(readRawVarint32()); + } + + @Override + public long readSInt64() throws IOException { + return decodeZigZag64(readRawVarint64()); + } + + // ================================================================= + + @Override + public int readRawVarint32() throws IOException { + // See implementation notes for readRawVarint64 + fastpath: + { + int tempPos = pos; + + if (bufferSize == tempPos) { + break fastpath; + } + + final byte[] buffer = this.buffer; + int x; + if ((x = buffer[tempPos++]) >= 0) { + pos = tempPos; + return x; + } else if (bufferSize - tempPos < 9) { + break fastpath; + } else if ((x ^= (buffer[tempPos++] << 7)) < 0) { + x ^= (~0 << 7); + } else if ((x ^= (buffer[tempPos++] << 14)) >= 0) { + x ^= (~0 << 7) ^ (~0 << 14); + } else if ((x ^= (buffer[tempPos++] << 21)) < 0) { + x ^= (~0 << 7) ^ (~0 << 14) ^ (~0 << 21); + } else { + int y = buffer[tempPos++]; + x ^= y << 28; + x ^= (~0 << 7) ^ (~0 << 14) ^ (~0 << 21) ^ (~0 << 28); + if (y < 0 + && buffer[tempPos++] < 0 + && buffer[tempPos++] < 0 + && buffer[tempPos++] < 0 + && buffer[tempPos++] < 0 + && buffer[tempPos++] < 0) { + break fastpath; // Will throw malformedVarint() + } + } + pos = tempPos; + return x; + } + return (int) readRawVarint64SlowPath(); + } + + private void skipRawVarint() throws IOException { + if (bufferSize - pos >= MAX_VARINT_SIZE) { + skipRawVarintFastPath(); + } else { + skipRawVarintSlowPath(); + } + } + + private void skipRawVarintFastPath() throws IOException { + for (int i = 0; i < MAX_VARINT_SIZE; i++) { + if (buffer[pos++] >= 0) { + return; + } + } + throw InvalidProtocolBufferException.malformedVarint(); + } + + private void skipRawVarintSlowPath() throws IOException { + for (int i = 0; i < MAX_VARINT_SIZE; i++) { + if (readRawByte() >= 0) { + return; + } + } + throw InvalidProtocolBufferException.malformedVarint(); + } + + @Override + public long readRawVarint64() throws IOException { + // Implementation notes: + // + // Optimized for one-byte values, expected to be common. + // The particular code below was selected from various candidates + // empirically, by winning VarintBenchmark. + // + // Sign extension of (signed) Java bytes is usually a nuisance, but + // we exploit it here to more easily obtain the sign of bytes read. + // Instead of cleaning up the sign extension bits by masking eagerly, + // we delay until we find the final (positive) byte, when we clear all + // accumulated bits with one xor. We depend on javac to constant fold. + fastpath: + { + int tempPos = pos; + + if (bufferSize == tempPos) { + break fastpath; + } + + final byte[] buffer = this.buffer; + long x; + int y; + if ((y = buffer[tempPos++]) >= 0) { + pos = tempPos; + return y; + } else if (bufferSize - tempPos < 9) { + break fastpath; + } else if ((y ^= (buffer[tempPos++] << 7)) < 0) { + x = y ^ (~0 << 7); + } else if ((y ^= (buffer[tempPos++] << 14)) >= 0) { + x = y ^ ((~0 << 7) ^ (~0 << 14)); + } else if ((y ^= (buffer[tempPos++] << 21)) < 0) { + x = y ^ ((~0 << 7) ^ (~0 << 14) ^ (~0 << 21)); + } else if ((x = y ^ ((long) buffer[tempPos++] << 28)) >= 0L) { + x ^= (~0L << 7) ^ (~0L << 14) ^ (~0L << 21) ^ (~0L << 28); + } else if ((x ^= ((long) buffer[tempPos++] << 35)) < 0L) { + x ^= (~0L << 7) ^ (~0L << 14) ^ (~0L << 21) ^ (~0L << 28) ^ (~0L << 35); + } else if ((x ^= ((long) buffer[tempPos++] << 42)) >= 0L) { + x ^= (~0L << 7) ^ (~0L << 14) ^ (~0L << 21) ^ (~0L << 28) ^ (~0L << 35) ^ (~0L << 42); + } else if ((x ^= ((long) buffer[tempPos++] << 49)) < 0L) { + x ^= + (~0L << 7) + ^ (~0L << 14) + ^ (~0L << 21) + ^ (~0L << 28) + ^ (~0L << 35) + ^ (~0L << 42) + ^ (~0L << 49); + } else { + x ^= ((long) buffer[tempPos++] << 56); + x ^= + (~0L << 7) + ^ (~0L << 14) + ^ (~0L << 21) + ^ (~0L << 28) + ^ (~0L << 35) + ^ (~0L << 42) + ^ (~0L << 49) + ^ (~0L << 56); + if (x < 0L) { + if (buffer[tempPos++] < 0L) { + break fastpath; // Will throw malformedVarint() + } + } + } + pos = tempPos; + return x; + } + return readRawVarint64SlowPath(); + } + + @Override + long readRawVarint64SlowPath() throws IOException { + long result = 0; + for (int shift = 0; shift < 64; shift += 7) { + final byte b = readRawByte(); + result |= (long) (b & 0x7F) << shift; + if ((b & 0x80) == 0) { + return result; + } + } + throw InvalidProtocolBufferException.malformedVarint(); + } + + @Override + public int readRawLittleEndian32() throws IOException { + int tempPos = pos; + + if (bufferSize - tempPos < FIXED_32_SIZE) { + refillBuffer(FIXED_32_SIZE); + tempPos = pos; + } + + final byte[] buffer = this.buffer; + pos = tempPos + FIXED_32_SIZE; + return (((buffer[tempPos] & 0xff)) + | ((buffer[tempPos + 1] & 0xff) << 8) + | ((buffer[tempPos + 2] & 0xff) << 16) + | ((buffer[tempPos + 3] & 0xff) << 24)); + } + + @Override + public long readRawLittleEndian64() throws IOException { + int tempPos = pos; + + if (bufferSize - tempPos < FIXED_64_SIZE) { + refillBuffer(FIXED_64_SIZE); + tempPos = pos; + } + + final byte[] buffer = this.buffer; + pos = tempPos + FIXED_64_SIZE; + return (((buffer[tempPos] & 0xffL)) + | ((buffer[tempPos + 1] & 0xffL) << 8) + | ((buffer[tempPos + 2] & 0xffL) << 16) + | ((buffer[tempPos + 3] & 0xffL) << 24) + | ((buffer[tempPos + 4] & 0xffL) << 32) + | ((buffer[tempPos + 5] & 0xffL) << 40) + | ((buffer[tempPos + 6] & 0xffL) << 48) + | ((buffer[tempPos + 7] & 0xffL) << 56)); + } + + // ----------------------------------------------------------------- + + @Override + public void enableAliasing(boolean enabled) { + // TODO(nathanmittler): Ideally we should throw here. Do nothing for backward compatibility. + } + + @Override + public void resetSizeCounter() { + totalBytesRetired = -pos; + } + + @Override + public int pushLimit(int byteLimit) throws InvalidProtocolBufferException { + if (byteLimit < 0) { + throw InvalidProtocolBufferException.negativeSize(); + } + byteLimit += totalBytesRetired + pos; + final int oldLimit = currentLimit; + if (byteLimit > oldLimit) { + throw InvalidProtocolBufferException.truncatedMessage(); + } + currentLimit = byteLimit; + + recomputeBufferSizeAfterLimit(); + + return oldLimit; + } + + private void recomputeBufferSizeAfterLimit() { + bufferSize += bufferSizeAfterLimit; + final int bufferEnd = totalBytesRetired + bufferSize; + if (bufferEnd > currentLimit) { + // Limit is in current buffer. + bufferSizeAfterLimit = bufferEnd - currentLimit; + bufferSize -= bufferSizeAfterLimit; + } else { + bufferSizeAfterLimit = 0; + } + } + + @Override + public void popLimit(final int oldLimit) { + currentLimit = oldLimit; + recomputeBufferSizeAfterLimit(); + } + + @Override + public int getBytesUntilLimit() { + if (currentLimit == Integer.MAX_VALUE) { + return -1; + } + + final int currentAbsolutePosition = totalBytesRetired + pos; + return currentLimit - currentAbsolutePosition; + } + + @Override + public boolean isAtEnd() throws IOException { + return pos == bufferSize && !tryRefillBuffer(1); + } + + @Override + public int getTotalBytesRead() { + return totalBytesRetired + pos; + } + + private interface RefillCallback { + void onRefill(); + } + + private RefillCallback refillCallback = null; + + /** + * Reads more bytes from the input, making at least {@code n} bytes available in the buffer. + * Caller must ensure that the requested space is not yet available, and that the requested + * space is less than BUFFER_SIZE. + * + * @throws InvalidProtocolBufferException The end of the stream or the current limit was + * reached. + */ + private void refillBuffer(int n) throws IOException { + if (!tryRefillBuffer(n)) { + throw InvalidProtocolBufferException.truncatedMessage(); + } + } + + /** + * Tries to read more bytes from the input, making at least {@code n} bytes available in the + * buffer. Caller must ensure that the requested space is not yet available, and that the + * requested space is less than BUFFER_SIZE. + * + * @return {@code true} if the bytes could be made available; {@code false} if the end of the + * stream or the current limit was reached. + */ + private boolean tryRefillBuffer(int n) throws IOException { + if (pos + n <= bufferSize) { + throw new IllegalStateException( + "refillBuffer() called when " + n + " bytes were already available in buffer"); + } + + if (totalBytesRetired + pos + n > currentLimit) { + // Oops, we hit a limit. + return false; + } + + if (refillCallback != null) { + refillCallback.onRefill(); + } + + int tempPos = pos; + if (tempPos > 0) { + if (bufferSize > tempPos) { + System.arraycopy(buffer, tempPos, buffer, 0, bufferSize - tempPos); + } + totalBytesRetired += tempPos; + bufferSize -= tempPos; + pos = 0; + } + + int bytesRead = input.read(buffer, bufferSize, buffer.length - bufferSize); + if (bytesRead == 0 || bytesRead < -1 || bytesRead > buffer.length) { + throw new IllegalStateException( + "InputStream#read(byte[]) returned invalid result: " + + bytesRead + + "\nThe InputStream implementation is buggy."); + } + if (bytesRead > 0) { + bufferSize += bytesRead; + // Integer-overflow-conscious check against sizeLimit + if (totalBytesRetired + n - sizeLimit > 0) { + throw InvalidProtocolBufferException.sizeLimitExceeded(); + } + recomputeBufferSizeAfterLimit(); + return (bufferSize >= n) ? true : tryRefillBuffer(n); + } + + return false; + } + + @Override + public byte readRawByte() throws IOException { + if (pos == bufferSize) { + refillBuffer(1); + } + return buffer[pos++]; + } + + @Override + public byte[] readRawBytes(final int size) throws IOException { + final int tempPos = pos; + if (size <= (bufferSize - tempPos) && size > 0) { + pos = tempPos + size; + return Arrays.copyOfRange(buffer, tempPos, tempPos + size); + } else { + return readRawBytesSlowPath(size); + } + } + + /** + * Exactly like readRawBytes, but caller must have already checked the fast path: (size <= + * (bufferSize - pos) && size > 0) + */ + private byte[] readRawBytesSlowPath(final int size) throws IOException { + if (size == 0) { + return Internal.EMPTY_BYTE_ARRAY; + } + if (size < 0) { + throw InvalidProtocolBufferException.negativeSize(); + } + + // Verify that the message size so far has not exceeded sizeLimit. + int currentMessageSize = totalBytesRetired + pos + size; + if (currentMessageSize > sizeLimit) { + throw InvalidProtocolBufferException.sizeLimitExceeded(); + } + + // Verify that the message size so far has not exceeded currentLimit. + if (currentMessageSize > currentLimit) { + // Read to the end of the stream anyway. + skipRawBytes(currentLimit - totalBytesRetired - pos); + throw InvalidProtocolBufferException.truncatedMessage(); + } + + final int originalBufferPos = pos; + final int bufferedBytes = bufferSize - pos; + + // Mark the current buffer consumed. + totalBytesRetired += bufferSize; + pos = 0; + bufferSize = 0; + + // Determine the number of bytes we need to read from the input stream. + int sizeLeft = size - bufferedBytes; + // TODO(nathanmittler): Consider using a value larger than DEFAULT_BUFFER_SIZE. + if (sizeLeft < DEFAULT_BUFFER_SIZE || sizeLeft <= input.available()) { + // Either the bytes we need are known to be available, or the required buffer is + // within an allowed threshold - go ahead and allocate the buffer now. + final byte[] bytes = new byte[size]; + + // Copy all of the buffered bytes to the result buffer. + System.arraycopy(buffer, originalBufferPos, bytes, 0, bufferedBytes); + + // Fill the remaining bytes from the input stream. + int tempPos = bufferedBytes; + while (tempPos < bytes.length) { + int n = input.read(bytes, tempPos, size - tempPos); + if (n == -1) { + throw InvalidProtocolBufferException.truncatedMessage(); + } + totalBytesRetired += n; + tempPos += n; + } + + return bytes; + } + + // The size is very large. For security reasons, we can't allocate the + // entire byte array yet. The size comes directly from the input, so a + // maliciously-crafted message could provide a bogus very large size in + // order to trick the app into allocating a lot of memory. We avoid this + // by allocating and reading only a small chunk at a time, so that the + // malicious message must actually *be* extremely large to cause + // problems. Meanwhile, we limit the allowed size of a message elsewhere. + final List chunks = new ArrayList(); + + while (sizeLeft > 0) { + // TODO(nathanmittler): Consider using a value larger than DEFAULT_BUFFER_SIZE. + final byte[] chunk = new byte[Math.min(sizeLeft, DEFAULT_BUFFER_SIZE)]; + int tempPos = 0; + while (tempPos < chunk.length) { + final int n = input.read(chunk, tempPos, chunk.length - tempPos); + if (n == -1) { + throw InvalidProtocolBufferException.truncatedMessage(); + } + totalBytesRetired += n; + tempPos += n; + } + sizeLeft -= chunk.length; + chunks.add(chunk); + } + + // OK, got everything. Now concatenate it all into one buffer. + final byte[] bytes = new byte[size]; + + // Start by copying the leftover bytes from this.buffer. + System.arraycopy(buffer, originalBufferPos, bytes, 0, bufferedBytes); + + // And now all the chunks. + int tempPos = bufferedBytes; + for (final byte[] chunk : chunks) { + System.arraycopy(chunk, 0, bytes, tempPos, chunk.length); + tempPos += chunk.length; + } + + // Done. + return bytes; + } + + @Override + public void skipRawBytes(final int size) throws IOException { + if (size <= (bufferSize - pos) && size >= 0) { + // We have all the bytes we need already. + pos += size; + } else { + skipRawBytesSlowPath(size); + } + } + + /** + * Exactly like skipRawBytes, but caller must have already checked the fast path: (size <= + * (bufferSize - pos) && size >= 0) + */ + private void skipRawBytesSlowPath(final int size) throws IOException { + if (size < 0) { + throw InvalidProtocolBufferException.negativeSize(); + } + + if (totalBytesRetired + pos + size > currentLimit) { + // Read to the end of the stream anyway. + skipRawBytes(currentLimit - totalBytesRetired - pos); + // Then fail. + throw InvalidProtocolBufferException.truncatedMessage(); + } + + // Skipping more bytes than are in the buffer. First skip what we have. + int tempPos = bufferSize - pos; + pos = bufferSize; + + // Keep refilling the buffer until we get to the point we wanted to skip to. + // This has the side effect of ensuring the limits are updated correctly. + refillBuffer(1); + while (size - tempPos > bufferSize) { + tempPos += bufferSize; + pos = bufferSize; + refillBuffer(1); + } + + pos = size - tempPos; + } } } diff --git a/java/core/src/main/java/com/google/protobuf/CodedOutputStream.java b/java/core/src/main/java/com/google/protobuf/CodedOutputStream.java index e5515285..3e32c2c5 100644 --- a/java/core/src/main/java/com/google/protobuf/CodedOutputStream.java +++ b/java/core/src/main/java/com/google/protobuf/CodedOutputStream.java @@ -30,10 +30,12 @@ package com.google.protobuf; +import static com.google.protobuf.WireFormat.FIXED_32_SIZE; +import static com.google.protobuf.WireFormat.FIXED_64_SIZE; +import static com.google.protobuf.WireFormat.MAX_VARINT_SIZE; import static java.lang.Math.max; import com.google.protobuf.Utf8.UnpairedSurrogateException; - import java.io.IOException; import java.io.OutputStream; import java.nio.BufferOverflowException; @@ -59,10 +61,6 @@ public abstract class CodedOutputStream extends ByteOutput { private static final boolean HAS_UNSAFE_ARRAY_OPERATIONS = UnsafeUtil.hasUnsafeArrayOperations(); private static final long ARRAY_BASE_OFFSET = UnsafeUtil.getArrayBaseOffset(); - private static final int FIXED_32_SIZE = 4; - private static final int FIXED_64_SIZE = 8; - private static final int MAX_VARINT_SIZE = 10; - /** * @deprecated Use {@link #computeFixed32SizeNoTag(int)} instead. */ @@ -134,14 +132,27 @@ public abstract class CodedOutputStream extends ByteOutput { return new ArrayEncoder(flatArray, offset, length); } - /** - * Create a new {@code CodedOutputStream} that writes to the given {@link ByteBuffer}. - */ - public static CodedOutputStream newInstance(ByteBuffer byteBuffer) { - if (byteBuffer.hasArray()) { - return new NioHeapEncoder(byteBuffer); + /** Create a new {@code CodedOutputStream} that writes to the given {@link ByteBuffer}. */ + public static CodedOutputStream newInstance(ByteBuffer buffer) { + if (buffer.hasArray()) { + return new HeapNioEncoder(buffer); } - return new NioEncoder(byteBuffer); + if (buffer.isDirect() && !buffer.isReadOnly()) { + return UnsafeDirectNioEncoder.isSupported() + ? newUnsafeInstance(buffer) + : newSafeInstance(buffer); + } + throw new IllegalArgumentException("ByteBuffer is read-only"); + } + + /** For testing purposes only. */ + static CodedOutputStream newUnsafeInstance(ByteBuffer buffer) { + return new UnsafeDirectNioEncoder(buffer); + } + + /** For testing purposes only. */ + static CodedOutputStream newSafeInstance(ByteBuffer buffer) { + return new SafeDirectNioEncoder(buffer); } /** @@ -979,6 +990,10 @@ public abstract class CodedOutputStream extends ByteOutput { super(MESSAGE); } + OutOfSpaceException(String explanationMessage) { + super(MESSAGE + ": " + explanationMessage); + } + OutOfSpaceException(Throwable cause) { super(MESSAGE, cause); } @@ -1486,11 +1501,11 @@ public abstract class CodedOutputStream extends ByteOutput { * A {@link CodedOutputStream} that writes directly to a heap {@link ByteBuffer}. Writes are * done directly to the underlying array. The buffer position is only updated after a flush. */ - private static final class NioHeapEncoder extends ArrayEncoder { + private static final class HeapNioEncoder extends ArrayEncoder { private final ByteBuffer byteBuffer; private int initialPosition; - NioHeapEncoder(ByteBuffer byteBuffer) { + HeapNioEncoder(ByteBuffer byteBuffer) { super(byteBuffer.array(), byteBuffer.arrayOffset() + byteBuffer.position(), byteBuffer.remaining()); this.byteBuffer = byteBuffer; @@ -1505,14 +1520,15 @@ public abstract class CodedOutputStream extends ByteOutput { } /** - * A {@link CodedOutputStream} that writes directly to a {@link ByteBuffer}. + * A {@link CodedOutputStream} that writes directly to a direct {@link ByteBuffer}, using only + * safe operations.. */ - private static final class NioEncoder extends CodedOutputStream { + private static final class SafeDirectNioEncoder extends CodedOutputStream { private final ByteBuffer originalBuffer; private final ByteBuffer buffer; private final int initialPosition; - NioEncoder(ByteBuffer buffer) { + SafeDirectNioEncoder(ByteBuffer buffer) { this.originalBuffer = buffer; this.buffer = buffer.duplicate().order(ByteOrder.LITTLE_ENDIAN); initialPosition = buffer.position(); @@ -1814,6 +1830,356 @@ public abstract class CodedOutputStream extends ByteOutput { } } + /** + * A {@link CodedOutputStream} that writes directly to a direct {@link ByteBuffer} using {@code + * sun.misc.Unsafe}. + */ + private static final class UnsafeDirectNioEncoder extends CodedOutputStream { + private final ByteBuffer originalBuffer; + private final ByteBuffer buffer; + private final long address; + private final long initialPosition; + private final long limit; + private final long oneVarintLimit; + private long position; + + UnsafeDirectNioEncoder(ByteBuffer buffer) { + this.originalBuffer = buffer; + this.buffer = buffer.duplicate().order(ByteOrder.LITTLE_ENDIAN); + address = UnsafeUtil.addressOffset(buffer); + initialPosition = address + buffer.position(); + limit = address + buffer.limit(); + oneVarintLimit = limit - MAX_VARINT_SIZE; + position = initialPosition; + } + + static boolean isSupported() { + return UnsafeUtil.hasUnsafeByteBufferOperations(); + } + + @Override + public void writeTag(int fieldNumber, int wireType) throws IOException { + writeUInt32NoTag(WireFormat.makeTag(fieldNumber, wireType)); + } + + @Override + public void writeInt32(int fieldNumber, int value) throws IOException { + writeTag(fieldNumber, WireFormat.WIRETYPE_VARINT); + writeInt32NoTag(value); + } + + @Override + public void writeUInt32(int fieldNumber, int value) throws IOException { + writeTag(fieldNumber, WireFormat.WIRETYPE_VARINT); + writeUInt32NoTag(value); + } + + @Override + public void writeFixed32(int fieldNumber, int value) throws IOException { + writeTag(fieldNumber, WireFormat.WIRETYPE_FIXED32); + writeFixed32NoTag(value); + } + + @Override + public void writeUInt64(int fieldNumber, long value) throws IOException { + writeTag(fieldNumber, WireFormat.WIRETYPE_VARINT); + writeUInt64NoTag(value); + } + + @Override + public void writeFixed64(int fieldNumber, long value) throws IOException { + writeTag(fieldNumber, WireFormat.WIRETYPE_FIXED64); + writeFixed64NoTag(value); + } + + @Override + public void writeBool(int fieldNumber, boolean value) throws IOException { + writeTag(fieldNumber, WireFormat.WIRETYPE_VARINT); + write((byte) (value ? 1 : 0)); + } + + @Override + public void writeString(int fieldNumber, String value) throws IOException { + writeTag(fieldNumber, WireFormat.WIRETYPE_LENGTH_DELIMITED); + writeStringNoTag(value); + } + + @Override + public void writeBytes(int fieldNumber, ByteString value) throws IOException { + writeTag(fieldNumber, WireFormat.WIRETYPE_LENGTH_DELIMITED); + writeBytesNoTag(value); + } + + @Override + public void writeByteArray(int fieldNumber, byte[] value) throws IOException { + writeByteArray(fieldNumber, value, 0, value.length); + } + + @Override + public void writeByteArray(int fieldNumber, byte[] value, int offset, int length) + throws IOException { + writeTag(fieldNumber, WireFormat.WIRETYPE_LENGTH_DELIMITED); + writeByteArrayNoTag(value, offset, length); + } + + @Override + public void writeByteBuffer(int fieldNumber, ByteBuffer value) throws IOException { + writeTag(fieldNumber, WireFormat.WIRETYPE_LENGTH_DELIMITED); + writeUInt32NoTag(value.capacity()); + writeRawBytes(value); + } + + @Override + public void writeMessage(int fieldNumber, MessageLite value) throws IOException { + writeTag(fieldNumber, WireFormat.WIRETYPE_LENGTH_DELIMITED); + writeMessageNoTag(value); + } + + @Override + public void writeMessageSetExtension(int fieldNumber, MessageLite value) throws IOException { + writeTag(WireFormat.MESSAGE_SET_ITEM, WireFormat.WIRETYPE_START_GROUP); + writeUInt32(WireFormat.MESSAGE_SET_TYPE_ID, fieldNumber); + writeMessage(WireFormat.MESSAGE_SET_MESSAGE, value); + writeTag(WireFormat.MESSAGE_SET_ITEM, WireFormat.WIRETYPE_END_GROUP); + } + + @Override + public void writeRawMessageSetExtension(int fieldNumber, ByteString value) throws IOException { + writeTag(WireFormat.MESSAGE_SET_ITEM, WireFormat.WIRETYPE_START_GROUP); + writeUInt32(WireFormat.MESSAGE_SET_TYPE_ID, fieldNumber); + writeBytes(WireFormat.MESSAGE_SET_MESSAGE, value); + writeTag(WireFormat.MESSAGE_SET_ITEM, WireFormat.WIRETYPE_END_GROUP); + } + + @Override + public void writeMessageNoTag(MessageLite value) throws IOException { + writeUInt32NoTag(value.getSerializedSize()); + value.writeTo(this); + } + + @Override + public void write(byte value) throws IOException { + if (position >= limit) { + throw new OutOfSpaceException( + String.format("Pos: %d, limit: %d, len: %d", position, limit, 1)); + } + UnsafeUtil.putByte(position++, value); + } + + @Override + public void writeBytesNoTag(ByteString value) throws IOException { + writeUInt32NoTag(value.size()); + value.writeTo(this); + } + + @Override + public void writeByteArrayNoTag(byte[] value, int offset, int length) throws IOException { + writeUInt32NoTag(length); + write(value, offset, length); + } + + @Override + public void writeRawBytes(ByteBuffer value) throws IOException { + if (value.hasArray()) { + write(value.array(), value.arrayOffset(), value.capacity()); + } else { + ByteBuffer duplicated = value.duplicate(); + duplicated.clear(); + write(duplicated); + } + } + + @Override + public void writeInt32NoTag(int value) throws IOException { + if (value >= 0) { + writeUInt32NoTag(value); + } else { + // Must sign-extend. + writeUInt64NoTag(value); + } + } + + @Override + public void writeUInt32NoTag(int value) throws IOException { + if (position <= oneVarintLimit) { + // Optimization to avoid bounds checks on each iteration. + while (true) { + if ((value & ~0x7F) == 0) { + UnsafeUtil.putByte(position++, (byte) value); + return; + } else { + UnsafeUtil.putByte(position++, (byte) ((value & 0x7F) | 0x80)); + value >>>= 7; + } + } + } else { + while (position < limit) { + if ((value & ~0x7F) == 0) { + UnsafeUtil.putByte(position++, (byte) value); + return; + } else { + UnsafeUtil.putByte(position++, (byte) ((value & 0x7F) | 0x80)); + value >>>= 7; + } + } + throw new OutOfSpaceException( + String.format("Pos: %d, limit: %d, len: %d", position, limit, 1)); + } + } + + @Override + public void writeFixed32NoTag(int value) throws IOException { + buffer.putInt(bufferPos(position), value); + position += FIXED_32_SIZE; + } + + @Override + public void writeUInt64NoTag(long value) throws IOException { + if (position <= oneVarintLimit) { + // Optimization to avoid bounds checks on each iteration. + while (true) { + if ((value & ~0x7FL) == 0) { + UnsafeUtil.putByte(position++, (byte) value); + return; + } else { + UnsafeUtil.putByte(position++, (byte) (((int) value & 0x7F) | 0x80)); + value >>>= 7; + } + } + } else { + while (position < limit) { + if ((value & ~0x7FL) == 0) { + UnsafeUtil.putByte(position++, (byte) value); + return; + } else { + UnsafeUtil.putByte(position++, (byte) (((int) value & 0x7F) | 0x80)); + value >>>= 7; + } + } + throw new OutOfSpaceException( + String.format("Pos: %d, limit: %d, len: %d", position, limit, 1)); + } + } + + @Override + public void writeFixed64NoTag(long value) throws IOException { + buffer.putLong(bufferPos(position), value); + position += FIXED_64_SIZE; + } + + @Override + public void write(byte[] value, int offset, int length) throws IOException { + if (value == null + || offset < 0 + || length < 0 + || (value.length - length) < offset + || (limit - length) < position) { + if (value == null) { + throw new NullPointerException("value"); + } + throw new OutOfSpaceException( + String.format("Pos: %d, limit: %d, len: %d", position, limit, length)); + } + + UnsafeUtil.copyMemory( + value, UnsafeUtil.getArrayBaseOffset() + offset, null, position, length); + position += length; + } + + @Override + public void writeLazy(byte[] value, int offset, int length) throws IOException { + write(value, offset, length); + } + + @Override + public void write(ByteBuffer value) throws IOException { + try { + int length = value.remaining(); + repositionBuffer(position); + buffer.put(value); + position += length; + } catch (BufferOverflowException e) { + throw new OutOfSpaceException(e); + } + } + + @Override + public void writeLazy(ByteBuffer value) throws IOException { + write(value); + } + + @Override + public void writeStringNoTag(String value) throws IOException { + long prevPos = position; + try { + // UTF-8 byte length of the string is at least its UTF-16 code unit length (value.length()), + // and at most 3 times of it. We take advantage of this in both branches below. + int maxEncodedSize = value.length() * Utf8.MAX_BYTES_PER_CHAR; + int maxLengthVarIntSize = computeUInt32SizeNoTag(maxEncodedSize); + int minLengthVarIntSize = computeUInt32SizeNoTag(value.length()); + if (minLengthVarIntSize == maxLengthVarIntSize) { + // Save the current position and increment past the length field. We'll come back + // and write the length field after the encoding is complete. + int stringStart = bufferPos(position) + minLengthVarIntSize; + buffer.position(stringStart); + + // Encode the string. + Utf8.encodeUtf8(value, buffer); + + // Write the length and advance the position. + int length = buffer.position() - stringStart; + writeUInt32NoTag(length); + position += length; + } else { + // Calculate and write the encoded length. + int length = Utf8.encodedLength(value); + writeUInt32NoTag(length); + + // Write the string and advance the position. + repositionBuffer(position); + Utf8.encodeUtf8(value, buffer); + position += length; + } + } catch (UnpairedSurrogateException e) { + // Roll back the change and convert to an IOException. + position = prevPos; + repositionBuffer(position); + + // TODO(nathanmittler): We should throw an IOException here instead. + inefficientWriteStringNoTag(value, e); + } catch (IllegalArgumentException e) { + // Thrown by buffer.position() if out of range. + throw new OutOfSpaceException(e); + } catch (IndexOutOfBoundsException e) { + throw new OutOfSpaceException(e); + } + } + + @Override + public void flush() { + // Update the position of the original buffer. + originalBuffer.position(bufferPos(position)); + } + + @Override + public int spaceLeft() { + return (int) (limit - position); + } + + @Override + public int getTotalBytesWritten() { + return (int) (position - initialPosition); + } + + private void repositionBuffer(long pos) { + buffer.position(bufferPos(pos)); + } + + private int bufferPos(long pos) { + return (int) (pos - address); + } + } + /** * Abstract base class for buffered encoders. */ diff --git a/java/core/src/main/java/com/google/protobuf/Descriptors.java b/java/core/src/main/java/com/google/protobuf/Descriptors.java index 1c34c24f..cab7118a 100644 --- a/java/core/src/main/java/com/google/protobuf/Descriptors.java +++ b/java/core/src/main/java/com/google/protobuf/Descriptors.java @@ -1212,33 +1212,20 @@ public final class Descriptors { private final Object defaultDefault; } - // TODO(xiaofeng): Implement it consistently across different languages. See b/24751348. - private static String fieldNameToLowerCamelCase(String name) { + // This method should match exactly with the ToJsonName() function in C++ + // descriptor.cc. + private static String fieldNameToJsonName(String name) { StringBuilder result = new StringBuilder(name.length()); boolean isNextUpperCase = false; for (int i = 0; i < name.length(); i++) { Character ch = name.charAt(i); - if (Character.isLowerCase(ch)) { - if (isNextUpperCase) { - result.append(Character.toUpperCase(ch)); - } else { - result.append(ch); - } - isNextUpperCase = false; - } else if (Character.isUpperCase(ch)) { - if (i == 0) { - // Force first letter to lower-case. - result.append(Character.toLowerCase(ch)); - } else { - // Capital letters after the first are left as-is. - result.append(ch); - } - isNextUpperCase = false; - } else if (Character.isDigit(ch)) { - result.append(ch); + if (ch == '_') { + isNextUpperCase = true; + } else if (isNextUpperCase) { + result.append(Character.toUpperCase(ch)); isNextUpperCase = false; } else { - isNextUpperCase = true; + result.append(ch); } } return result.toString(); @@ -1257,7 +1244,7 @@ public final class Descriptors { if (proto.hasJsonName()) { jsonName = proto.getJsonName(); } else { - jsonName = fieldNameToLowerCamelCase(proto.getName()); + jsonName = fieldNameToJsonName(proto.getName()); } if (proto.hasType()) { 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 5dfe7ff7..5c0b9967 100644 --- a/java/core/src/main/java/com/google/protobuf/GeneratedMessageV3.java +++ b/java/core/src/main/java/com/google/protobuf/GeneratedMessageV3.java @@ -36,7 +36,6 @@ import com.google.protobuf.Descriptors.EnumValueDescriptor; import com.google.protobuf.Descriptors.FieldDescriptor; import com.google.protobuf.Descriptors.FileDescriptor; import com.google.protobuf.Descriptors.OneofDescriptor; -import com.google.protobuf.GeneratedMessage.GeneratedExtension; import java.io.IOException; import java.io.InputStream; @@ -45,6 +44,7 @@ import java.io.Serializable; import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; import java.util.ArrayList; +import java.util.Arrays; import java.util.Collections; import java.util.Iterator; import java.util.List; @@ -1609,6 +1609,43 @@ public abstract class GeneratedMessageV3 extends AbstractMessage FieldDescriptor getDescriptor(); } + /** For use by generated code only. */ + public static + GeneratedExtension + newMessageScopedGeneratedExtension(final Message scope, + final int descriptorIndex, + final Class singularType, + final Message defaultInstance) { + // For extensions scoped within a Message, we use the Message to resolve + // the outer class's descriptor, from which the extension descriptor is + // obtained. + return new GeneratedExtension( + new CachedDescriptorRetriever() { + @Override + public FieldDescriptor loadDescriptor() { + return scope.getDescriptorForType().getExtensions().get(descriptorIndex); + } + }, + singularType, + defaultInstance, + Extension.ExtensionType.IMMUTABLE); + } + + /** For use by generated code only. */ + public static + GeneratedExtension + newFileScopedGeneratedExtension(final Class singularType, + final Message defaultInstance) { + // For extensions scoped within a file, we rely on the outer class's + // static initializer to call internalInit() on the extension when the + // descriptor is available. + return new GeneratedExtension( + null, // ExtensionDescriptorRetriever is initialized in internalInit(); + singularType, + defaultInstance, + Extension.ExtensionType.IMMUTABLE); + } + private abstract static class CachedDescriptorRetriever implements ExtensionDescriptorRetriever { private volatile FieldDescriptor descriptor; @@ -1627,6 +1664,301 @@ public abstract class GeneratedMessageV3 extends AbstractMessage } } + /** + * Used in proto1 generated code only. + * + * After enabling bridge, we can define proto2 extensions (the extended type + * is a proto2 mutable message) in a proto1 .proto file. For these extensions + * we should generate proto2 GeneratedExtensions. + */ + public static + GeneratedExtension + newMessageScopedGeneratedExtension( + final Message scope, final String name, + final Class singularType, final Message defaultInstance) { + // For extensions scoped within a Message, we use the Message to resolve + // the outer class's descriptor, from which the extension descriptor is + // obtained. + return new GeneratedExtension( + new CachedDescriptorRetriever() { + @Override + protected FieldDescriptor loadDescriptor() { + return scope.getDescriptorForType().findFieldByName(name); + } + }, + singularType, + defaultInstance, + Extension.ExtensionType.MUTABLE); + } + + /** + * Used in proto1 generated code only. + * + * After enabling bridge, we can define proto2 extensions (the extended type + * is a proto2 mutable message) in a proto1 .proto file. For these extensions + * we should generate proto2 GeneratedExtensions. + */ + public static + GeneratedExtension + newFileScopedGeneratedExtension( + final Class singularType, final Message defaultInstance, + final String descriptorOuterClass, final String extensionName) { + // For extensions scoped within a file, we load the descriptor outer + // class and rely on it to get the FileDescriptor which then can be + // used to obtain the extension's FieldDescriptor. + return new GeneratedExtension( + new CachedDescriptorRetriever() { + @Override + protected FieldDescriptor loadDescriptor() { + try { + Class clazz = singularType.getClassLoader().loadClass(descriptorOuterClass); + FileDescriptor file = (FileDescriptor) clazz.getField("descriptor").get(null); + return file.findExtensionByName(extensionName); + } catch (Exception e) { + throw new RuntimeException( + "Cannot load descriptors: " + + descriptorOuterClass + + " is not a valid descriptor class name", + e); + } + } + }, + singularType, + defaultInstance, + Extension.ExtensionType.MUTABLE); + } + + /** + * Type used to represent generated extensions. The protocol compiler + * generates a static singleton instance of this class for each extension. + * + *

For example, imagine you have the {@code .proto} file: + * + *

+   * option java_class = "MyProto";
+   *
+   * message Foo {
+   *   extensions 1000 to max;
+   * }
+   *
+   * extend Foo {
+   *   optional int32 bar;
+   * }
+   * 
+ * + *

Then, {@code MyProto.Foo.bar} has type + * {@code GeneratedExtension}. + * + *

In general, users should ignore the details of this type, and simply use + * these static singletons as parameters to the extension accessors defined + * in {@link ExtendableMessage} and {@link ExtendableBuilder}. + */ + public static class GeneratedExtension< + ContainingType extends Message, Type> extends + Extension { + // TODO(kenton): Find ways to avoid using Java reflection within this + // class. Also try to avoid suppressing unchecked warnings. + + // We can't always initialize the descriptor of a GeneratedExtension when + // we first construct it due to initialization order difficulties (namely, + // the descriptor may not have been constructed yet, since it is often + // constructed by the initializer of a separate module). + // + // In the case of nested extensions, we initialize the + // ExtensionDescriptorRetriever with an instance that uses the scoping + // Message's default instance to retrieve the extension's descriptor. + // + // In the case of non-nested extensions, we initialize the + // ExtensionDescriptorRetriever to null and rely on the outer class's static + // initializer to call internalInit() after the descriptor has been parsed. + GeneratedExtension(ExtensionDescriptorRetriever descriptorRetriever, + Class singularType, + Message messageDefaultInstance, + ExtensionType extensionType) { + if (Message.class.isAssignableFrom(singularType) && + !singularType.isInstance(messageDefaultInstance)) { + throw new IllegalArgumentException( + "Bad messageDefaultInstance for " + singularType.getName()); + } + this.descriptorRetriever = descriptorRetriever; + this.singularType = singularType; + this.messageDefaultInstance = messageDefaultInstance; + + if (ProtocolMessageEnum.class.isAssignableFrom(singularType)) { + this.enumValueOf = getMethodOrDie(singularType, "valueOf", + EnumValueDescriptor.class); + this.enumGetValueDescriptor = + getMethodOrDie(singularType, "getValueDescriptor"); + } else { + this.enumValueOf = null; + this.enumGetValueDescriptor = null; + } + this.extensionType = extensionType; + } + + /** For use by generated code only. */ + public void internalInit(final FieldDescriptor descriptor) { + if (descriptorRetriever != null) { + throw new IllegalStateException("Already initialized."); + } + descriptorRetriever = + new ExtensionDescriptorRetriever() { + @Override + public FieldDescriptor getDescriptor() { + return descriptor; + } + }; + } + + private ExtensionDescriptorRetriever descriptorRetriever; + private final Class singularType; + private final Message messageDefaultInstance; + private final Method enumValueOf; + private final Method enumGetValueDescriptor; + private final ExtensionType extensionType; + + @Override + public FieldDescriptor getDescriptor() { + if (descriptorRetriever == null) { + throw new IllegalStateException( + "getDescriptor() called before internalInit()"); + } + return descriptorRetriever.getDescriptor(); + } + + /** + * If the extension is an embedded message or group, returns the default + * instance of the message. + */ + @Override + public Message getMessageDefaultInstance() { + return messageDefaultInstance; + } + + @Override + protected ExtensionType getExtensionType() { + return extensionType; + } + + /** + * Convert from the type used by the reflection accessors to the type used + * by native accessors. E.g., for enums, the reflection accessors use + * EnumValueDescriptors but the native accessors use the generated enum + * type. + */ + @Override + @SuppressWarnings("unchecked") + protected Object fromReflectionType(final Object value) { + FieldDescriptor descriptor = getDescriptor(); + if (descriptor.isRepeated()) { + if (descriptor.getJavaType() == FieldDescriptor.JavaType.MESSAGE || + descriptor.getJavaType() == FieldDescriptor.JavaType.ENUM) { + // Must convert the whole list. + final List result = new ArrayList(); + for (final Object element : (List) value) { + result.add(singularFromReflectionType(element)); + } + return result; + } else { + return value; + } + } else { + return singularFromReflectionType(value); + } + } + + /** + * Like {@link #fromReflectionType(Object)}, but if the type is a repeated + * type, this converts a single element. + */ + @Override + protected Object singularFromReflectionType(final Object value) { + FieldDescriptor descriptor = getDescriptor(); + switch (descriptor.getJavaType()) { + case MESSAGE: + if (singularType.isInstance(value)) { + return value; + } else { + return messageDefaultInstance.newBuilderForType() + .mergeFrom((Message) value).build(); + } + case ENUM: + return invokeOrDie(enumValueOf, null, (EnumValueDescriptor) value); + default: + return value; + } + } + + /** + * Convert from the type used by the native accessors to the type used + * by reflection accessors. E.g., for enums, the reflection accessors use + * EnumValueDescriptors but the native accessors use the generated enum + * type. + */ + @Override + @SuppressWarnings("unchecked") + protected Object toReflectionType(final Object value) { + FieldDescriptor descriptor = getDescriptor(); + if (descriptor.isRepeated()) { + if (descriptor.getJavaType() == FieldDescriptor.JavaType.ENUM) { + // Must convert the whole list. + final List result = new ArrayList(); + for (final Object element : (List) value) { + result.add(singularToReflectionType(element)); + } + return result; + } else { + return value; + } + } else { + return singularToReflectionType(value); + } + } + + /** + * Like {@link #toReflectionType(Object)}, but if the type is a repeated + * type, this converts a single element. + */ + @Override + protected Object singularToReflectionType(final Object value) { + FieldDescriptor descriptor = getDescriptor(); + switch (descriptor.getJavaType()) { + case ENUM: + return invokeOrDie(enumGetValueDescriptor, value); + default: + return value; + } + } + + @Override + public int getNumber() { + return getDescriptor().getNumber(); + } + + @Override + public WireFormat.FieldType getLiteType() { + return getDescriptor().getLiteType(); + } + + @Override + public boolean isRepeated() { + return getDescriptor().isRepeated(); + } + + @Override + @SuppressWarnings("unchecked") + public Type getDefaultValue() { + if (isRepeated()) { + return (Type) Collections.emptyList(); + } + if (getDescriptor().getJavaType() == FieldDescriptor.JavaType.MESSAGE) { + return (Type) messageDefaultInstance; + } + return (Type) singularFromReflectionType( + getDescriptor().getDefaultValue()); + } + } + // ================================================================= /** Calls Class.getMethod and throws a RuntimeException if it fails. */ @@ -2223,6 +2555,20 @@ public abstract class GeneratedMessageV3 extends AbstractMessage field.getNumber()); } + private Message coerceType(Message value) { + if (value == null) { + return null; + } + if (mapEntryMessageDefaultInstance.getClass().isInstance(value)) { + return value; + } + // The value is not the exact right message type. However, if it + // is an alternative implementation of the same type -- e.g. a + // DynamicMessage -- we should accept it. In this case we can make + // a copy of the message. + return mapEntryMessageDefaultInstance.toBuilder().mergeFrom(value).build(); + } + @Override public Object get(GeneratedMessageV3 message) { List result = new ArrayList(); @@ -2278,15 +2624,15 @@ public abstract class GeneratedMessageV3 extends AbstractMessage public Object getRepeatedRaw(Builder builder, int index) { return getRepeated(builder, index); } - + @Override public void setRepeated(Builder builder, int index, Object value) { - getMutableMapField(builder).getMutableList().set(index, (Message) value); + getMutableMapField(builder).getMutableList().set(index, coerceType((Message) value)); } @Override public void addRepeated(Builder builder, Object value) { - getMutableMapField(builder).getMutableList().add((Message) value); + getMutableMapField(builder).getMutableList().add(coerceType((Message) value)); } @Override @@ -2713,4 +3059,131 @@ public abstract class GeneratedMessageV3 extends AbstractMessage output.writeBytesNoTag((ByteString) value); } } + + protected static void serializeIntegerMapTo( + CodedOutputStream out, + MapField field, + MapEntry defaultEntry, + int fieldNumber) throws IOException { + Map m = field.getMap(); + if (!out.isSerializationDeterministic()) { + serializeMapTo(out, m, defaultEntry, fieldNumber); + return; + } + // Sorting the unboxed keys and then look up the values during serialziation is 2x faster + // than sorting map entries with a custom comparator directly. + int[] keys = new int[m.size()]; + int index = 0; + for (int k : m.keySet()) { + keys[index++] = k; + } + Arrays.sort(keys); + for (int key : keys) { + out.writeMessage(fieldNumber, + defaultEntry.newBuilderForType() + .setKey(key) + .setValue(m.get(key)) + .build()); + } + } + + protected static void serializeLongMapTo( + CodedOutputStream out, + MapField field, + MapEntry defaultEntry, + int fieldNumber) + throws IOException { + Map m = field.getMap(); + if (!out.isSerializationDeterministic()) { + serializeMapTo(out, m, defaultEntry, fieldNumber); + return; + } + + long[] keys = new long[m.size()]; + int index = 0; + for (long k : m.keySet()) { + keys[index++] = k; + } + Arrays.sort(keys); + for (long key : keys) { + out.writeMessage(fieldNumber, + defaultEntry.newBuilderForType() + .setKey(key) + .setValue(m.get(key)) + .build()); + } + } + + protected static void serializeStringMapTo( + CodedOutputStream out, + MapField field, + MapEntry defaultEntry, + int fieldNumber) + throws IOException { + Map m = field.getMap(); + if (!out.isSerializationDeterministic()) { + serializeMapTo(out, m, defaultEntry, fieldNumber); + return; + } + + // Sorting the String keys and then look up the values during serialziation is 25% faster than + // sorting map entries with a custom comparator directly. + String[] keys = new String[m.size()]; + keys = m.keySet().toArray(keys); + Arrays.sort(keys); + for (String key : keys) { + out.writeMessage(fieldNumber, + defaultEntry.newBuilderForType() + .setKey(key) + .setValue(m.get(key)) + .build()); + } + } + + protected static void serializeBooleanMapTo( + CodedOutputStream out, + MapField field, + MapEntry defaultEntry, + int fieldNumber) + throws IOException { + Map m = field.getMap(); + if (!out.isSerializationDeterministic()) { + serializeMapTo(out, m, defaultEntry, fieldNumber); + return; + } + maybeSerializeBooleanEntryTo(out, m, defaultEntry, fieldNumber, false); + maybeSerializeBooleanEntryTo(out, m, defaultEntry, fieldNumber, true); + } + + private static void maybeSerializeBooleanEntryTo( + CodedOutputStream out, + Map m, + MapEntry defaultEntry, + int fieldNumber, + boolean key) + throws IOException { + if (m.containsKey(key)) { + out.writeMessage(fieldNumber, + defaultEntry.newBuilderForType() + .setKey(key) + .setValue(m.get(key)) + .build()); + } + } + + /** Serialize the map using the iteration order. */ + private static void serializeMapTo( + CodedOutputStream out, + Map m, + MapEntry defaultEntry, + int fieldNumber) + throws IOException { + for (Map.Entry entry : m.entrySet()) { + out.writeMessage(fieldNumber, + defaultEntry.newBuilderForType() + .setKey(entry.getKey()) + .setValue(entry.getValue()) + .build()); + } + } } diff --git a/java/core/src/main/java/com/google/protobuf/Internal.java b/java/core/src/main/java/com/google/protobuf/Internal.java index 3b4a0412..c234559c 100644 --- a/java/core/src/main/java/com/google/protobuf/Internal.java +++ b/java/core/src/main/java/com/google/protobuf/Internal.java @@ -59,6 +59,16 @@ public final class Internal { static final Charset UTF_8 = Charset.forName("UTF-8"); static final Charset ISO_8859_1 = Charset.forName("ISO-8859-1"); + /** + * Throws an appropriate {@link NullPointerException} if the given objects is {@code null}. + */ + static T checkNotNull(T obj, String message) { + if (obj == null) { + throw new NullPointerException(message); + } + return obj; + } + /** * Helper called by generated code to construct default values for string * fields. diff --git a/java/core/src/main/java/com/google/protobuf/InvalidProtocolBufferException.java b/java/core/src/main/java/com/google/protobuf/InvalidProtocolBufferException.java index 85ce7b24..55e33d21 100644 --- a/java/core/src/main/java/com/google/protobuf/InvalidProtocolBufferException.java +++ b/java/core/src/main/java/com/google/protobuf/InvalidProtocolBufferException.java @@ -107,11 +107,23 @@ public class InvalidProtocolBufferException extends IOException { "Protocol message end-group tag did not match expected tag."); } - static InvalidProtocolBufferException invalidWireType() { - return new InvalidProtocolBufferException( + static InvalidWireTypeException invalidWireType() { + return new InvalidWireTypeException( "Protocol message tag had invalid wire type."); } + /** + * Exception indicating that and unexpected wire type was encountered for a field. + */ + @ExperimentalApi + public static class InvalidWireTypeException extends InvalidProtocolBufferException { + private static final long serialVersionUID = 3283890091615336259L; + + public InvalidWireTypeException(String description) { + super(description); + } + } + static InvalidProtocolBufferException recursionLimitExceeded() { return new InvalidProtocolBufferException( "Protocol message had too many levels of nesting. May be malicious. " + diff --git a/java/core/src/main/java/com/google/protobuf/MapEntry.java b/java/core/src/main/java/com/google/protobuf/MapEntry.java index 117cd911..4f0351f4 100644 --- a/java/core/src/main/java/com/google/protobuf/MapEntry.java +++ b/java/core/src/main/java/com/google/protobuf/MapEntry.java @@ -334,6 +334,15 @@ public final class MapEntry extends AbstractMessage { } else { if (field.getType() == FieldDescriptor.Type.ENUM) { value = ((EnumValueDescriptor) value).getNumber(); + } else if (field.getType() == FieldDescriptor.Type.MESSAGE) { + if (value != null && !metadata.defaultValue.getClass().isInstance(value)) { + // The value is not the exact right message type. However, if it + // is an alternative implementation of the same type -- e.g. a + // DynamicMessage -- we should accept it. In this case we can make + // a copy of the message. + value = + ((Message) metadata.defaultValue).toBuilder().mergeFrom((Message) value).build(); + } } setValue((V) value); } diff --git a/java/core/src/main/java/com/google/protobuf/NioByteString.java b/java/core/src/main/java/com/google/protobuf/NioByteString.java index 6163c7b1..76594809 100644 --- a/java/core/src/main/java/com/google/protobuf/NioByteString.java +++ b/java/core/src/main/java/com/google/protobuf/NioByteString.java @@ -30,6 +30,8 @@ package com.google.protobuf; +import static com.google.protobuf.Internal.checkNotNull; + import java.io.IOException; import java.io.InputStream; import java.io.InvalidObjectException; @@ -49,10 +51,9 @@ final class NioByteString extends ByteString.LeafByteString { private final ByteBuffer buffer; NioByteString(ByteBuffer buffer) { - if (buffer == null) { - throw new NullPointerException("buffer"); - } + checkNotNull(buffer, "buffer"); + // Use native byte order for fast fixed32/64 operations. this.buffer = buffer.slice().order(ByteOrder.nativeOrder()); } @@ -266,7 +267,7 @@ final class NioByteString extends ByteString.LeafByteString { @Override public CodedInputStream newCodedInput() { - return CodedInputStream.newInstance(buffer); + return CodedInputStream.newInstance(buffer, true); } /** 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 3f3e9bd1..6fa555df 100644 --- a/java/core/src/main/java/com/google/protobuf/RopeByteString.java +++ b/java/core/src/main/java/com/google/protobuf/RopeByteString.java @@ -406,6 +406,7 @@ final class RopeByteString extends ByteString { right.writeTo(output); } + @Override protected String toStringInternal(Charset charset) { return new String(toByteArray(), charset); diff --git a/java/core/src/main/java/com/google/protobuf/TextFormat.java b/java/core/src/main/java/com/google/protobuf/TextFormat.java index ff13675d..49708242 100644 --- a/java/core/src/main/java/com/google/protobuf/TextFormat.java +++ b/java/core/src/main/java/com/google/protobuf/TextFormat.java @@ -1576,14 +1576,22 @@ public final class TextFormat { // Support specifying repeated field values as a comma-separated list. // Ex."foo: [1, 2, 3]" if (field.isRepeated() && tokenizer.tryConsume("[")) { - while (true) { - consumeFieldValue(tokenizer, extensionRegistry, target, field, extension, - parseTreeBuilder, unknownFields); - if (tokenizer.tryConsume("]")) { - // End of list. - break; + if (!tokenizer.tryConsume("]")) { // Allow "foo: []" to be treated as empty. + while (true) { + consumeFieldValue( + tokenizer, + extensionRegistry, + target, + field, + extension, + parseTreeBuilder, + unknownFields); + if (tokenizer.tryConsume("]")) { + // End of list. + break; + } + tokenizer.consume(","); } - tokenizer.consume(","); } } else { consumeFieldValue(tokenizer, extensionRegistry, target, field, diff --git a/java/core/src/main/java/com/google/protobuf/TextFormatParseInfoTree.java b/java/core/src/main/java/com/google/protobuf/TextFormatParseInfoTree.java index 5c43b2c3..0127ce92 100644 --- a/java/core/src/main/java/com/google/protobuf/TextFormatParseInfoTree.java +++ b/java/core/src/main/java/com/google/protobuf/TextFormatParseInfoTree.java @@ -45,7 +45,8 @@ import java.util.Map.Entry; * *

The locations of primary fields values are retrieved by {@code getLocation} or * {@code getLocations}. The locations of sub message values are within nested - * {@code TextFormatParseInfoTree}s and are retrieve by {@code getNestedTree} or {@code getNestedTrees}. + * {@code TextFormatParseInfoTree}s and are retrieve by {@code getNestedTree} or + * {@code getNestedTrees}. * *

The {@code TextFormatParseInfoTree} is created by a Builder. */ diff --git a/java/core/src/main/java/com/google/protobuf/UnsafeByteOperations.java b/java/core/src/main/java/com/google/protobuf/UnsafeByteOperations.java index e72a6b4d..878c7758 100644 --- a/java/core/src/main/java/com/google/protobuf/UnsafeByteOperations.java +++ b/java/core/src/main/java/com/google/protobuf/UnsafeByteOperations.java @@ -64,6 +64,29 @@ import java.nio.ByteBuffer; public final class UnsafeByteOperations { private UnsafeByteOperations() {} + /** + * An unsafe operation that returns a {@link ByteString} that is backed by the provided buffer. + * + * @param buffer the buffer to be wrapped + * @return a {@link ByteString} backed by the provided buffer + */ + public static ByteString unsafeWrap(byte[] buffer) { + return ByteString.wrap(buffer); + } + + /** + * An unsafe operation that returns a {@link ByteString} that is backed by a subregion of the + * provided buffer. + * + * @param buffer the buffer to be wrapped + * @param offset the offset of the wrapped region + * @param length the number of bytes of the wrapped region + * @return a {@link ByteString} backed by the provided buffer + */ + public static ByteString unsafeWrap(byte[] buffer, int offset, int length) { + return ByteString.wrap(buffer, offset, length); + } + /** * An unsafe operation that returns a {@link ByteString} that is backed by the provided buffer. * @@ -71,12 +94,7 @@ public final class UnsafeByteOperations { * @return a {@link ByteString} backed by the provided buffer */ public static ByteString unsafeWrap(ByteBuffer buffer) { - if (buffer.hasArray()) { - final int offset = buffer.arrayOffset(); - return ByteString.wrap(buffer.array(), offset + buffer.position(), buffer.remaining()); - } else { - return new NioByteString(buffer); - } + return ByteString.wrap(buffer); } /** @@ -98,4 +116,5 @@ public final class UnsafeByteOperations { public static void unsafeWriteTo(ByteString bytes, ByteOutput output) throws IOException { bytes.writeTo(output); } + } diff --git a/java/core/src/main/java/com/google/protobuf/UnsafeUtil.java b/java/core/src/main/java/com/google/protobuf/UnsafeUtil.java index 6a4787d1..5f7bafd6 100644 --- a/java/core/src/main/java/com/google/protobuf/UnsafeUtil.java +++ b/java/core/src/main/java/com/google/protobuf/UnsafeUtil.java @@ -30,17 +30,14 @@ package com.google.protobuf; -import sun.misc.Unsafe; - import java.lang.reflect.Field; import java.nio.Buffer; import java.nio.ByteBuffer; import java.security.AccessController; import java.security.PrivilegedExceptionAction; +import sun.misc.Unsafe; -/** - * Utility class for working with unsafe operations. - */ +/** Utility class for working with unsafe operations. */ // TODO(nathanmittler): Add support for Android Memory/MemoryBlock final class UnsafeUtil { private static final sun.misc.Unsafe UNSAFE = getUnsafe(); @@ -50,8 +47,7 @@ final class UnsafeUtil { private static final long ARRAY_BASE_OFFSET = byteArrayBaseOffset(); private static final long BUFFER_ADDRESS_OFFSET = fieldOffset(field(Buffer.class, "address")); - private UnsafeUtil() { - } + private UnsafeUtil() {} static boolean hasUnsafeArrayOperations() { return HAS_UNSAFE_ARRAY_OPERATIONS; @@ -61,27 +57,83 @@ final class UnsafeUtil { return HAS_UNSAFE_BYTEBUFFER_OPERATIONS; } + static Object allocateInstance(Class clazz) { + try { + return UNSAFE.allocateInstance(clazz); + } catch (InstantiationException e) { + throw new RuntimeException(e); + } + } + + static long objectFieldOffset(Field field) { + return UNSAFE.objectFieldOffset(field); + } + static long getArrayBaseOffset() { return ARRAY_BASE_OFFSET; } - static byte getByte(byte[] target, long offset) { + static byte getByte(Object target, long offset) { return UNSAFE.getByte(target, offset); } - static void putByte(byte[] target, long offset, byte value) { + static void putByte(Object target, long offset, byte value) { UNSAFE.putByte(target, offset, value); } - static void copyMemory( - byte[] src, long srcOffset, byte[] target, long targetOffset, long length) { - UNSAFE.copyMemory(src, srcOffset, target, targetOffset, length); + static int getInt(Object target, long offset) { + return UNSAFE.getInt(target, offset); } - static long getLong(byte[] target, long offset) { + static void putInt(Object target, long offset, int value) { + UNSAFE.putInt(target, offset, value); + } + + static long getLong(Object target, long offset) { return UNSAFE.getLong(target, offset); } + static void putLong(Object target, long offset, long value) { + UNSAFE.putLong(target, offset, value); + } + + static boolean getBoolean(Object target, long offset) { + return UNSAFE.getBoolean(target, offset); + } + + static void putBoolean(Object target, long offset, boolean value) { + UNSAFE.putBoolean(target, offset, value); + } + + static float getFloat(Object target, long offset) { + return UNSAFE.getFloat(target, offset); + } + + static void putFloat(Object target, long offset, float value) { + UNSAFE.putFloat(target, offset, value); + } + + static double getDouble(Object target, long offset) { + return UNSAFE.getDouble(target, offset); + } + + static void putDouble(Object target, long offset, double value) { + UNSAFE.putDouble(target, offset, value); + } + + static Object getObject(Object target, long offset) { + return UNSAFE.getObject(target, offset); + } + + static void putObject(Object target, long offset, Object value) { + UNSAFE.putObject(target, offset, value); + } + + static void copyMemory( + Object src, long srcOffset, Object target, long targetOffset, long length) { + UNSAFE.copyMemory(src, srcOffset, target, targetOffset, length); + } + static byte getByte(long address) { return UNSAFE.getByte(address); } @@ -90,14 +142,30 @@ final class UnsafeUtil { UNSAFE.putByte(address, value); } + static int getInt(long address) { + return UNSAFE.getInt(address); + } + + static void putInt(long address, int value) { + UNSAFE.putInt(address, value); + } + static long getLong(long address) { return UNSAFE.getLong(address); } + static void putLong(long address, long value) { + UNSAFE.putLong(address, value); + } + static void copyMemory(long srcAddress, long targetAddress, long length) { UNSAFE.copyMemory(srcAddress, targetAddress, length); } + static void setMemory(long address, long numBytes, byte value) { + UNSAFE.setMemory(address, numBytes, value); + } + /** * Gets the offset of the {@code address} field of the given direct {@link ByteBuffer}. */ @@ -136,18 +204,29 @@ final class UnsafeUtil { return unsafe; } - /** - * Indicates whether or not unsafe array operations are supported on this platform. - */ + /** Indicates whether or not unsafe array operations are supported on this platform. */ private static boolean supportsUnsafeArrayOperations() { boolean supported = false; if (UNSAFE != null) { try { Class clazz = UNSAFE.getClass(); + clazz.getMethod("objectFieldOffset", Field.class); + clazz.getMethod("allocateInstance", Class.class); clazz.getMethod("arrayBaseOffset", Class.class); clazz.getMethod("getByte", Object.class, long.class); clazz.getMethod("putByte", Object.class, long.class, byte.class); + clazz.getMethod("getBoolean", Object.class, long.class); + clazz.getMethod("putBoolean", Object.class, long.class, boolean.class); + clazz.getMethod("getInt", Object.class, long.class); + clazz.getMethod("putInt", Object.class, long.class, int.class); clazz.getMethod("getLong", Object.class, long.class); + clazz.getMethod("putLong", Object.class, long.class, long.class); + clazz.getMethod("getFloat", Object.class, long.class); + clazz.getMethod("putFloat", Object.class, long.class, float.class); + clazz.getMethod("getDouble", Object.class, long.class); + clazz.getMethod("putDouble", Object.class, long.class, double.class); + clazz.getMethod("getObject", Object.class, long.class); + clazz.getMethod("putObject", Object.class, long.class, Object.class); clazz.getMethod( "copyMemory", Object.class, long.class, Object.class, long.class, long.class); supported = true; @@ -163,11 +242,17 @@ final class UnsafeUtil { if (UNSAFE != null) { try { Class clazz = UNSAFE.getClass(); + // Methods for getting direct buffer address. clazz.getMethod("objectFieldOffset", Field.class); - clazz.getMethod("getByte", long.class); clazz.getMethod("getLong", Object.class, long.class); + + clazz.getMethod("getByte", long.class); clazz.getMethod("putByte", long.class, byte.class); + clazz.getMethod("getInt", long.class); + clazz.getMethod("putInt", long.class, int.class); clazz.getMethod("getLong", long.class); + clazz.getMethod("putLong", long.class, long.class); + clazz.getMethod("setMemory", long.class, long.class, byte.class); clazz.getMethod("copyMemory", long.class, long.class, long.class); supported = true; } catch (Throwable e) { diff --git a/java/core/src/main/java/com/google/protobuf/WireFormat.java b/java/core/src/main/java/com/google/protobuf/WireFormat.java index 6a58b081..0b0cdb7d 100644 --- a/java/core/src/main/java/com/google/protobuf/WireFormat.java +++ b/java/core/src/main/java/com/google/protobuf/WireFormat.java @@ -47,6 +47,10 @@ public final class WireFormat { // Do not allow instantiation. private WireFormat() {} + static final int FIXED_32_SIZE = 4; + static final int FIXED_64_SIZE = 8; + static final int MAX_VARINT_SIZE = 10; + public static final int WIRETYPE_VARINT = 0; public static final int WIRETYPE_FIXED64 = 1; public static final int WIRETYPE_LENGTH_DELIMITED = 2; diff --git a/java/core/src/test/java/com/google/protobuf/AbstractMessageTest.java b/java/core/src/test/java/com/google/protobuf/AbstractMessageTest.java index 7dc9fc15..622e36a4 100644 --- a/java/core/src/test/java/com/google/protobuf/AbstractMessageTest.java +++ b/java/core/src/test/java/com/google/protobuf/AbstractMessageTest.java @@ -40,9 +40,8 @@ import protobuf_unittest.UnittestProto.TestPackedTypes; import protobuf_unittest.UnittestProto.TestRequired; import protobuf_unittest.UnittestProto.TestRequiredForeign; import protobuf_unittest.UnittestProto.TestUnpackedTypes; -import junit.framework.TestCase; - import java.util.Map; +import junit.framework.TestCase; /** * Unit test for {@link AbstractMessage}. @@ -492,7 +491,6 @@ public class AbstractMessageTest extends TestCase { checkEqualsIsConsistent(eUnknownFields, eUnknownFields2); } - /** * Asserts that the given proto has symmetric equals and hashCode methods. */ diff --git a/java/core/src/test/java/com/google/protobuf/BooleanArrayListTest.java b/java/core/src/test/java/com/google/protobuf/BooleanArrayListTest.java index ec139225..18132e9e 100644 --- a/java/core/src/test/java/com/google/protobuf/BooleanArrayListTest.java +++ b/java/core/src/test/java/com/google/protobuf/BooleanArrayListTest.java @@ -32,11 +32,10 @@ package com.google.protobuf; import static java.util.Arrays.asList; -import junit.framework.TestCase; - import java.util.Collections; import java.util.ConcurrentModificationException; import java.util.Iterator; +import junit.framework.TestCase; /** * Tests for {@link BooleanArrayList}. diff --git a/java/core/src/test/java/com/google/protobuf/ByteBufferWriterTest.java b/java/core/src/test/java/com/google/protobuf/ByteBufferWriterTest.java index cbe742e5..6b1cfe78 100644 --- a/java/core/src/test/java/com/google/protobuf/ByteBufferWriterTest.java +++ b/java/core/src/test/java/com/google/protobuf/ByteBufferWriterTest.java @@ -30,13 +30,12 @@ package com.google.protobuf; -import junit.framework.TestCase; - import java.io.ByteArrayOutputStream; import java.io.IOException; import java.nio.ByteBuffer; import java.util.Arrays; import java.util.Random; +import junit.framework.TestCase; /** * Tests for {@link ByteBufferWriter}. diff --git a/java/core/src/test/java/com/google/protobuf/ByteStringTest.java b/java/core/src/test/java/com/google/protobuf/ByteStringTest.java index ad9f266e..be71f1f5 100644 --- a/java/core/src/test/java/com/google/protobuf/ByteStringTest.java +++ b/java/core/src/test/java/com/google/protobuf/ByteStringTest.java @@ -31,9 +31,6 @@ package com.google.protobuf; import com.google.protobuf.ByteString.Output; - -import junit.framework.TestCase; - import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; import java.io.IOException; @@ -48,6 +45,7 @@ import java.util.Iterator; import java.util.List; import java.util.NoSuchElementException; import java.util.Random; +import junit.framework.TestCase; /** * Test methods with implementations in {@link ByteString}, plus do some top-level "integration" diff --git a/java/core/src/test/java/com/google/protobuf/CodedInputStreamTest.java b/java/core/src/test/java/com/google/protobuf/CodedInputStreamTest.java index ca940ced..e2ab0df9 100644 --- a/java/core/src/test/java/com/google/protobuf/CodedInputStreamTest.java +++ b/java/core/src/test/java/com/google/protobuf/CodedInputStreamTest.java @@ -30,20 +30,20 @@ package com.google.protobuf; +import static org.junit.Assert.assertArrayEquals; + import protobuf_unittest.UnittestProto.BoolMessage; import protobuf_unittest.UnittestProto.Int32Message; import protobuf_unittest.UnittestProto.Int64Message; import protobuf_unittest.UnittestProto.TestAllTypes; import protobuf_unittest.UnittestProto.TestRecursiveMessage; - -import junit.framework.TestCase; - import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; import java.io.FilterInputStream; import java.io.IOException; import java.io.InputStream; import java.nio.ByteBuffer; +import junit.framework.TestCase; /** * Unit test for {@link CodedInputStream}. @@ -51,10 +51,45 @@ import java.nio.ByteBuffer; * @author kenton@google.com Kenton Varda */ public class CodedInputStreamTest extends TestCase { + private enum InputType { + ARRAY { + @Override + CodedInputStream newDecoder(byte[] data, int blockSize) { + return CodedInputStream.newInstance(data); + } + }, + NIO_HEAP { + @Override + CodedInputStream newDecoder(byte[] data, int blockSize) { + return CodedInputStream.newInstance(ByteBuffer.wrap(data)); + } + }, + NIO_DIRECT { + @Override + CodedInputStream newDecoder(byte[] data, int blockSize) { + ByteBuffer buffer = ByteBuffer.allocateDirect(data.length); + buffer.put(data); + buffer.flip(); + return CodedInputStream.newInstance(buffer); + } + }, + STREAM { + @Override + CodedInputStream newDecoder(byte[] data, int blockSize) { + return CodedInputStream.newInstance(new SmallBlockInputStream(data, blockSize)); + } + }; + + CodedInputStream newDecoder(byte[] data) { + return newDecoder(data, data.length); + } + + abstract CodedInputStream newDecoder(byte[] data, int blockSize); + } + /** - * Helper to construct a byte array from a bunch of bytes. The inputs are - * actually ints so that I can use hex notation and not get stupid errors - * about precision. + * Helper to construct a byte array from a bunch of bytes. The inputs are actually ints so that I + * can use hex notation and not get stupid errors about precision. */ private byte[] bytes(int... bytesAsInts) { byte[] bytes = new byte[bytesAsInts.length]; @@ -65,19 +100,14 @@ public class CodedInputStreamTest extends TestCase { } /** - * An InputStream which limits the number of bytes it reads at a time. - * We use this to make sure that CodedInputStream doesn't screw up when - * reading in small blocks. + * An InputStream which limits the number of bytes it reads at a time. We use this to make sure + * that CodedInputStream doesn't screw up when reading in small blocks. */ private static final class SmallBlockInputStream extends FilterInputStream { private final int blockSize; public SmallBlockInputStream(byte[] data, int blockSize) { - this(new ByteArrayInputStream(data), blockSize); - } - - public SmallBlockInputStream(InputStream in, int blockSize) { - super(in); + super(new ByteArrayInputStream(data)); this.blockSize = blockSize; } @@ -92,54 +122,36 @@ public class CodedInputStreamTest extends TestCase { } } - private void assertDataConsumed(byte[] data, CodedInputStream input) + private void assertDataConsumed(String msg, byte[] data, CodedInputStream input) throws IOException { - assertEquals(data.length, input.getTotalBytesRead()); - assertTrue(input.isAtEnd()); + assertEquals(msg, data.length, input.getTotalBytesRead()); + assertTrue(msg, input.isAtEnd()); } /** - * Parses the given bytes using readRawVarint32() and readRawVarint64() and - * checks that the result matches the given value. + * Parses the given bytes using readRawVarint32() and readRawVarint64() and checks that the result + * matches the given value. */ private void assertReadVarint(byte[] data, long value) throws Exception { - CodedInputStream input = CodedInputStream.newInstance(data); - assertEquals((int) value, input.readRawVarint32()); - assertDataConsumed(data, input); - - input = CodedInputStream.newInstance(data); - assertEquals(value, input.readRawVarint64()); - assertDataConsumed(data, input); - - input = CodedInputStream.newInstance(data); - assertEquals(value, input.readRawVarint64SlowPath()); - assertDataConsumed(data, input); - - input = CodedInputStream.newInstance(data); - assertTrue(input.skipField(WireFormat.WIRETYPE_VARINT)); - assertDataConsumed(data, input); - - // Try different block sizes. - for (int blockSize = 1; blockSize <= 16; blockSize *= 2) { - input = CodedInputStream.newInstance( - new SmallBlockInputStream(data, blockSize)); - assertEquals((int) value, input.readRawVarint32()); - assertDataConsumed(data, input); - - input = CodedInputStream.newInstance( - new SmallBlockInputStream(data, blockSize)); - assertEquals(value, input.readRawVarint64()); - assertDataConsumed(data, input); - - input = CodedInputStream.newInstance( - new SmallBlockInputStream(data, blockSize)); - assertEquals(value, input.readRawVarint64SlowPath()); - assertDataConsumed(data, input); - - input = CodedInputStream.newInstance( - new SmallBlockInputStream(data, blockSize)); - assertTrue(input.skipField(WireFormat.WIRETYPE_VARINT)); - assertDataConsumed(data, input); + for (InputType inputType : InputType.values()) { + // Try different block sizes. + for (int blockSize = 1; blockSize <= 16; blockSize *= 2) { + CodedInputStream input = inputType.newDecoder(data, blockSize); + assertEquals(inputType.name(), (int) value, input.readRawVarint32()); + assertDataConsumed(inputType.name(), data, input); + + input = inputType.newDecoder(data, blockSize); + assertEquals(inputType.name(), value, input.readRawVarint64()); + assertDataConsumed(inputType.name(), data, input); + + input = inputType.newDecoder(data, blockSize); + assertEquals(inputType.name(), value, input.readRawVarint64SlowPath()); + assertDataConsumed(inputType.name(), data, input); + + input = inputType.newDecoder(data, blockSize); + assertTrue(inputType.name(), input.skipField(WireFormat.WIRETYPE_VARINT)); + assertDataConsumed(inputType.name(), data, input); + } } // Try reading direct from an InputStream. We want to verify that it @@ -153,35 +165,26 @@ public class CodedInputStreamTest extends TestCase { } /** - * Parses the given bytes using readRawVarint32() and readRawVarint64() and - * expects them to fail with an InvalidProtocolBufferException whose - * description matches the given one. + * Parses the given bytes using readRawVarint32() and readRawVarint64() and expects them to fail + * with an InvalidProtocolBufferException whose description matches the given one. */ - private void assertReadVarintFailure( - InvalidProtocolBufferException expected, byte[] data) + private void assertReadVarintFailure(InvalidProtocolBufferException expected, byte[] data) throws Exception { - CodedInputStream input = CodedInputStream.newInstance(data); - try { - input.readRawVarint32(); - fail("Should have thrown an exception."); - } catch (InvalidProtocolBufferException e) { - assertEquals(expected.getMessage(), e.getMessage()); - } - - input = CodedInputStream.newInstance(data); - try { - input.readRawVarint64(); - fail("Should have thrown an exception."); - } catch (InvalidProtocolBufferException e) { - assertEquals(expected.getMessage(), e.getMessage()); - } - - input = CodedInputStream.newInstance(data); - try { - input.readRawVarint64SlowPath(); - fail("Should have thrown an exception."); - } catch (InvalidProtocolBufferException e) { - assertEquals(expected.getMessage(), e.getMessage()); + for (InputType inputType : InputType.values()) { + try { + CodedInputStream input = inputType.newDecoder(data); + input.readRawVarint32(); + fail(inputType.name() + ": Should have thrown an exception."); + } catch (InvalidProtocolBufferException e) { + assertEquals(inputType.name(), expected.getMessage(), e.getMessage()); + } + try { + CodedInputStream input = inputType.newDecoder(data); + input.readRawVarint64(); + fail(inputType.name() + ": Should have thrown an exception."); + } catch (InvalidProtocolBufferException e) { + assertEquals(inputType.name(), expected.getMessage(), e.getMessage()); + } } // Make sure we get the same error when reading direct from an InputStream. @@ -201,72 +204,74 @@ public class CodedInputStreamTest extends TestCase { // 14882 assertReadVarint(bytes(0xa2, 0x74), (0x22 << 0) | (0x74 << 7)); // 2961488830 - assertReadVarint(bytes(0xbe, 0xf7, 0x92, 0x84, 0x0b), - (0x3e << 0) | (0x77 << 7) | (0x12 << 14) | (0x04 << 21) | - (0x0bL << 28)); + assertReadVarint( + bytes(0xbe, 0xf7, 0x92, 0x84, 0x0b), + (0x3e << 0) | (0x77 << 7) | (0x12 << 14) | (0x04 << 21) | (0x0bL << 28)); // 64-bit // 7256456126 - assertReadVarint(bytes(0xbe, 0xf7, 0x92, 0x84, 0x1b), - (0x3e << 0) | (0x77 << 7) | (0x12 << 14) | (0x04 << 21) | - (0x1bL << 28)); + assertReadVarint( + bytes(0xbe, 0xf7, 0x92, 0x84, 0x1b), + (0x3e << 0) | (0x77 << 7) | (0x12 << 14) | (0x04 << 21) | (0x1bL << 28)); // 41256202580718336 assertReadVarint( - bytes(0x80, 0xe6, 0xeb, 0x9c, 0xc3, 0xc9, 0xa4, 0x49), - (0x00 << 0) | (0x66 << 7) | (0x6b << 14) | (0x1c << 21) | - (0x43L << 28) | (0x49L << 35) | (0x24L << 42) | (0x49L << 49)); + bytes(0x80, 0xe6, 0xeb, 0x9c, 0xc3, 0xc9, 0xa4, 0x49), + (0x00 << 0) + | (0x66 << 7) + | (0x6b << 14) + | (0x1c << 21) + | (0x43L << 28) + | (0x49L << 35) + | (0x24L << 42) + | (0x49L << 49)); // 11964378330978735131 assertReadVarint( - bytes(0x9b, 0xa8, 0xf9, 0xc2, 0xbb, 0xd6, 0x80, 0x85, 0xa6, 0x01), - (0x1b << 0) | (0x28 << 7) | (0x79 << 14) | (0x42 << 21) | - (0x3bL << 28) | (0x56L << 35) | (0x00L << 42) | - (0x05L << 49) | (0x26L << 56) | (0x01L << 63)); + bytes(0x9b, 0xa8, 0xf9, 0xc2, 0xbb, 0xd6, 0x80, 0x85, 0xa6, 0x01), + (0x1b << 0) + | (0x28 << 7) + | (0x79 << 14) + | (0x42 << 21) + | (0x3bL << 28) + | (0x56L << 35) + | (0x00L << 42) + | (0x05L << 49) + | (0x26L << 56) + | (0x01L << 63)); // Failures assertReadVarintFailure( - InvalidProtocolBufferException.malformedVarint(), - bytes(0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, - 0x00)); - assertReadVarintFailure( - InvalidProtocolBufferException.truncatedMessage(), - bytes(0x80)); + InvalidProtocolBufferException.malformedVarint(), + bytes(0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x00)); + assertReadVarintFailure(InvalidProtocolBufferException.truncatedMessage(), bytes(0x80)); } /** - * Parses the given bytes using readRawLittleEndian32() and checks - * that the result matches the given value. + * Parses the given bytes using readRawLittleEndian32() and checks that the result matches the + * given value. */ - private void assertReadLittleEndian32(byte[] data, int value) - throws Exception { - CodedInputStream input = CodedInputStream.newInstance(data); - assertEquals(value, input.readRawLittleEndian32()); - assertTrue(input.isAtEnd()); - - // Try different block sizes. - for (int blockSize = 1; blockSize <= 16; blockSize *= 2) { - input = CodedInputStream.newInstance( - new SmallBlockInputStream(data, blockSize)); - assertEquals(value, input.readRawLittleEndian32()); - assertTrue(input.isAtEnd()); + private void assertReadLittleEndian32(byte[] data, int value) throws Exception { + for (InputType inputType : InputType.values()) { + // Try different block sizes. + for (int blockSize = 1; blockSize <= 16; blockSize *= 2) { + CodedInputStream input = inputType.newDecoder(data, blockSize); + assertEquals(inputType.name(), value, input.readRawLittleEndian32()); + assertTrue(inputType.name(), input.isAtEnd()); + } } } /** - * Parses the given bytes using readRawLittleEndian64() and checks - * that the result matches the given value. + * Parses the given bytes using readRawLittleEndian64() and checks that the result matches the + * given value. */ - private void assertReadLittleEndian64(byte[] data, long value) - throws Exception { - CodedInputStream input = CodedInputStream.newInstance(data); - assertEquals(value, input.readRawLittleEndian64()); - assertTrue(input.isAtEnd()); - - // Try different block sizes. - for (int blockSize = 1; blockSize <= 16; blockSize *= 2) { - input = CodedInputStream.newInstance( - new SmallBlockInputStream(data, blockSize)); - assertEquals(value, input.readRawLittleEndian64()); - assertTrue(input.isAtEnd()); + private void assertReadLittleEndian64(byte[] data, long value) throws Exception { + for (InputType inputType : InputType.values()) { + // Try different block sizes. + for (int blockSize = 1; blockSize <= 16; blockSize *= 2) { + CodedInputStream input = inputType.newDecoder(data, blockSize); + assertEquals(inputType.name(), value, input.readRawLittleEndian64()); + assertTrue(inputType.name(), input.isAtEnd()); + } } } @@ -276,40 +281,32 @@ public class CodedInputStreamTest extends TestCase { assertReadLittleEndian32(bytes(0xf0, 0xde, 0xbc, 0x9a), 0x9abcdef0); assertReadLittleEndian64( - bytes(0xf0, 0xde, 0xbc, 0x9a, 0x78, 0x56, 0x34, 0x12), - 0x123456789abcdef0L); + bytes(0xf0, 0xde, 0xbc, 0x9a, 0x78, 0x56, 0x34, 0x12), 0x123456789abcdef0L); assertReadLittleEndian64( - bytes(0x78, 0x56, 0x34, 0x12, 0xf0, 0xde, 0xbc, 0x9a), - 0x9abcdef012345678L); + bytes(0x78, 0x56, 0x34, 0x12, 0xf0, 0xde, 0xbc, 0x9a), 0x9abcdef012345678L); } /** Test decodeZigZag32() and decodeZigZag64(). */ public void testDecodeZigZag() throws Exception { - assertEquals( 0, CodedInputStream.decodeZigZag32(0)); + assertEquals(0, CodedInputStream.decodeZigZag32(0)); assertEquals(-1, CodedInputStream.decodeZigZag32(1)); - assertEquals( 1, CodedInputStream.decodeZigZag32(2)); + assertEquals(1, CodedInputStream.decodeZigZag32(2)); assertEquals(-2, CodedInputStream.decodeZigZag32(3)); assertEquals(0x3FFFFFFF, CodedInputStream.decodeZigZag32(0x7FFFFFFE)); assertEquals(0xC0000000, CodedInputStream.decodeZigZag32(0x7FFFFFFF)); assertEquals(0x7FFFFFFF, CodedInputStream.decodeZigZag32(0xFFFFFFFE)); assertEquals(0x80000000, CodedInputStream.decodeZigZag32(0xFFFFFFFF)); - assertEquals( 0, CodedInputStream.decodeZigZag64(0)); + assertEquals(0, CodedInputStream.decodeZigZag64(0)); assertEquals(-1, CodedInputStream.decodeZigZag64(1)); - assertEquals( 1, CodedInputStream.decodeZigZag64(2)); + assertEquals(1, CodedInputStream.decodeZigZag64(2)); assertEquals(-2, CodedInputStream.decodeZigZag64(3)); - assertEquals(0x000000003FFFFFFFL, - CodedInputStream.decodeZigZag64(0x000000007FFFFFFEL)); - assertEquals(0xFFFFFFFFC0000000L, - CodedInputStream.decodeZigZag64(0x000000007FFFFFFFL)); - assertEquals(0x000000007FFFFFFFL, - CodedInputStream.decodeZigZag64(0x00000000FFFFFFFEL)); - assertEquals(0xFFFFFFFF80000000L, - CodedInputStream.decodeZigZag64(0x00000000FFFFFFFFL)); - assertEquals(0x7FFFFFFFFFFFFFFFL, - CodedInputStream.decodeZigZag64(0xFFFFFFFFFFFFFFFEL)); - assertEquals(0x8000000000000000L, - CodedInputStream.decodeZigZag64(0xFFFFFFFFFFFFFFFFL)); + assertEquals(0x000000003FFFFFFFL, CodedInputStream.decodeZigZag64(0x000000007FFFFFFEL)); + assertEquals(0xFFFFFFFFC0000000L, CodedInputStream.decodeZigZag64(0x000000007FFFFFFFL)); + assertEquals(0x000000007FFFFFFFL, CodedInputStream.decodeZigZag64(0x00000000FFFFFFFEL)); + assertEquals(0xFFFFFFFF80000000L, CodedInputStream.decodeZigZag64(0x00000000FFFFFFFFL)); + assertEquals(0x7FFFFFFFFFFFFFFFL, CodedInputStream.decodeZigZag64(0xFFFFFFFFFFFFFFFEL)); + assertEquals(0x8000000000000000L, CodedInputStream.decodeZigZag64(0xFFFFFFFFFFFFFFFFL)); } /** Tests reading and parsing a whole message with every field type. */ @@ -319,14 +316,12 @@ public class CodedInputStreamTest extends TestCase { byte[] rawBytes = message.toByteArray(); assertEquals(rawBytes.length, message.getSerializedSize()); - TestAllTypes message2 = TestAllTypes.parseFrom(rawBytes); - TestUtil.assertAllFieldsSet(message2); - - // Try different block sizes. - for (int blockSize = 1; blockSize < 256; blockSize *= 2) { - message2 = TestAllTypes.parseFrom( - new SmallBlockInputStream(rawBytes, blockSize)); - TestUtil.assertAllFieldsSet(message2); + for (InputType inputType : InputType.values()) { + // Try different block sizes. + for (int blockSize = 1; blockSize < 256; blockSize *= 2) { + TestAllTypes message2 = TestAllTypes.parseFrom(inputType.newDecoder(rawBytes, blockSize)); + TestUtil.assertAllFieldsSet(message2); + } } } @@ -335,57 +330,65 @@ public class CodedInputStreamTest extends TestCase { TestAllTypes message = TestUtil.getAllSet(); byte[] rawBytes = message.toByteArray(); - // Create two parallel inputs. Parse one as unknown fields while using - // skipField() to skip each field on the other. Expect the same tags. - CodedInputStream input1 = CodedInputStream.newInstance(rawBytes); - CodedInputStream input2 = CodedInputStream.newInstance(rawBytes); + InputType[] inputTypes = InputType.values(); + CodedInputStream[] inputs = new CodedInputStream[inputTypes.length]; + for (int i = 0; i < inputs.length; ++i) { + inputs[i] = inputTypes[i].newDecoder(rawBytes); + } UnknownFieldSet.Builder unknownFields = UnknownFieldSet.newBuilder(); while (true) { + CodedInputStream input1 = inputs[0]; int tag = input1.readTag(); - assertEquals(tag, input2.readTag()); + // Ensure that the rest match. + for (int i = 1; i < inputs.length; ++i) { + assertEquals(inputTypes[i].name(), tag, inputs[i].readTag()); + } if (tag == 0) { break; } unknownFields.mergeFieldFrom(tag, input1); - input2.skipField(tag); + // Skip the field for the rest of the inputs. + for (int i = 1; i < inputs.length; ++i) { + inputs[i].skipField(tag); + } } } /** - * Test that a bug in skipRawBytes() has been fixed: if the skip skips - * exactly up to a limit, this should not break things. + * Test that a bug in skipRawBytes() has been fixed: if the skip skips exactly up to a limit, this + * should not break things. */ public void testSkipRawBytesBug() throws Exception { - byte[] rawBytes = new byte[] { 1, 2 }; - CodedInputStream input = CodedInputStream.newInstance(rawBytes); - - int limit = input.pushLimit(1); - input.skipRawBytes(1); - input.popLimit(limit); - assertEquals(2, input.readRawByte()); + byte[] rawBytes = new byte[] {1, 2}; + for (InputType inputType : InputType.values()) { + CodedInputStream input = inputType.newDecoder(rawBytes); + int limit = input.pushLimit(1); + input.skipRawBytes(1); + input.popLimit(limit); + assertEquals(inputType.name(), 2, input.readRawByte()); + } } /** - * Test that a bug in skipRawBytes() has been fixed: if the skip skips - * past the end of a buffer with a limit that has been set past the end of - * that buffer, this should not break things. + * Test that a bug in skipRawBytes() has been fixed: if the skip skips past the end of a buffer + * with a limit that has been set past the end of that buffer, this should not break things. */ public void testSkipRawBytesPastEndOfBufferWithLimit() throws Exception { - byte[] rawBytes = new byte[] { 1, 2, 3, 4, 5 }; - CodedInputStream input = CodedInputStream.newInstance( - new SmallBlockInputStream(rawBytes, 3)); - - int limit = input.pushLimit(4); - // In order to expose the bug we need to read at least one byte to prime the - // buffer inside the CodedInputStream. - assertEquals(1, input.readRawByte()); - // Skip to the end of the limit. - input.skipRawBytes(3); - assertTrue(input.isAtEnd()); - input.popLimit(limit); - assertEquals(5, input.readRawByte()); + byte[] rawBytes = new byte[] {1, 2, 3, 4, 5}; + for (InputType inputType : InputType.values()) { + CodedInputStream input = inputType.newDecoder(rawBytes); + int limit = input.pushLimit(4); + // In order to expose the bug we need to read at least one byte to prime the + // buffer inside the CodedInputStream. + assertEquals(inputType.name(), 1, input.readRawByte()); + // Skip to the end of the limit. + input.skipRawBytes(3); + assertTrue(inputType.name(), input.isAtEnd()); + input.popLimit(limit); + assertEquals(inputType.name(), 5, input.readRawByte()); + } } public void testReadHugeBlob() throws Exception { @@ -401,19 +404,22 @@ public class CodedInputStreamTest extends TestCase { builder.setOptionalBytes(ByteString.copyFrom(blob)); TestAllTypes message = builder.build(); - // Serialize and parse it. Make sure to parse from an InputStream, not - // directly from a ByteString, so that CodedInputStream uses buffered - // reading. - TestAllTypes message2 = - TestAllTypes.parseFrom(message.toByteString().newInput()); - - assertEquals(message.getOptionalBytes(), message2.getOptionalBytes()); - - // Make sure all the other fields were parsed correctly. - TestAllTypes message3 = TestAllTypes.newBuilder(message2) - .setOptionalBytes(TestUtil.getAllSet().getOptionalBytes()) - .build(); - TestUtil.assertAllFieldsSet(message3); + byte[] data = message.toByteArray(); + for (InputType inputType : InputType.values()) { + // Serialize and parse it. Make sure to parse from an InputStream, not + // directly from a ByteString, so that CodedInputStream uses buffered + // reading. + TestAllTypes message2 = TestAllTypes.parseFrom(inputType.newDecoder(data)); + + assertEquals(inputType.name(), message.getOptionalBytes(), message2.getOptionalBytes()); + + // Make sure all the other fields were parsed correctly. + TestAllTypes message3 = + TestAllTypes.newBuilder(message2) + .setOptionalBytes(TestUtil.getAllSet().getOptionalBytes()) + .build(); + TestUtil.assertAllFieldsSet(message3); + } } public void testReadMaliciouslyLargeBlob() throws Exception { @@ -423,17 +429,19 @@ public class CodedInputStreamTest extends TestCase { int tag = WireFormat.makeTag(1, WireFormat.WIRETYPE_LENGTH_DELIMITED); output.writeRawVarint32(tag); output.writeRawVarint32(0x7FFFFFFF); - output.writeRawBytes(new byte[32]); // Pad with a few random bytes. + output.writeRawBytes(new byte[32]); // Pad with a few random bytes. output.flush(); - CodedInputStream input = rawOutput.toByteString().newCodedInput(); - assertEquals(tag, input.readTag()); - - try { - input.readBytes(); - fail("Should have thrown an exception!"); - } catch (InvalidProtocolBufferException e) { - // success. + byte[] data = rawOutput.toByteString().toByteArray(); + for (InputType inputType : InputType.values()) { + CodedInputStream input = inputType.newDecoder(data); + assertEquals(tag, input.readTag()); + try { + input.readBytes(); + fail(inputType.name() + ": Should have thrown an exception!"); + } catch (InvalidProtocolBufferException e) { + // success. + } } } @@ -441,54 +449,55 @@ public class CodedInputStreamTest extends TestCase { if (depth == 0) { return TestRecursiveMessage.newBuilder().setI(5).build(); } else { - return TestRecursiveMessage.newBuilder() - .setA(makeRecursiveMessage(depth - 1)).build(); + return TestRecursiveMessage.newBuilder().setA(makeRecursiveMessage(depth - 1)).build(); } } - private void assertMessageDepth(TestRecursiveMessage message, int depth) { + private void assertMessageDepth(String msg, TestRecursiveMessage message, int depth) { if (depth == 0) { - assertFalse(message.hasA()); - assertEquals(5, message.getI()); + assertFalse(msg, message.hasA()); + assertEquals(msg, 5, message.getI()); } else { - assertTrue(message.hasA()); - assertMessageDepth(message.getA(), depth - 1); + assertTrue(msg, message.hasA()); + assertMessageDepth(msg, message.getA(), depth - 1); } } public void testMaliciousRecursion() throws Exception { - ByteString data100 = makeRecursiveMessage(100).toByteString(); - ByteString data101 = makeRecursiveMessage(101).toByteString(); + byte[] data100 = makeRecursiveMessage(100).toByteArray(); + byte[] data101 = makeRecursiveMessage(101).toByteArray(); - assertMessageDepth(TestRecursiveMessage.parseFrom(data100), 100); + for (InputType inputType : InputType.values()) { + assertMessageDepth( + inputType.name(), TestRecursiveMessage.parseFrom(inputType.newDecoder(data100)), 100); - try { - TestRecursiveMessage.parseFrom(data101); - fail("Should have thrown an exception!"); - } catch (InvalidProtocolBufferException e) { - // success. - } + try { + TestRecursiveMessage.parseFrom(inputType.newDecoder(data101)); + fail("Should have thrown an exception!"); + } catch (InvalidProtocolBufferException e) { + // success. + } - CodedInputStream input = data100.newCodedInput(); - input.setRecursionLimit(8); - try { - TestRecursiveMessage.parseFrom(input); - fail("Should have thrown an exception!"); - } catch (InvalidProtocolBufferException e) { - // success. + CodedInputStream input = inputType.newDecoder(data100); + input.setRecursionLimit(8); + try { + TestRecursiveMessage.parseFrom(input); + fail(inputType.name() + ": Should have thrown an exception!"); + } catch (InvalidProtocolBufferException e) { + // success. + } } } private void checkSizeLimitExceeded(InvalidProtocolBufferException e) { - assertEquals( - InvalidProtocolBufferException.sizeLimitExceeded().getMessage(), - e.getMessage()); + assertEquals(InvalidProtocolBufferException.sizeLimitExceeded().getMessage(), e.getMessage()); } public void testSizeLimit() throws Exception { - CodedInputStream input = CodedInputStream.newInstance( - new SmallBlockInputStream( - TestUtil.getAllSet().toByteString().newInput(), 16)); + // NOTE: Size limit only applies to the stream-backed CIS. + CodedInputStream input = + CodedInputStream.newInstance( + new SmallBlockInputStream(TestUtil.getAllSet().toByteArray(), 16)); input.setSizeLimit(16); try { @@ -500,8 +509,9 @@ public class CodedInputStreamTest extends TestCase { } public void testResetSizeCounter() throws Exception { - CodedInputStream input = CodedInputStream.newInstance( - new SmallBlockInputStream(new byte[256], 8)); + // NOTE: Size limit only applies to the stream-backed CIS. + CodedInputStream input = + CodedInputStream.newInstance(new SmallBlockInputStream(new byte[256], 8)); input.setSizeLimit(16); input.readRawBytes(16); assertEquals(16, input.getTotalBytesRead()); @@ -515,7 +525,7 @@ public class CodedInputStreamTest extends TestCase { input.resetSizeCounter(); assertEquals(0, input.getTotalBytesRead()); - input.readRawByte(); // No exception thrown. + input.readRawByte(); // No exception thrown. input.resetSizeCounter(); assertEquals(0, input.getTotalBytesRead()); input.readRawBytes(16); @@ -523,7 +533,7 @@ public class CodedInputStreamTest extends TestCase { input.resetSizeCounter(); try { - input.readRawBytes(17); // Hits limit again. + input.readRawBytes(17); // Hits limit again. fail("Should have thrown an exception!"); } catch (InvalidProtocolBufferException expected) { checkSizeLimitExceeded(expected); @@ -531,12 +541,12 @@ public class CodedInputStreamTest extends TestCase { } public void testSizeLimitMultipleMessages() throws Exception { + // NOTE: Size limit only applies to the stream-backed CIS. byte[] bytes = new byte[256]; for (int i = 0; i < bytes.length; i++) { bytes[i] = (byte) i; } - CodedInputStream input = CodedInputStream.newInstance( - new SmallBlockInputStream(bytes, 7)); + CodedInputStream input = CodedInputStream.newInstance(new SmallBlockInputStream(bytes, 7)); input.setSizeLimit(16); for (int i = 0; i < 256 / 16; i++) { byte[] message = input.readRawBytes(16); @@ -566,12 +576,13 @@ public class CodedInputStreamTest extends TestCase { output.writeRawBytes(bytes); output.flush(); - CodedInputStream input = - CodedInputStream.newInstance( - new ByteArrayInputStream(rawOutput.toByteString().toByteArray())); - assertEquals(tag, input.readTag()); - String text = input.readString(); - assertEquals(lorem, text); + byte[] rawInput = rawOutput.toByteString().toByteArray(); + for (InputType inputType : InputType.values()) { + CodedInputStream input = inputType.newDecoder(rawInput); + assertEquals(inputType.name(), tag, input.readTag()); + String text = input.readString(); + assertEquals(inputType.name(), lorem, text); + } } public void testReadStringRequireUtf8() throws Exception { @@ -591,18 +602,18 @@ public class CodedInputStreamTest extends TestCase { output.writeRawBytes(bytes); output.flush(); - CodedInputStream input = - CodedInputStream.newInstance( - new ByteArrayInputStream(rawOutput.toByteString().toByteArray())); - assertEquals(tag, input.readTag()); - String text = input.readStringRequireUtf8(); - assertEquals(lorem, text); + byte[] rawInput = rawOutput.toByteString().toByteArray(); + for (InputType inputType : InputType.values()) { + CodedInputStream input = inputType.newDecoder(rawInput); + assertEquals(inputType.name(), tag, input.readTag()); + String text = input.readStringRequireUtf8(); + assertEquals(inputType.name(), lorem, text); + } } /** - * Tests that if we readString invalid UTF-8 bytes, no exception - * is thrown. Instead, the invalid bytes are replaced with the Unicode - * "replacement character" U+FFFD. + * Tests that if we readString invalid UTF-8 bytes, no exception is thrown. Instead, the invalid + * bytes are replaced with the Unicode "replacement character" U+FFFD. */ public void testReadStringInvalidUtf8() throws Exception { ByteString.Output rawOutput = ByteString.newOutput(); @@ -611,18 +622,21 @@ public class CodedInputStreamTest extends TestCase { int tag = WireFormat.makeTag(1, WireFormat.WIRETYPE_LENGTH_DELIMITED); output.writeRawVarint32(tag); output.writeRawVarint32(1); - output.writeRawBytes(new byte[] { (byte) 0x80 }); + output.writeRawBytes(new byte[] {(byte) 0x80}); output.flush(); - CodedInputStream input = rawOutput.toByteString().newCodedInput(); - assertEquals(tag, input.readTag()); - String text = input.readString(); - assertEquals(0xfffd, text.charAt(0)); + byte[] rawInput = rawOutput.toByteString().toByteArray(); + for (InputType inputType : InputType.values()) { + CodedInputStream input = inputType.newDecoder(rawInput); + assertEquals(inputType.name(), tag, input.readTag()); + String text = input.readString(); + assertEquals(inputType.name(), 0xfffd, text.charAt(0)); + } } /** - * Tests that if we readStringRequireUtf8 invalid UTF-8 bytes, an - * InvalidProtocolBufferException is thrown. + * Tests that if we readStringRequireUtf8 invalid UTF-8 bytes, an InvalidProtocolBufferException + * is thrown. */ public void testReadStringRequireUtf8InvalidUtf8() throws Exception { ByteString.Output rawOutput = ByteString.newOutput(); @@ -631,16 +645,20 @@ public class CodedInputStreamTest extends TestCase { int tag = WireFormat.makeTag(1, WireFormat.WIRETYPE_LENGTH_DELIMITED); output.writeRawVarint32(tag); output.writeRawVarint32(1); - output.writeRawBytes(new byte[] { (byte) 0x80 }); + output.writeRawBytes(new byte[] {(byte) 0x80}); output.flush(); - CodedInputStream input = rawOutput.toByteString().newCodedInput(); - assertEquals(tag, input.readTag()); - try { - input.readStringRequireUtf8(); - fail("Expected invalid UTF-8 exception."); - } catch (InvalidProtocolBufferException exception) { - assertEquals("Protocol message had invalid UTF-8.", exception.getMessage()); + byte[] rawInput = rawOutput.toByteString().toByteArray(); + for (InputType inputType : InputType.values()) { + CodedInputStream input = inputType.newDecoder(rawInput); + assertEquals(tag, input.readTag()); + try { + input.readStringRequireUtf8(); + fail(inputType.name() + ": Expected invalid UTF-8 exception."); + } catch (InvalidProtocolBufferException exception) { + assertEquals( + inputType.name(), "Protocol message had invalid UTF-8.", exception.getMessage()); + } } } @@ -660,13 +678,17 @@ public class CodedInputStreamTest extends TestCase { public void testInvalidTag() throws Exception { // Any tag number which corresponds to field number zero is invalid and // should throw InvalidProtocolBufferException. - for (int i = 0; i < 8; i++) { - try { - CodedInputStream.newInstance(bytes(i)).readTag(); - fail("Should have thrown an exception."); - } catch (InvalidProtocolBufferException e) { - assertEquals(InvalidProtocolBufferException.invalidTag().getMessage(), - e.getMessage()); + for (InputType inputType : InputType.values()) { + for (int i = 0; i < 8; i++) { + try { + inputType.newDecoder(bytes(i)).readTag(); + fail(inputType.name() + ": Should have thrown an exception."); + } catch (InvalidProtocolBufferException e) { + assertEquals( + inputType.name(), + InvalidProtocolBufferException.invalidTag().getMessage(), + e.getMessage()); + } } } } @@ -678,10 +700,10 @@ public class CodedInputStreamTest extends TestCase { output.writeRawVarint32(0); // One one-byte bytes field output.writeRawVarint32(1); - output.writeRawBytes(new byte[] { (byte) 23 }); + output.writeRawBytes(new byte[] {(byte) 23}); // Another one-byte bytes field output.writeRawVarint32(1); - output.writeRawBytes(new byte[] { (byte) 45 }); + output.writeRawBytes(new byte[] {(byte) 45}); // A bytes field large enough that won't fit into the 4K buffer. final int bytesLength = 16 * 1024; byte[] bytes = new byte[bytesLength]; @@ -691,20 +713,24 @@ public class CodedInputStreamTest extends TestCase { output.writeRawBytes(bytes); output.flush(); - CodedInputStream inputStream = rawOutput.toByteString().newCodedInput(); - - byte[] result = inputStream.readByteArray(); - assertEquals(0, result.length); - result = inputStream.readByteArray(); - assertEquals(1, result.length); - assertEquals((byte) 23, result[0]); - result = inputStream.readByteArray(); - assertEquals(1, result.length); - assertEquals((byte) 45, result[0]); - result = inputStream.readByteArray(); - assertEquals(bytesLength, result.length); - assertEquals((byte) 67, result[0]); - assertEquals((byte) 89, result[bytesLength - 1]); + + byte[] rawInput = rawOutput.toByteString().toByteArray(); + for (InputType inputType : InputType.values()) { + CodedInputStream inputStream = inputType.newDecoder(rawInput); + + byte[] result = inputStream.readByteArray(); + assertEquals(inputType.name(), 0, result.length); + result = inputStream.readByteArray(); + assertEquals(inputType.name(), 1, result.length); + assertEquals(inputType.name(), (byte) 23, result[0]); + result = inputStream.readByteArray(); + assertEquals(inputType.name(), 1, result.length); + assertEquals(inputType.name(), (byte) 45, result[0]); + result = inputStream.readByteArray(); + assertEquals(inputType.name(), bytesLength, result.length); + assertEquals(inputType.name(), (byte) 67, result[0]); + assertEquals(inputType.name(), (byte) 89, result[bytesLength - 1]); + } } public void testReadByteBuffer() throws Exception { @@ -714,10 +740,10 @@ public class CodedInputStreamTest extends TestCase { output.writeRawVarint32(0); // One one-byte bytes field output.writeRawVarint32(1); - output.writeRawBytes(new byte[]{(byte) 23}); + output.writeRawBytes(new byte[] {(byte) 23}); // Another one-byte bytes field output.writeRawVarint32(1); - output.writeRawBytes(new byte[]{(byte) 45}); + output.writeRawBytes(new byte[] {(byte) 45}); // A bytes field large enough that won't fit into the 4K buffer. final int bytesLength = 16 * 1024; byte[] bytes = new byte[bytesLength]; @@ -727,21 +753,25 @@ public class CodedInputStreamTest extends TestCase { output.writeRawBytes(bytes); output.flush(); - CodedInputStream inputStream = rawOutput.toByteString().newCodedInput(); - - ByteBuffer result = inputStream.readByteBuffer(); - assertEquals(0, result.capacity()); - result = inputStream.readByteBuffer(); - assertEquals(1, result.capacity()); - assertEquals((byte) 23, result.get()); - result = inputStream.readByteBuffer(); - assertEquals(1, result.capacity()); - assertEquals((byte) 45, result.get()); - result = inputStream.readByteBuffer(); - assertEquals(bytesLength, result.capacity()); - assertEquals((byte) 67, result.get()); - result.position(bytesLength - 1); - assertEquals((byte) 89, result.get()); + + byte[] rawInput = rawOutput.toByteString().toByteArray(); + for (InputType inputType : InputType.values()) { + CodedInputStream inputStream = inputType.newDecoder(rawInput); + + ByteBuffer result = inputStream.readByteBuffer(); + assertEquals(inputType.name(), 0, result.capacity()); + result = inputStream.readByteBuffer(); + assertEquals(inputType.name(), 1, result.capacity()); + assertEquals(inputType.name(), (byte) 23, result.get()); + result = inputStream.readByteBuffer(); + assertEquals(inputType.name(), 1, result.capacity()); + assertEquals(inputType.name(), (byte) 45, result.get()); + result = inputStream.readByteBuffer(); + assertEquals(inputType.name(), bytesLength, result.capacity()); + assertEquals(inputType.name(), (byte) 67, result.get()); + result.position(bytesLength - 1); + assertEquals(inputType.name(), (byte) 89, result.get()); + } } public void testReadByteBufferAliasing() throws Exception { @@ -751,10 +781,10 @@ public class CodedInputStreamTest extends TestCase { output.writeRawVarint32(0); // One one-byte bytes field output.writeRawVarint32(1); - output.writeRawBytes(new byte[]{(byte) 23}); + output.writeRawBytes(new byte[] {(byte) 23}); // Another one-byte bytes field output.writeRawVarint32(1); - output.writeRawBytes(new byte[]{(byte) 45}); + output.writeRawBytes(new byte[] {(byte) 45}); // A bytes field large enough that won't fit into the 4K buffer. final int bytesLength = 16 * 1024; byte[] bytes = new byte[bytesLength]; @@ -763,59 +793,105 @@ public class CodedInputStreamTest extends TestCase { output.writeRawVarint32(bytesLength); output.writeRawBytes(bytes); output.flush(); + byte[] data = byteArrayStream.toByteArray(); - // Without aliasing - CodedInputStream inputStream = CodedInputStream.newInstance(data); - ByteBuffer result = inputStream.readByteBuffer(); - assertEquals(0, result.capacity()); - result = inputStream.readByteBuffer(); - assertTrue(result.array() != data); - assertEquals(1, result.capacity()); - assertEquals((byte) 23, result.get()); - result = inputStream.readByteBuffer(); - assertTrue(result.array() != data); - assertEquals(1, result.capacity()); - assertEquals((byte) 45, result.get()); - result = inputStream.readByteBuffer(); - assertTrue(result.array() != data); - assertEquals(bytesLength, result.capacity()); - assertEquals((byte) 67, result.get()); - result.position(bytesLength - 1); - assertEquals((byte) 89, result.get()); - - // Enable aliasing - inputStream = CodedInputStream.newInstance(data); - inputStream.enableAliasing(true); - result = inputStream.readByteBuffer(); - assertEquals(0, result.capacity()); - result = inputStream.readByteBuffer(); - assertTrue(result.array() == data); - assertEquals(1, result.capacity()); - assertEquals((byte) 23, result.get()); - result = inputStream.readByteBuffer(); - assertTrue(result.array() == data); - assertEquals(1, result.capacity()); - assertEquals((byte) 45, result.get()); - result = inputStream.readByteBuffer(); - assertTrue(result.array() == data); - assertEquals(bytesLength, result.capacity()); - assertEquals((byte) 67, result.get()); - result.position(bytesLength - 1); - assertEquals((byte) 89, result.get()); + for (InputType inputType : InputType.values()) { + if (inputType == InputType.STREAM) { + // Aliasing doesn't apply to stream-backed CIS. + continue; + } + + // Without aliasing + CodedInputStream inputStream = inputType.newDecoder(data); + ByteBuffer result = inputStream.readByteBuffer(); + assertEquals(inputType.name(), 0, result.capacity()); + result = inputStream.readByteBuffer(); + assertTrue(inputType.name(), result.array() != data); + assertEquals(inputType.name(), 1, result.capacity()); + assertEquals(inputType.name(), (byte) 23, result.get()); + result = inputStream.readByteBuffer(); + assertTrue(inputType.name(), result.array() != data); + assertEquals(inputType.name(), 1, result.capacity()); + assertEquals(inputType.name(), (byte) 45, result.get()); + result = inputStream.readByteBuffer(); + assertTrue(inputType.name(), result.array() != data); + assertEquals(inputType.name(), bytesLength, result.capacity()); + assertEquals(inputType.name(), (byte) 67, result.get()); + result.position(bytesLength - 1); + assertEquals(inputType.name(), (byte) 89, result.get()); + + // Enable aliasing + inputStream = inputType.newDecoder(data); + inputStream.enableAliasing(true); + result = inputStream.readByteBuffer(); + assertEquals(inputType.name(), 0, result.capacity()); + result = inputStream.readByteBuffer(); + if (result.hasArray()) { + assertTrue(inputType.name(), result.array() == data); + } + assertEquals(inputType.name(), 1, result.capacity()); + assertEquals(inputType.name(), (byte) 23, result.get()); + result = inputStream.readByteBuffer(); + if (result.hasArray()) { + assertTrue(inputType.name(), result.array() == data); + } + assertEquals(inputType.name(), 1, result.capacity()); + assertEquals(inputType.name(), (byte) 45, result.get()); + result = inputStream.readByteBuffer(); + if (result.hasArray()) { + assertTrue(inputType.name(), result.array() == data); + } + assertEquals(inputType.name(), bytesLength, result.capacity()); + assertEquals(inputType.name(), (byte) 67, result.get()); + result.position(bytesLength - 1); + assertEquals(inputType.name(), (byte) 89, result.get()); + } } public void testCompatibleTypes() throws Exception { long data = 0x100000000L; Int64Message message = Int64Message.newBuilder().setData(data).build(); - ByteString serialized = message.toByteString(); + byte[] serialized = message.toByteArray(); + for (InputType inputType : InputType.values()) { + CodedInputStream inputStream = inputType.newDecoder(serialized); + + // Test int64(long) is compatible with bool(boolean) + BoolMessage msg2 = BoolMessage.parseFrom(inputStream); + assertTrue(msg2.getData()); + + // Test int64(long) is compatible with int32(int) + inputStream = inputType.newDecoder(serialized); + Int32Message msg3 = Int32Message.parseFrom(inputStream); + assertEquals((int) data, msg3.getData()); + } + } - // Test int64(long) is compatible with bool(boolean) - BoolMessage msg2 = BoolMessage.parseFrom(serialized); - assertTrue(msg2.getData()); + public void testSkipInvalidVarint_FastPath() throws Exception { + // Fast path: We have >= 10 bytes available. Ensure we properly recognize a non-ending varint. + byte[] data = new byte[] {-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 0}; + for (InputType inputType : InputType.values()) { + try { + CodedInputStream input = inputType.newDecoder(data); + input.skipField(WireFormat.makeTag(1, WireFormat.WIRETYPE_VARINT)); + fail(inputType.name() + ": Should have thrown an exception."); + } catch (InvalidProtocolBufferException e) { + // Expected + } + } + } - // Test int64(long) is compatible with int32(int) - Int32Message msg3 = Int32Message.parseFrom(serialized); - assertEquals((int) data, msg3.getData()); + public void testSkipInvalidVarint_SlowPath() throws Exception { + // Slow path: < 10 bytes available. Ensure we properly recognize a non-ending varint. + byte[] data = new byte[] {-1, -1, -1, -1, -1, -1, -1, -1, -1}; + for (InputType inputType : InputType.values()) { + try { + CodedInputStream input = inputType.newDecoder(data); + input.skipField(WireFormat.makeTag(1, WireFormat.WIRETYPE_VARINT)); + fail(inputType.name() + ": Should have thrown an exception."); + } catch (InvalidProtocolBufferException e) { + // Expected + } + } } } diff --git a/java/core/src/test/java/com/google/protobuf/CodedOutputStreamTest.java b/java/core/src/test/java/com/google/protobuf/CodedOutputStreamTest.java index 33aa4357..78f415c2 100644 --- a/java/core/src/test/java/com/google/protobuf/CodedOutputStreamTest.java +++ b/java/core/src/test/java/com/google/protobuf/CodedOutputStreamTest.java @@ -35,15 +35,13 @@ import protobuf_unittest.UnittestProto.SparseEnumMessage; import protobuf_unittest.UnittestProto.TestAllTypes; import protobuf_unittest.UnittestProto.TestPackedTypes; import protobuf_unittest.UnittestProto.TestSparseEnum; - -import junit.framework.TestCase; - import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; import java.nio.ByteBuffer; import java.util.ArrayList; import java.util.Arrays; import java.util.List; +import junit.framework.TestCase; /** * Unit test for {@link CodedOutputStream}. @@ -151,16 +149,21 @@ public class CodedOutputStreamTest extends TestCase { private final int initialPosition; private final CodedOutputStream stream; private final ByteBuffer buffer; + private final boolean unsafe; - NioDirectCoder(int size) { - this(size, 0); + NioDirectCoder(int size, boolean unsafe) { + this(size, 0, unsafe); } - NioDirectCoder(int size, int initialPosition) { + NioDirectCoder(int size, int initialPosition, boolean unsafe) { + this.unsafe = unsafe; this.initialPosition = initialPosition; buffer = ByteBuffer.allocateDirect(size); buffer.position(initialPosition); - stream = CodedOutputStream.newInstance(buffer); + stream = + unsafe + ? CodedOutputStream.newUnsafeInstance(buffer) + : CodedOutputStream.newSafeInstance(buffer); } @Override @@ -181,7 +184,7 @@ public class CodedOutputStreamTest extends TestCase { @Override public OutputType getOutputType() { - return OutputType.NIO_DIRECT; + return unsafe ? OutputType.NIO_DIRECT_SAFE : OutputType.NIO_DIRECT_UNSAFE; } } @@ -198,10 +201,16 @@ public class CodedOutputStreamTest extends TestCase { return new NioHeapCoder(size); } }, - NIO_DIRECT() { + NIO_DIRECT_SAFE() { @Override Coder newCoder(int size) { - return new NioDirectCoder(size); + return new NioDirectCoder(size, false); + } + }, + NIO_DIRECT_UNSAFE() { + @Override + Coder newCoder(int size) { + return new NioDirectCoder(size, true); } }, STREAM() { @@ -389,6 +398,7 @@ public class CodedOutputStreamTest extends TestCase { != CodedOutputStream.computeUInt32SizeNoTag(string.length() * Utf8.MAX_BYTES_PER_CHAR)); coder.stream().writeStringNoTag(string); + coder.stream().flush(); int stringSize = CodedOutputStream.computeStringSizeNoTag(string); // Verify that the total bytes written is correct @@ -478,11 +488,12 @@ public class CodedOutputStreamTest extends TestCase { public void testWriteByteArrayWithOffsets() throws Exception { byte[] fullArray = bytes(0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 0x88); - byte[] destination = new byte[4]; - CodedOutputStream codedStream = CodedOutputStream.newInstance(destination); - codedStream.writeByteArrayNoTag(fullArray, 2, 2); - assertEqualBytes(OutputType.ARRAY, bytes(0x02, 0x33, 0x44, 0x00), destination); - assertEquals(3, codedStream.getTotalBytesWritten()); + for (OutputType type : new OutputType[] {OutputType.ARRAY}) { + Coder coder = type.newCoder(4); + coder.stream().writeByteArrayNoTag(fullArray, 2, 2); + assertEqualBytes(type, bytes(0x02, 0x33, 0x44), coder.toByteArray()); + assertEquals(3, coder.stream().getTotalBytesWritten()); + } } public void testSerializeUtf8_MultipleSmallWrites() throws Exception { @@ -561,7 +572,12 @@ public class CodedOutputStreamTest extends TestCase { // Tag is one byte, varint describing string length is 1 byte, string length is 9 bytes. // An array of size 1 will cause a failure when trying to write the varint. for (OutputType outputType : - new OutputType[] {OutputType.ARRAY, OutputType.NIO_HEAP, OutputType.NIO_DIRECT}) { + new OutputType[] { + OutputType.ARRAY, + OutputType.NIO_HEAP, + OutputType.NIO_DIRECT_SAFE, + OutputType.NIO_DIRECT_UNSAFE + }) { for (int i = 0; i < 11; i++) { Coder coder = outputType.newCoder(i); try { @@ -599,10 +615,13 @@ public class CodedOutputStreamTest extends TestCase { public void testNioEncodersWithInitialOffsets() throws Exception { String value = "abc"; - for (Coder coder : new Coder[] {new NioHeapCoder(10, 2), new NioDirectCoder(10, 2)}) { + for (Coder coder : + new Coder[] { + new NioHeapCoder(10, 2), new NioDirectCoder(10, 2, false), new NioDirectCoder(10, 2, true) + }) { coder.stream().writeStringNoTag(value); coder.stream().flush(); - assertEqualBytes(coder.getOutputType(), new byte[]{3, 'a', 'b', 'c'}, coder.toByteArray()); + assertEqualBytes(coder.getOutputType(), new byte[] {3, 'a', 'b', 'c'}, coder.toByteArray()); } } diff --git a/java/core/src/test/java/com/google/protobuf/DeprecatedFieldTest.java b/java/core/src/test/java/com/google/protobuf/DeprecatedFieldTest.java index ce85ae2e..2c272a73 100644 --- a/java/core/src/test/java/com/google/protobuf/DeprecatedFieldTest.java +++ b/java/core/src/test/java/com/google/protobuf/DeprecatedFieldTest.java @@ -31,11 +31,9 @@ package com.google.protobuf; import protobuf_unittest.UnittestProto.TestDeprecatedFields; - -import junit.framework.TestCase; - import java.lang.reflect.AnnotatedElement; import java.lang.reflect.Method; +import junit.framework.TestCase; /** * Test field deprecation diff --git a/java/core/src/test/java/com/google/protobuf/DescriptorsTest.java b/java/core/src/test/java/com/google/protobuf/DescriptorsTest.java index b3302441..b60cd620 100644 --- a/java/core/src/test/java/com/google/protobuf/DescriptorsTest.java +++ b/java/core/src/test/java/com/google/protobuf/DescriptorsTest.java @@ -55,15 +55,15 @@ import protobuf_unittest.UnittestProto.ForeignMessage; import protobuf_unittest.UnittestProto.TestAllExtensions; import protobuf_unittest.UnittestProto.TestAllTypes; import protobuf_unittest.UnittestProto.TestExtremeDefaultValues; +import protobuf_unittest.UnittestProto.TestJsonName; import protobuf_unittest.UnittestProto.TestMultipleExtensionRanges; import protobuf_unittest.UnittestProto.TestRequired; import protobuf_unittest.UnittestProto.TestReservedFields; import protobuf_unittest.UnittestProto.TestService; -import junit.framework.TestCase; - import java.util.Arrays; import java.util.Collections; import java.util.List; +import junit.framework.TestCase; /** * Unit test for {@link Descriptors}. @@ -805,4 +805,15 @@ public class DescriptorsTest extends TestCase { Descriptors.FileDescriptor.buildFrom( fileDescriptorProto, new FileDescriptor[0]); } + + public void testFieldJsonName() throws Exception { + Descriptor d = TestJsonName.getDescriptor(); + assertEquals(6, d.getFields().size()); + assertEquals("fieldName1", d.getFields().get(0).getJsonName()); + assertEquals("fieldName2", d.getFields().get(1).getJsonName()); + assertEquals("FieldName3", d.getFields().get(2).getJsonName()); + assertEquals("FieldName4", d.getFields().get(3).getJsonName()); + assertEquals("FIELDNAME5", d.getFields().get(4).getJsonName()); + assertEquals("@type", d.getFields().get(5).getJsonName()); + } } diff --git a/java/core/src/test/java/com/google/protobuf/DoubleArrayListTest.java b/java/core/src/test/java/com/google/protobuf/DoubleArrayListTest.java index 8e8e4fe2..d8942792 100644 --- a/java/core/src/test/java/com/google/protobuf/DoubleArrayListTest.java +++ b/java/core/src/test/java/com/google/protobuf/DoubleArrayListTest.java @@ -32,11 +32,10 @@ package com.google.protobuf; import static java.util.Arrays.asList; -import junit.framework.TestCase; - import java.util.Collections; import java.util.ConcurrentModificationException; import java.util.Iterator; +import junit.framework.TestCase; /** * Tests for {@link DoubleArrayList}. diff --git a/java/core/src/test/java/com/google/protobuf/DynamicMessageTest.java b/java/core/src/test/java/com/google/protobuf/DynamicMessageTest.java index 8f3a74c1..77d14f6b 100644 --- a/java/core/src/test/java/com/google/protobuf/DynamicMessageTest.java +++ b/java/core/src/test/java/com/google/protobuf/DynamicMessageTest.java @@ -37,10 +37,8 @@ import protobuf_unittest.UnittestProto.TestAllExtensions; import protobuf_unittest.UnittestProto.TestAllTypes; import protobuf_unittest.UnittestProto.TestEmptyMessage; import protobuf_unittest.UnittestProto.TestPackedTypes; - -import junit.framework.TestCase; - import java.util.Arrays; +import junit.framework.TestCase; /** * Unit test for {@link DynamicMessage}. See also {@link MessageTest}, which diff --git a/java/core/src/test/java/com/google/protobuf/ExtensionRegistryFactoryTest.java b/java/core/src/test/java/com/google/protobuf/ExtensionRegistryFactoryTest.java index c1246782..6157e589 100644 --- a/java/core/src/test/java/com/google/protobuf/ExtensionRegistryFactoryTest.java +++ b/java/core/src/test/java/com/google/protobuf/ExtensionRegistryFactoryTest.java @@ -32,26 +32,24 @@ package com.google.protobuf; import protobuf_unittest.NonNestedExtension; import protobuf_unittest.NonNestedExtensionLite; - -import junit.framework.Test; -import junit.framework.TestCase; -import junit.framework.TestSuite; - import java.lang.reflect.Method; import java.net.URLClassLoader; import java.util.Arrays; import java.util.Collections; import java.util.HashSet; import java.util.Set; +import junit.framework.Test; +import junit.framework.TestCase; +import junit.framework.TestSuite; /** * Tests for {@link ExtensionRegistryFactory} and the {@link ExtensionRegistry} instances it * creates. - * + * *

This test simulates the runtime behaviour of the ExtensionRegistryFactory by delegating test * definitions to two inner classes {@link InnerTest} and {@link InnerLiteTest}, the latter of * which is executed using a custom ClassLoader, simulating the ProtoLite environment. - * + * *

The test mechanism employed here is based on the pattern in * {@code com.google.common.util.concurrent.AbstractFutureFallbackAtomicHelperTest} */ @@ -68,6 +66,7 @@ public class ExtensionRegistryFactoryTest extends TestCase { void testEmpty(); void testIsFullRegistry(); void testAdd(); + void testAdd_immutable(); } /** @@ -125,6 +124,29 @@ public class ExtensionRegistryFactoryTest extends TestCase { assertNotNull("Extension is registered in masqueraded full registry", fullRegistry2.findImmutableExtensionByName("protobuf_unittest.nonNestedExtension")); } + + @Override + public void testAdd_immutable() { + ExtensionRegistryLite registry1 = ExtensionRegistryLite.newInstance().getUnmodifiable(); + try { + NonNestedExtensionLite.registerAllExtensions(registry1); + fail(); + } catch (UnsupportedOperationException expected) {} + try { + registry1.add(NonNestedExtensionLite.nonNestedExtensionLite); + fail(); + } catch (UnsupportedOperationException expected) {} + + ExtensionRegistryLite registry2 = ExtensionRegistryLite.newInstance().getUnmodifiable(); + try { + NonNestedExtension.registerAllExtensions((ExtensionRegistry) registry2); + fail(); + } catch (IllegalArgumentException expected) {} + try { + registry2.add(NonNestedExtension.nonNestedExtension); + fail(); + } catch (IllegalArgumentException expected) {} + } } /** @@ -162,12 +184,21 @@ public class ExtensionRegistryFactoryTest extends TestCase { NonNestedExtensionLite.MessageLiteToBeExtended.getDefaultInstance(), 1); assertNotNull("Extension is registered in Lite registry", extension); } + + @Override + public void testAdd_immutable() { + ExtensionRegistryLite registry = ExtensionRegistryLite.newInstance().getUnmodifiable(); + try { + NonNestedExtensionLite.registerAllExtensions(registry); + fail(); + } catch (UnsupportedOperationException expected) {} + } } /** * Defines a suite of tests which the JUnit3 runner retrieves by reflection. */ - public static Test suite() { + public static Test suite() { TestSuite suite = new TestSuite(); for (Method method : RegistryTests.class.getMethods()) { suite.addTest(TestSuite.createTest(ExtensionRegistryFactoryTest.class, method.getName())); diff --git a/java/core/src/test/java/com/google/protobuf/FloatArrayListTest.java b/java/core/src/test/java/com/google/protobuf/FloatArrayListTest.java index 0e13a598..aa36be49 100644 --- a/java/core/src/test/java/com/google/protobuf/FloatArrayListTest.java +++ b/java/core/src/test/java/com/google/protobuf/FloatArrayListTest.java @@ -32,11 +32,10 @@ package com.google.protobuf; import static java.util.Arrays.asList; -import junit.framework.TestCase; - import java.util.Collections; import java.util.ConcurrentModificationException; import java.util.Iterator; +import junit.framework.TestCase; /** * Tests for {@link FloatArrayList}. diff --git a/java/core/src/test/java/com/google/protobuf/GeneratedMessageTest.java b/java/core/src/test/java/com/google/protobuf/GeneratedMessageTest.java index 127e06fd..3eece26a 100644 --- a/java/core/src/test/java/com/google/protobuf/GeneratedMessageTest.java +++ b/java/core/src/test/java/com/google/protobuf/GeneratedMessageTest.java @@ -65,9 +65,6 @@ import protobuf_unittest.UnittestProto.TestExtremeDefaultValues; import protobuf_unittest.UnittestProto.TestOneof2; import protobuf_unittest.UnittestProto.TestPackedTypes; import protobuf_unittest.UnittestProto.TestUnpackedTypes; - -import junit.framework.TestCase; - import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; import java.io.ObjectInputStream; @@ -76,6 +73,7 @@ import java.util.Arrays; import java.util.Collections; import java.util.Iterator; import java.util.List; +import junit.framework.TestCase; /** * Unit test for generated messages and generated code. See also diff --git a/java/core/src/test/java/com/google/protobuf/IntArrayListTest.java b/java/core/src/test/java/com/google/protobuf/IntArrayListTest.java index e59e3c6e..60c85450 100644 --- a/java/core/src/test/java/com/google/protobuf/IntArrayListTest.java +++ b/java/core/src/test/java/com/google/protobuf/IntArrayListTest.java @@ -32,11 +32,10 @@ package com.google.protobuf; import static java.util.Arrays.asList; -import junit.framework.TestCase; - import java.util.Collections; import java.util.ConcurrentModificationException; import java.util.Iterator; +import junit.framework.TestCase; /** * Tests for {@link IntArrayList}. diff --git a/java/core/src/test/java/com/google/protobuf/LazyFieldLiteTest.java b/java/core/src/test/java/com/google/protobuf/LazyFieldLiteTest.java index 8d1de6dc..efdfdfbe 100644 --- a/java/core/src/test/java/com/google/protobuf/LazyFieldLiteTest.java +++ b/java/core/src/test/java/com/google/protobuf/LazyFieldLiteTest.java @@ -35,10 +35,8 @@ import static protobuf_unittest.UnittestProto.optionalInt64Extension; import protobuf_unittest.UnittestProto.TestAllExtensions; import protobuf_unittest.UnittestProto.TestAllTypes; - -import junit.framework.TestCase; - import java.io.IOException; +import junit.framework.TestCase; /** * Unit test for {@link LazyFieldLite}. diff --git a/java/core/src/test/java/com/google/protobuf/LazyFieldTest.java b/java/core/src/test/java/com/google/protobuf/LazyFieldTest.java index ce473ae9..5f013f3c 100644 --- a/java/core/src/test/java/com/google/protobuf/LazyFieldTest.java +++ b/java/core/src/test/java/com/google/protobuf/LazyFieldTest.java @@ -32,10 +32,8 @@ package com.google.protobuf; import protobuf_unittest.UnittestProto.TestAllExtensions; import protobuf_unittest.UnittestProto.TestAllTypes; - -import junit.framework.TestCase; - import java.io.IOException; +import junit.framework.TestCase; /** * Unit test for {@link LazyField}. diff --git a/java/core/src/test/java/com/google/protobuf/LazyMessageLiteTest.java b/java/core/src/test/java/com/google/protobuf/LazyMessageLiteTest.java index e5b11cf1..c8ca9b6a 100644 --- a/java/core/src/test/java/com/google/protobuf/LazyMessageLiteTest.java +++ b/java/core/src/test/java/com/google/protobuf/LazyMessageLiteTest.java @@ -34,10 +34,8 @@ import protobuf_unittest.LazyFieldsLite.LazyExtension; import protobuf_unittest.LazyFieldsLite.LazyInnerMessageLite; import protobuf_unittest.LazyFieldsLite.LazyMessageLite; import protobuf_unittest.LazyFieldsLite.LazyNestedInnerMessageLite; - -import junit.framework.TestCase; - import java.util.ArrayList; +import junit.framework.TestCase; /** * Unit test for messages with lazy fields. diff --git a/java/core/src/test/java/com/google/protobuf/LazyStringArrayListTest.java b/java/core/src/test/java/com/google/protobuf/LazyStringArrayListTest.java index 497c4df2..d2bee2a4 100644 --- a/java/core/src/test/java/com/google/protobuf/LazyStringArrayListTest.java +++ b/java/core/src/test/java/com/google/protobuf/LazyStringArrayListTest.java @@ -32,13 +32,12 @@ package com.google.protobuf; import static java.util.Arrays.asList; -import junit.framework.TestCase; - import java.util.ArrayList; import java.util.Collections; import java.util.ConcurrentModificationException; import java.util.Iterator; import java.util.List; +import junit.framework.TestCase; /** * Tests for {@link LazyStringArrayList}. diff --git a/java/core/src/test/java/com/google/protobuf/LazyStringEndToEndTest.java b/java/core/src/test/java/com/google/protobuf/LazyStringEndToEndTest.java index 0ef414aa..006e4933 100644 --- a/java/core/src/test/java/com/google/protobuf/LazyStringEndToEndTest.java +++ b/java/core/src/test/java/com/google/protobuf/LazyStringEndToEndTest.java @@ -32,10 +32,8 @@ package com.google.protobuf; import protobuf_unittest.UnittestProto; - -import junit.framework.TestCase; - import java.io.IOException; +import junit.framework.TestCase; /** * Tests to make sure the lazy conversion of UTF8-encoded byte arrays to diff --git a/java/core/src/test/java/com/google/protobuf/LiteTest.java b/java/core/src/test/java/com/google/protobuf/LiteTest.java index b3a246dc..254beba1 100644 --- a/java/core/src/test/java/com/google/protobuf/LiteTest.java +++ b/java/core/src/test/java/com/google/protobuf/LiteTest.java @@ -35,7 +35,6 @@ import static java.util.Collections.singletonList; import com.google.protobuf.UnittestImportLite.ImportEnumLite; import com.google.protobuf.UnittestImportPublicLite.PublicImportMessageLite; -import com.google.protobuf.UnittestLite; import com.google.protobuf.UnittestLite.ForeignEnumLite; import com.google.protobuf.UnittestLite.ForeignMessageLite; import com.google.protobuf.UnittestLite.TestAllExtensionsLite; @@ -52,15 +51,8 @@ import protobuf_unittest.lite_equals_and_hash.LiteEqualsAndHash.BarPrime; import protobuf_unittest.lite_equals_and_hash.LiteEqualsAndHash.Foo; import protobuf_unittest.lite_equals_and_hash.LiteEqualsAndHash.TestOneofEquals; import protobuf_unittest.lite_equals_and_hash.LiteEqualsAndHash.TestRecursiveOneof; - import junit.framework.TestCase; -import java.io.ByteArrayInputStream; -import java.io.ByteArrayOutputStream; -import java.io.NotSerializableException; -import java.io.ObjectInputStream; -import java.io.ObjectOutputStream; - /** * Test lite runtime. * @@ -139,7 +131,6 @@ public class LiteTest extends TestCase { UnittestLite.optionalNestedMessageExtensionLite).getBb()); } - public void testClone() { TestAllTypesLite.Builder expected = TestAllTypesLite.newBuilder() .setOptionalInt32(123); diff --git a/java/core/src/test/java/com/google/protobuf/LiteralByteStringTest.java b/java/core/src/test/java/com/google/protobuf/LiteralByteStringTest.java index 2e7792a8..eac47448 100644 --- a/java/core/src/test/java/com/google/protobuf/LiteralByteStringTest.java +++ b/java/core/src/test/java/com/google/protobuf/LiteralByteStringTest.java @@ -30,8 +30,6 @@ package com.google.protobuf; -import junit.framework.TestCase; - import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; import java.io.EOFException; @@ -45,6 +43,7 @@ import java.nio.ByteBuffer; import java.util.Arrays; import java.util.List; import java.util.NoSuchElementException; +import junit.framework.TestCase; /** * Test {@code LiteralByteString} by setting up a reference string in {@link #setUp()}. diff --git a/java/core/src/test/java/com/google/protobuf/LongArrayListTest.java b/java/core/src/test/java/com/google/protobuf/LongArrayListTest.java index 6aaf85d7..6bbdfcaa 100644 --- a/java/core/src/test/java/com/google/protobuf/LongArrayListTest.java +++ b/java/core/src/test/java/com/google/protobuf/LongArrayListTest.java @@ -32,11 +32,10 @@ package com.google.protobuf; import static java.util.Arrays.asList; -import junit.framework.TestCase; - import java.util.Collections; import java.util.ConcurrentModificationException; import java.util.Iterator; +import junit.framework.TestCase; /** * Tests for {@link LongArrayList}. diff --git a/java/core/src/test/java/com/google/protobuf/MapForProto2LiteTest.java b/java/core/src/test/java/com/google/protobuf/MapForProto2LiteTest.java index 04d58006..8b64fa27 100644 --- a/java/core/src/test/java/com/google/protobuf/MapForProto2LiteTest.java +++ b/java/core/src/test/java/com/google/protobuf/MapForProto2LiteTest.java @@ -35,15 +35,13 @@ import map_lite_test.MapForProto2TestProto.TestMap; import map_lite_test.MapForProto2TestProto.TestMap.MessageValue; import map_lite_test.MapForProto2TestProto.TestMapOrBuilder; import map_lite_test.MapForProto2TestProto.TestUnknownEnumValue; - -import junit.framework.TestCase; - import java.io.ByteArrayOutputStream; import java.io.IOException; import java.util.ArrayList; import java.util.Arrays; import java.util.HashMap; import java.util.Map; +import junit.framework.TestCase; /** * Unit tests for map fields. diff --git a/java/core/src/test/java/com/google/protobuf/MapForProto2Test.java b/java/core/src/test/java/com/google/protobuf/MapForProto2Test.java index e8246bf6..76bd7bd9 100644 --- a/java/core/src/test/java/com/google/protobuf/MapForProto2Test.java +++ b/java/core/src/test/java/com/google/protobuf/MapForProto2Test.java @@ -32,14 +32,14 @@ package com.google.protobuf; import com.google.protobuf.Descriptors.FieldDescriptor; import map_test.MapForProto2TestProto.BizarroTestMap; +import map_test.MapForProto2TestProto.ReservedAsMapField; +import map_test.MapForProto2TestProto.ReservedAsMapFieldWithEnumValue; import map_test.MapForProto2TestProto.TestMap; import map_test.MapForProto2TestProto.TestMap.MessageValue; import map_test.MapForProto2TestProto.TestMap.MessageWithRequiredFields; import map_test.MapForProto2TestProto.TestMapOrBuilder; import map_test.MapForProto2TestProto.TestRecursiveMap; import map_test.MapForProto2TestProto.TestUnknownEnumValue; -import junit.framework.TestCase; - import java.io.ByteArrayOutputStream; import java.io.IOException; import java.util.ArrayList; @@ -47,6 +47,7 @@ import java.util.Arrays; import java.util.HashMap; import java.util.List; import java.util.Map; +import junit.framework.TestCase; /** * Unit tests for map fields in proto2 protos. @@ -1143,6 +1144,11 @@ public class MapForProto2Test extends TestCase { assertEquals(2, mapEntry.getAllFields().size()); } + public void testReservedWordsFieldNames() { + ReservedAsMapField.newBuilder().build(); + ReservedAsMapFieldWithEnumValue.newBuilder().build(); + } + private static Map newMap(K key1, V value1) { Map map = new HashMap(); map.put(key1, value1); diff --git a/java/core/src/test/java/com/google/protobuf/MapTest.java b/java/core/src/test/java/com/google/protobuf/MapTest.java index caef246b..035a8335 100644 --- a/java/core/src/test/java/com/google/protobuf/MapTest.java +++ b/java/core/src/test/java/com/google/protobuf/MapTest.java @@ -36,12 +36,12 @@ import com.google.protobuf.Descriptors.EnumDescriptor; import com.google.protobuf.Descriptors.EnumValueDescriptor; import com.google.protobuf.Descriptors.FieldDescriptor; import map_test.MapTestProto.BizarroTestMap; +import map_test.MapTestProto.ReservedAsMapField; +import map_test.MapTestProto.ReservedAsMapFieldWithEnumValue; import map_test.MapTestProto.TestMap; import map_test.MapTestProto.TestMap.MessageValue; import map_test.MapTestProto.TestMapOrBuilder; import map_test.MapTestProto.TestOnChangeEventPropagation; -import junit.framework.TestCase; - import java.io.ByteArrayOutputStream; import java.io.IOException; import java.util.ArrayList; @@ -49,6 +49,7 @@ import java.util.Arrays; import java.util.HashMap; import java.util.List; import java.util.Map; +import junit.framework.TestCase; /** * Unit tests for map fields. @@ -1307,6 +1308,171 @@ public class MapTest extends TestCase { } } + public void testReservedWordsFieldNames() { + ReservedAsMapField.newBuilder().build(); + ReservedAsMapFieldWithEnumValue.newBuilder().build(); + } + + public void testDeterministicSerialziation() throws Exception { + TestMap.Builder builder = TestMap.newBuilder(); + // int32->int32 + builder.putInt32ToInt32Field(5, 1); + builder.putInt32ToInt32Field(1, 1); + builder.putInt32ToInt32Field(4, 1); + builder.putInt32ToInt32Field(-2, 1); + builder.putInt32ToInt32Field(0, 1); + + // uint32->int32 + builder.putUint32ToInt32Field(5, 1); + builder.putUint32ToInt32Field(1, 1); + builder.putUint32ToInt32Field(4, 1); + builder.putUint32ToInt32Field(-2, 1); + builder.putUint32ToInt32Field(0, 1); + + // int64->int32 + builder.putInt64ToInt32Field(5L, 1); + builder.putInt64ToInt32Field(1L, 1); + builder.putInt64ToInt32Field(4L, 1); + builder.putInt64ToInt32Field(-2L, 1); + builder.putInt64ToInt32Field(0L, 1); + + // string->int32 + builder.putStringToInt32Field("baz", 1); + builder.putStringToInt32Field("foo", 1); + builder.putStringToInt32Field("bar", 1); + builder.putStringToInt32Field("", 1); + builder.putStringToInt32Field("hello", 1); + builder.putStringToInt32Field("world", 1); + + TestMap message = builder.build(); + byte[] serialized = new byte[message.getSerializedSize()]; + CodedOutputStream output = CodedOutputStream.newInstance(serialized); + output.useDeterministicSerialization(); + message.writeTo(output); + output.flush(); + + CodedInputStream input = CodedInputStream.newInstance(serialized); + List int32Keys = new ArrayList(); + List uint32Keys = new ArrayList(); + List int64Keys = new ArrayList(); + List stringKeys = new ArrayList(); + int tag; + while (true) { + tag = input.readTag(); + if (tag == 0) { + break; + } + int length = input.readRawVarint32(); + int oldLimit = input.pushLimit(length); + switch (WireFormat.getTagFieldNumber(tag)) { + case TestMap.STRING_TO_INT32_FIELD_FIELD_NUMBER: + stringKeys.add(readMapStringKey(input)); + break; + case TestMap.INT32_TO_INT32_FIELD_FIELD_NUMBER: + int32Keys.add(readMapIntegerKey(input)); + break; + case TestMap.UINT32_TO_INT32_FIELD_FIELD_NUMBER: + uint32Keys.add(readMapIntegerKey(input)); + break; + case TestMap.INT64_TO_INT32_FIELD_FIELD_NUMBER: + int64Keys.add(readMapLongKey(input)); + break; + default: + fail("Unexpected fields."); + } + input.popLimit(oldLimit); + } + assertEquals( + Arrays.asList(-2, 0, 1, 4, 5), + int32Keys); + assertEquals( + Arrays.asList(-2, 0, 1, 4, 5), + uint32Keys); + assertEquals( + Arrays.asList(-2L, 0L, 1L, 4L, 5L), + int64Keys); + assertEquals( + Arrays.asList("", "bar", "baz", "foo", "hello", "world"), + stringKeys); + } + + public void testInitFromPartialDynamicMessage() { + FieldDescriptor fieldDescriptor = + TestMap.getDescriptor().findFieldByNumber(TestMap.INT32_TO_MESSAGE_FIELD_FIELD_NUMBER); + Descriptor mapEntryType = fieldDescriptor.getMessageType(); + FieldDescriptor keyField = mapEntryType.findFieldByNumber(1); + FieldDescriptor valueField = mapEntryType.findFieldByNumber(2); + DynamicMessage dynamicMessage = + DynamicMessage.newBuilder(TestMap.getDescriptor()) + .addRepeatedField( + fieldDescriptor, + DynamicMessage.newBuilder(mapEntryType) + .setField(keyField, 10) + .setField(valueField, TestMap.MessageValue.newBuilder().setValue(10).build()) + .build()) + .build(); + TestMap message = TestMap.newBuilder().mergeFrom(dynamicMessage).build(); + assertEquals( + TestMap.MessageValue.newBuilder().setValue(10).build(), + message.getInt32ToMessageFieldMap().get(10)); + } + + public void testInitFromFullyDynamicMessage() { + FieldDescriptor fieldDescriptor = + TestMap.getDescriptor().findFieldByNumber(TestMap.INT32_TO_MESSAGE_FIELD_FIELD_NUMBER); + Descriptor mapEntryType = fieldDescriptor.getMessageType(); + FieldDescriptor keyField = mapEntryType.findFieldByNumber(1); + FieldDescriptor valueField = mapEntryType.findFieldByNumber(2); + DynamicMessage dynamicMessage = + DynamicMessage.newBuilder(TestMap.getDescriptor()) + .addRepeatedField( + fieldDescriptor, + DynamicMessage.newBuilder(mapEntryType) + .setField(keyField, 10) + .setField( + valueField, + DynamicMessage.newBuilder(TestMap.MessageValue.getDescriptor()) + .setField( + TestMap.MessageValue.getDescriptor().findFieldByName("value"), 10) + .build()) + .build()) + .build(); + TestMap message = TestMap.newBuilder().mergeFrom(dynamicMessage).build(); + assertEquals( + TestMap.MessageValue.newBuilder().setValue(10).build(), + message.getInt32ToMessageFieldMap().get(10)); + } + + private int readMapIntegerKey(CodedInputStream input) throws IOException { + int tag = input.readTag(); + assertEquals(WireFormat.makeTag(1, WireFormat.WIRETYPE_VARINT), tag); + int ret = input.readInt32(); + // skip the value field. + input.skipField(input.readTag()); + assertTrue(input.isAtEnd()); + return ret; + } + + private long readMapLongKey(CodedInputStream input) throws IOException { + int tag = input.readTag(); + assertEquals(WireFormat.makeTag(1, WireFormat.WIRETYPE_VARINT), tag); + long ret = input.readInt64(); + // skip the value field. + input.skipField(input.readTag()); + assertTrue(input.isAtEnd()); + return ret; + } + + private String readMapStringKey(CodedInputStream input) throws IOException { + int tag = input.readTag(); + assertEquals(WireFormat.makeTag(1, WireFormat.WIRETYPE_LENGTH_DELIMITED), tag); + String ret = input.readString(); + // skip the value field. + input.skipField(input.readTag()); + assertTrue(input.isAtEnd()); + return ret; + } + private static Map newMap(K key1, V value1) { Map map = new HashMap(); map.put(key1, value1); diff --git a/java/core/src/test/java/com/google/protobuf/MessageTest.java b/java/core/src/test/java/com/google/protobuf/MessageTest.java index dcd1aba7..75b79a34 100644 --- a/java/core/src/test/java/com/google/protobuf/MessageTest.java +++ b/java/core/src/test/java/com/google/protobuf/MessageTest.java @@ -35,10 +35,8 @@ import protobuf_unittest.UnittestProto.TestAllExtensions; import protobuf_unittest.UnittestProto.TestAllTypes; import protobuf_unittest.UnittestProto.TestRequired; import protobuf_unittest.UnittestProto.TestRequiredForeign; - -import junit.framework.TestCase; - import java.util.List; +import junit.framework.TestCase; /** * Misc. unit tests for message operations that apply to both generated diff --git a/java/core/src/test/java/com/google/protobuf/NestedBuildersTest.java b/java/core/src/test/java/com/google/protobuf/NestedBuildersTest.java index 542e28c0..03ed65a5 100644 --- a/java/core/src/test/java/com/google/protobuf/NestedBuildersTest.java +++ b/java/core/src/test/java/com/google/protobuf/NestedBuildersTest.java @@ -32,11 +32,9 @@ package com.google.protobuf; import protobuf_unittest.Vehicle; import protobuf_unittest.Wheel; - -import junit.framework.TestCase; - import java.util.ArrayList; import java.util.List; +import junit.framework.TestCase; /** * Test cases that exercise end-to-end use cases involving diff --git a/java/core/src/test/java/com/google/protobuf/NioByteStringTest.java b/java/core/src/test/java/com/google/protobuf/NioByteStringTest.java index 6be5b93c..c388bd05 100644 --- a/java/core/src/test/java/com/google/protobuf/NioByteStringTest.java +++ b/java/core/src/test/java/com/google/protobuf/NioByteStringTest.java @@ -32,8 +32,6 @@ package com.google.protobuf; import static com.google.protobuf.Internal.UTF_8; -import junit.framework.TestCase; - import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; import java.io.EOFException; @@ -48,6 +46,7 @@ import java.nio.ByteBuffer; import java.util.Arrays; import java.util.List; import java.util.NoSuchElementException; +import junit.framework.TestCase; /** * Tests for {@link NioByteString}. diff --git a/java/core/src/test/java/com/google/protobuf/ParseExceptionsTest.java b/java/core/src/test/java/com/google/protobuf/ParseExceptionsTest.java index bf1f1d71..e376b1cd 100644 --- a/java/core/src/test/java/com/google/protobuf/ParseExceptionsTest.java +++ b/java/core/src/test/java/com/google/protobuf/ParseExceptionsTest.java @@ -36,16 +36,14 @@ import static org.junit.Assert.assertTrue; import static org.junit.Assert.fail; import com.google.protobuf.DescriptorProtos.DescriptorProto; - -import org.junit.Test; -import org.junit.runner.RunWith; -import org.junit.runners.JUnit4; - import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; import java.io.FilterInputStream; import java.io.IOException; import java.io.InputStream; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.junit.runners.JUnit4; /** * Tests the exceptions thrown when parsing from a stream. The methods on the {@link Parser} diff --git a/java/core/src/test/java/com/google/protobuf/ParserTest.java b/java/core/src/test/java/com/google/protobuf/ParserTest.java index 30842d2c..7086912b 100644 --- a/java/core/src/test/java/com/google/protobuf/ParserTest.java +++ b/java/core/src/test/java/com/google/protobuf/ParserTest.java @@ -42,13 +42,11 @@ import protobuf_unittest.UnittestProto.TestAllTypes; import protobuf_unittest.UnittestProto.TestEmptyMessage; import protobuf_unittest.UnittestProto.TestParsingMerge; import protobuf_unittest.UnittestProto.TestRequired; - -import junit.framework.TestCase; - import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; import java.io.IOException; import java.io.InputStream; +import junit.framework.TestCase; /** * Unit test for {@link Parser}. diff --git a/java/core/src/test/java/com/google/protobuf/ProtobufArrayListTest.java b/java/core/src/test/java/com/google/protobuf/ProtobufArrayListTest.java index 3f45e226..af717bfd 100644 --- a/java/core/src/test/java/com/google/protobuf/ProtobufArrayListTest.java +++ b/java/core/src/test/java/com/google/protobuf/ProtobufArrayListTest.java @@ -32,12 +32,11 @@ package com.google.protobuf; import static java.util.Arrays.asList; -import junit.framework.TestCase; - import java.util.Collections; import java.util.ConcurrentModificationException; import java.util.Iterator; import java.util.List; +import junit.framework.TestCase; /** * Tests for {@link ProtobufArrayList}. diff --git a/java/core/src/test/java/com/google/protobuf/RepeatedFieldBuilderV3Test.java b/java/core/src/test/java/com/google/protobuf/RepeatedFieldBuilderV3Test.java index 241a4354..edbd0afd 100644 --- a/java/core/src/test/java/com/google/protobuf/RepeatedFieldBuilderV3Test.java +++ b/java/core/src/test/java/com/google/protobuf/RepeatedFieldBuilderV3Test.java @@ -32,11 +32,9 @@ package com.google.protobuf; import protobuf_unittest.UnittestProto.TestAllTypes; import protobuf_unittest.UnittestProto.TestAllTypesOrBuilder; - -import junit.framework.TestCase; - import java.util.Collections; import java.util.List; +import junit.framework.TestCase; /** * Tests for {@link RepeatedFieldBuilderV3}. This tests basic functionality. diff --git a/java/core/src/test/java/com/google/protobuf/ServiceTest.java b/java/core/src/test/java/com/google/protobuf/ServiceTest.java index b902737d..b895ad8d 100644 --- a/java/core/src/test/java/com/google/protobuf/ServiceTest.java +++ b/java/core/src/test/java/com/google/protobuf/ServiceTest.java @@ -42,15 +42,13 @@ import protobuf_unittest.UnittestProto.FooResponse; import protobuf_unittest.UnittestProto.TestAllTypes; import protobuf_unittest.UnittestProto.TestService; +import java.util.HashSet; +import java.util.Set; import junit.framework.TestCase; - import org.easymock.classextension.EasyMock; import org.easymock.IArgumentMatcher; import org.easymock.classextension.IMocksControl; -import java.util.HashSet; -import java.util.Set; - /** * Tests services and stubs. * @@ -271,6 +269,8 @@ public class ServiceTest extends TestCase { file.getServices().get(0).getMethods().get(0).getName()); } + + // ================================================================= /** diff --git a/java/core/src/test/java/com/google/protobuf/SmallSortedMapTest.java b/java/core/src/test/java/com/google/protobuf/SmallSortedMapTest.java index e96ecd65..a7f8342d 100644 --- a/java/core/src/test/java/com/google/protobuf/SmallSortedMapTest.java +++ b/java/core/src/test/java/com/google/protobuf/SmallSortedMapTest.java @@ -30,8 +30,6 @@ package com.google.protobuf; -import junit.framework.TestCase; - import java.util.ArrayList; import java.util.Arrays; import java.util.HashMap; @@ -40,6 +38,7 @@ import java.util.List; import java.util.Map; import java.util.Set; import java.util.TreeSet; +import junit.framework.TestCase; /** * @author darick@google.com Darick Tong diff --git a/java/core/src/test/java/com/google/protobuf/TestUtil.java b/java/core/src/test/java/com/google/protobuf/TestUtil.java index d94f99e3..d4a18a22 100644 --- a/java/core/src/test/java/com/google/protobuf/TestUtil.java +++ b/java/core/src/test/java/com/google/protobuf/TestUtil.java @@ -232,12 +232,10 @@ import protobuf_unittest.UnittestProto.TestOneof2; import protobuf_unittest.UnittestProto.TestPackedExtensions; import protobuf_unittest.UnittestProto.TestPackedTypes; import protobuf_unittest.UnittestProto.TestUnpackedTypes; - -import junit.framework.Assert; - import java.io.File; import java.io.IOException; import java.io.RandomAccessFile; +import junit.framework.Assert; /** * Contains methods for setting all fields of {@code TestAllTypes} to @@ -259,6 +257,13 @@ public final class TestUtil { return ByteString.copyFrom(str.getBytes(Internal.UTF_8)); } + /** + * Dirties the message by resetting the momoized serialized size. + */ + public static void resetMemoizedSize(AbstractMessage message) { + message.memoizedSize = -1; + } + /** * Get a {@code TestAllTypes} with all fields set as they would be by * {@link #setAllFields(TestAllTypes.Builder)}. diff --git a/java/core/src/test/java/com/google/protobuf/TextFormatTest.java b/java/core/src/test/java/com/google/protobuf/TextFormatTest.java index 14783b0a..6a91b02f 100644 --- a/java/core/src/test/java/com/google/protobuf/TextFormatTest.java +++ b/java/core/src/test/java/com/google/protobuf/TextFormatTest.java @@ -42,11 +42,9 @@ import protobuf_unittest.UnittestProto.TestAllTypes.NestedMessage; import protobuf_unittest.UnittestProto.TestEmptyMessage; import protobuf_unittest.UnittestProto.TestOneof2; import proto2_wireformat_unittest.UnittestMsetWireFormat.TestMessageSet; - -import junit.framework.TestCase; - import java.io.StringReader; import java.util.List; +import junit.framework.TestCase; /** * Test case for {@link TextFormat}. @@ -992,10 +990,35 @@ public class TextFormatTest extends TestCase { assertParseSuccessWithOverwriteForbidden("repeated_nested_message [{ bb: 1 }, { bb: 2 }]\n"); } + public void testParseShortRepeatedFormOfEmptyRepeatedFields() throws Exception { + assertParseSuccessWithOverwriteForbidden("repeated_foreign_enum: []"); + assertParseSuccessWithOverwriteForbidden("repeated_int32: []\n"); + assertParseSuccessWithOverwriteForbidden("RepeatedGroup []\n"); + assertParseSuccessWithOverwriteForbidden("repeated_nested_message []\n"); + } + + public void testParseShortRepeatedFormWithTrailingComma() throws Exception { + assertParseErrorWithOverwriteForbidden( + "1:38: Expected identifier. Found \']\'", + "repeated_foreign_enum: [FOREIGN_FOO, ]\n"); + assertParseErrorWithOverwriteForbidden( + "1:22: Couldn't parse integer: For input string: \"]\"", + "repeated_int32: [ 1, ]\n"); + assertParseErrorWithOverwriteForbidden( + "1:25: Expected \"{\".", + "RepeatedGroup [{ a: 1 },]\n"); + assertParseErrorWithOverwriteForbidden( + "1:37: Expected \"{\".", + "repeated_nested_message [{ bb: 1 }, ]\n"); + } + public void testParseShortRepeatedFormOfNonRepeatedFields() throws Exception { assertParseErrorWithOverwriteForbidden( "1:17: Couldn't parse integer: For input string: \"[\"", "optional_int32: [1]\n"); + assertParseErrorWithOverwriteForbidden( + "1:17: Couldn't parse integer: For input string: \"[\"", + "optional_int32: []\n"); } // ======================================================================= diff --git a/java/core/src/test/java/com/google/protobuf/UnknownFieldSetLiteTest.java b/java/core/src/test/java/com/google/protobuf/UnknownFieldSetLiteTest.java index 573cd665..26ea850e 100644 --- a/java/core/src/test/java/com/google/protobuf/UnknownFieldSetLiteTest.java +++ b/java/core/src/test/java/com/google/protobuf/UnknownFieldSetLiteTest.java @@ -35,11 +35,9 @@ import com.google.protobuf.UnittestLite.TestAllTypesLite; import protobuf_unittest.lite_equals_and_hash.LiteEqualsAndHash; import protobuf_unittest.lite_equals_and_hash.LiteEqualsAndHash.Bar; import protobuf_unittest.lite_equals_and_hash.LiteEqualsAndHash.Foo; - -import junit.framework.TestCase; - import java.io.ByteArrayOutputStream; import java.io.IOException; +import junit.framework.TestCase; /** * Tests for {@link UnknownFieldSetLite}. 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 32380f70..f81e90b4 100644 --- a/java/core/src/test/java/com/google/protobuf/UnknownFieldSetTest.java +++ b/java/core/src/test/java/com/google/protobuf/UnknownFieldSetTest.java @@ -38,11 +38,9 @@ import protobuf_unittest.UnittestProto.TestEmptyMessage; import protobuf_unittest.UnittestProto.TestEmptyMessageWithExtensions; import protobuf_unittest.UnittestProto.TestPackedExtensions; import protobuf_unittest.UnittestProto.TestPackedTypes; - -import junit.framework.TestCase; - import java.util.Arrays; import java.util.Map; +import junit.framework.TestCase; /** * Tests related to unknown field handling. diff --git a/java/core/src/test/java/com/google/protobuf/UnmodifiableLazyStringListTest.java b/java/core/src/test/java/com/google/protobuf/UnmodifiableLazyStringListTest.java index b1c75fc3..00f201ca 100644 --- a/java/core/src/test/java/com/google/protobuf/UnmodifiableLazyStringListTest.java +++ b/java/core/src/test/java/com/google/protobuf/UnmodifiableLazyStringListTest.java @@ -30,11 +30,10 @@ package com.google.protobuf; -import junit.framework.TestCase; - import java.util.Iterator; import java.util.List; import java.util.ListIterator; +import junit.framework.TestCase; /** * Tests for {@link UnmodifiableLazyStringList}. diff --git a/java/core/src/test/java/com/google/protobuf/WireFormatTest.java b/java/core/src/test/java/com/google/protobuf/WireFormatTest.java index e66b371c..370860c2 100644 --- a/java/core/src/test/java/com/google/protobuf/WireFormatTest.java +++ b/java/core/src/test/java/com/google/protobuf/WireFormatTest.java @@ -44,12 +44,10 @@ import protobuf_unittest.UnittestProto.TestOneofBackwardsCompatible; import protobuf_unittest.UnittestProto.TestPackedExtensions; import protobuf_unittest.UnittestProto.TestPackedTypes; import proto2_wireformat_unittest.UnittestMsetWireFormat.TestMessageSet; - -import junit.framework.TestCase; - import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; import java.util.List; +import junit.framework.TestCase; /** * Tests related to parsing and serialization. diff --git a/java/core/src/test/proto/com/google/protobuf/field_presence_test.proto b/java/core/src/test/proto/com/google/protobuf/field_presence_test.proto index 86cdd286..2367bd8b 100644 --- a/java/core/src/test/proto/com/google/protobuf/field_presence_test.proto +++ b/java/core/src/test/proto/com/google/protobuf/field_presence_test.proto @@ -36,7 +36,6 @@ import "google/protobuf/unittest.proto"; option java_package = "com.google.protobuf"; option java_outer_classname = "FieldPresenceTestProto"; -option java_generate_equals_and_hash = true; message TestAllTypes { enum NestedEnum { diff --git a/java/core/src/test/proto/com/google/protobuf/map_for_proto2_lite_test.proto b/java/core/src/test/proto/com/google/protobuf/map_for_proto2_lite_test.proto index de3336a5..2ca0251c 100644 --- a/java/core/src/test/proto/com/google/protobuf/map_for_proto2_lite_test.proto +++ b/java/core/src/test/proto/com/google/protobuf/map_for_proto2_lite_test.proto @@ -32,7 +32,6 @@ syntax = "proto2"; option java_outer_classname = "MapForProto2TestProto"; -option java_generate_equals_and_hash = true; message TestMap { message MessageValue { @@ -81,6 +80,42 @@ message BizarroTestMap { map int32_to_message_field = 5; // different key and value types map string_to_int32_field = 6; // same key type, different value } + +// Used to test that java reserved words can be used as protobuf field names +// Not all reserved words are tested (to avoid bloat) but instead an arbitrary +// subset of them chosen to cover various keyword categories like +// type, modifier, declaration, etc. +message ReservedAsMapField { + map if = 1; + map const = 2; + map private = 3; + map class = 4; + map int = 5; + map void = 6; + map string = 7; // These are also proto keywords + map package = 8; + map enum = 9; // Most recent Java reserved word + map null = 10; + // null is not a 'reserved word' per se but as a literal needs similar care +} + +message ReservedAsMapFieldWithEnumValue { + enum SampleEnum { + A = 0; + B = 1; + } + map if = 1; + map const = 2; + map private = 3; + map class = 4; + map int = 5; + map void = 6; + map string = 7; // These are also proto keywords + map package = 8; + map enum = 9; // Most recent Java reserved word + map null = 10; + // null is not a 'reserved word' per se but as a literal needs similar care +} package map_for_proto2_lite_test; option java_package = "map_lite_test"; option optimize_for = LITE_RUNTIME; diff --git a/java/core/src/test/proto/com/google/protobuf/map_for_proto2_test.proto b/java/core/src/test/proto/com/google/protobuf/map_for_proto2_test.proto index 0c92b0ae..974f8a2c 100644 --- a/java/core/src/test/proto/com/google/protobuf/map_for_proto2_test.proto +++ b/java/core/src/test/proto/com/google/protobuf/map_for_proto2_test.proto @@ -34,7 +34,6 @@ package map_for_proto2_test; option java_package = "map_test"; option java_outer_classname = "MapForProto2TestProto"; -option java_generate_equals_and_hash = true; message TestMap { message MessageValue { @@ -83,3 +82,39 @@ message BizarroTestMap { map int32_to_message_field = 5; // different key and value types map string_to_int32_field = 6; // same key type, different value } + +// Used to test that java reserved words can be used as protobuf field names +// Not all reserved words are tested (to avoid bloat) but instead an arbitrary +// subset of them chosen to cover various keyword categories like +// type, modifier, declaration, etc. +message ReservedAsMapField { + map if = 1; + map const = 2; + map private = 3; + map class = 4; + map int = 5; + map void = 6; + map string = 7; // These are also proto keywords + map package = 8; + map enum = 9; // Most recent Java reserved word + map null = 10; + // null is not a 'reserved word' per se but as a literal needs similar care +} + +message ReservedAsMapFieldWithEnumValue { + enum SampleEnum { + A = 0; + B = 1; + } + map if = 1; + map const = 2; + map private = 3; + map class = 4; + map int = 5; + map void = 6; + map string = 7; // These are also proto keywords + map package = 8; + map enum = 9; // Most recent Java reserved word + map null = 10; + // null is not a 'reserved word' per se but as a literal needs similar care +} diff --git a/java/core/src/test/proto/com/google/protobuf/map_test.proto b/java/core/src/test/proto/com/google/protobuf/map_test.proto index 9eb63fc3..bc2105e5 100644 --- a/java/core/src/test/proto/com/google/protobuf/map_test.proto +++ b/java/core/src/test/proto/com/google/protobuf/map_test.proto @@ -34,7 +34,6 @@ package map_test; option java_package = "map_test"; option java_outer_classname = "MapTestProto"; -option java_generate_equals_and_hash = true; message TestMap { message MessageValue { @@ -53,6 +52,8 @@ message TestMap { map int32_to_enum_field = 4; map int32_to_message_field = 5; map string_to_int32_field = 6; + map uint32_to_int32_field = 7; + map int64_to_int32_field = 8; } // Used to test that a nested builder containing map fields will properly @@ -71,3 +72,39 @@ message BizarroTestMap { map int32_to_message_field = 5; // different key and value types map string_to_int32_field = 6; // same key type, different value } + +// Used to test that java reserved words can be used as protobuf field names +// Not all reserved words are tested (to avoid bloat) but instead an arbitrary +// subset of them chosen to cover various keyword categories like +// type, modifier, declaration, etc. +message ReservedAsMapField { + map if = 1; + map const = 2; + map private = 3; + map class = 4; + map int = 5; + map void = 6; + map string = 7; // These are also proto keywords + map package = 8; + map enum = 9; // Most recent Java reserved word + map null = 10; + // null is not a 'reserved word' per se but as a literal needs similar care +} + +message ReservedAsMapFieldWithEnumValue { + enum SampleEnum { + A = 0; + B = 1; + } + map if = 1; + map const = 2; + map private = 3; + map class = 4; + map int = 5; + map void = 6; + map string = 7; // These are also proto keywords + map package = 8; + map enum = 9; // Most recent Java reserved word + map null = 10; + // null is not a 'reserved word' per se but as a literal needs similar care +} diff --git a/java/core/src/test/proto/com/google/protobuf/test_bad_identifiers.proto b/java/core/src/test/proto/com/google/protobuf/test_bad_identifiers.proto index 2b1f65e4..d2c77936 100644 --- a/java/core/src/test/proto/com/google/protobuf/test_bad_identifiers.proto +++ b/java/core/src/test/proto/com/google/protobuf/test_bad_identifiers.proto @@ -43,7 +43,6 @@ package io_protocol_tests; option java_package = "com.google.protobuf"; option java_outer_classname = "TestBadIdentifiersProto"; -option java_generate_equals_and_hash = true; message TestMessage { optional string cached_size = 1; diff --git a/java/src/main/java/com/google/protobuf/AbstractMessage.java b/java/src/main/java/com/google/protobuf/AbstractMessage.java new file mode 100755 index 00000000..7639efcf --- /dev/null +++ b/java/src/main/java/com/google/protobuf/AbstractMessage.java @@ -0,0 +1,646 @@ +// 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. + +package com.google.protobuf; + +import com.google.protobuf.Descriptors.EnumValueDescriptor; +import com.google.protobuf.Descriptors.FieldDescriptor; +import com.google.protobuf.Descriptors.OneofDescriptor; +import com.google.protobuf.Internal.EnumLite; + +import java.io.IOException; +import java.io.InputStream; +import java.util.Arrays; +import java.util.Collections; +import java.util.HashMap; +import java.util.Iterator; +import java.util.List; +import java.util.Map; + +/** + * A partial implementation of the {@link Message} interface which implements + * as many methods of that interface as possible in terms of other methods. + * + * @author kenton@google.com Kenton Varda + */ +public abstract class AbstractMessage + // TODO(dweis): Update GeneratedMessage to parameterize with MessageType and BuilderType. + extends AbstractMessageLite + implements Message { + + @Override + public boolean isInitialized() { + return MessageReflection.isInitialized(this); + } + + /** + * Interface for the parent of a Builder that allows the builder to + * communicate invalidations back to the parent for use when using nested + * builders. + */ + protected interface BuilderParent { + + /** + * A builder becomes dirty whenever a field is modified -- including fields + * in nested builders -- and becomes clean when build() is called. Thus, + * when a builder becomes dirty, all its parents become dirty as well, and + * when it becomes clean, all its children become clean. The dirtiness + * state is used to invalidate certain cached values. + *
+ * To this end, a builder calls markDirty() on its parent whenever it + * transitions from clean to dirty. The parent must propagate this call to + * its own parent, unless it was already dirty, in which case the + * grandparent must necessarily already be dirty as well. The parent can + * only transition back to "clean" after calling build() on all children. + */ + void markDirty(); + } + + /** Create a nested builder. */ + protected Message.Builder newBuilderForType(BuilderParent parent) { + throw new UnsupportedOperationException("Nested builder is not supported for this type."); + } + + + @Override + public List findInitializationErrors() { + return MessageReflection.findMissingFields(this); + } + + @Override + public String getInitializationErrorString() { + return MessageReflection.delimitWithCommas(findInitializationErrors()); + } + + /** TODO(jieluo): Clear it when all subclasses have implemented this method. */ + @Override + public boolean hasOneof(OneofDescriptor oneof) { + throw new UnsupportedOperationException("hasOneof() is not implemented."); + } + + /** TODO(jieluo): Clear it when all subclasses have implemented this method. */ + @Override + public FieldDescriptor getOneofFieldDescriptor(OneofDescriptor oneof) { + throw new UnsupportedOperationException( + "getOneofFieldDescriptor() is not implemented."); + } + + @Override + public final String toString() { + return TextFormat.printToString(this); + } + + @Override + public void writeTo(final CodedOutputStream output) throws IOException { + MessageReflection.writeMessageTo(this, getAllFields(), output, false); + } + + protected int memoizedSize = -1; + + @Override + public int getSerializedSize() { + int size = memoizedSize; + if (size != -1) { + return size; + } + + memoizedSize = MessageReflection.getSerializedSize(this, getAllFields()); + return memoizedSize; + } + + @Override + public boolean equals(final Object other) { + if (other == this) { + return true; + } + if (!(other instanceof Message)) { + return false; + } + final Message otherMessage = (Message) other; + if (getDescriptorForType() != otherMessage.getDescriptorForType()) { + return false; + } + return compareFields(getAllFields(), otherMessage.getAllFields()) && + getUnknownFields().equals(otherMessage.getUnknownFields()); + } + + @Override + public int hashCode() { + int hash = memoizedHashCode; + if (hash == 0) { + hash = 41; + hash = (19 * hash) + getDescriptorForType().hashCode(); + hash = hashFields(hash, getAllFields()); + hash = (29 * hash) + getUnknownFields().hashCode(); + memoizedHashCode = hash; + } + return hash; + } + + private static ByteString toByteString(Object value) { + if (value instanceof byte[]) { + return ByteString.copyFrom((byte[]) value); + } else { + return (ByteString) value; + } + } + + /** + * Compares two bytes fields. The parameters must be either a byte array or a + * ByteString object. They can be of different type though. + */ + private static boolean compareBytes(Object a, Object b) { + if (a instanceof byte[] && b instanceof byte[]) { + return Arrays.equals((byte[])a, (byte[])b); + } + return toByteString(a).equals(toByteString(b)); + } + + /** + * Converts a list of MapEntry messages into a Map used for equals() and + * hashCode(). + */ + @SuppressWarnings({"rawtypes", "unchecked"}) + private static Map convertMapEntryListToMap(List list) { + if (list.isEmpty()) { + return Collections.emptyMap(); + } + Map result = new HashMap(); + Iterator iterator = list.iterator(); + Message entry = (Message) iterator.next(); + Descriptors.Descriptor descriptor = entry.getDescriptorForType(); + Descriptors.FieldDescriptor key = descriptor.findFieldByName("key"); + Descriptors.FieldDescriptor value = descriptor.findFieldByName("value"); + Object fieldValue = entry.getField(value); + if (fieldValue instanceof EnumValueDescriptor) { + fieldValue = ((EnumValueDescriptor) fieldValue).getNumber(); + } + result.put(entry.getField(key), fieldValue); + while (iterator.hasNext()) { + entry = (Message) iterator.next(); + fieldValue = entry.getField(value); + if (fieldValue instanceof EnumValueDescriptor) { + fieldValue = ((EnumValueDescriptor) fieldValue).getNumber(); + } + result.put(entry.getField(key), fieldValue); + } + return result; + } + + /** + * Compares two map fields. The parameters must be a list of MapEntry + * messages. + */ + @SuppressWarnings({"rawtypes", "unchecked"}) + private static boolean compareMapField(Object a, Object b) { + Map ma = convertMapEntryListToMap((List) a); + Map mb = convertMapEntryListToMap((List) b); + return MapFieldLite.equals(ma, mb); + } + + /** + * Compares two set of fields. + * This method is used to implement {@link AbstractMessage#equals(Object)} + * and {@link AbstractMutableMessage#equals(Object)}. It takes special care + * of bytes fields because immutable messages and mutable messages use + * different Java type to reprensent a bytes field and this method should be + * able to compare immutable messages, mutable messages and also an immutable + * message to a mutable message. + */ + static boolean compareFields(Map a, + Map b) { + if (a.size() != b.size()) { + return false; + } + for (FieldDescriptor descriptor : a.keySet()) { + if (!b.containsKey(descriptor)) { + return false; + } + Object value1 = a.get(descriptor); + Object value2 = b.get(descriptor); + if (descriptor.getType() == FieldDescriptor.Type.BYTES) { + if (descriptor.isRepeated()) { + List list1 = (List) value1; + List list2 = (List) value2; + if (list1.size() != list2.size()) { + return false; + } + for (int i = 0; i < list1.size(); i++) { + if (!compareBytes(list1.get(i), list2.get(i))) { + return false; + } + } + } else { + // Compares a singular bytes field. + if (!compareBytes(value1, value2)) { + return false; + } + } + } else if (descriptor.isMapField()) { + if (!compareMapField(value1, value2)) { + return false; + } + } else { + // Compare non-bytes fields. + if (!value1.equals(value2)) { + return false; + } + } + } + return true; + } + + /** + * Calculates the hash code of a map field. {@code value} must be a list of + * MapEntry messages. + */ + @SuppressWarnings("unchecked") + private static int hashMapField(Object value) { + return MapFieldLite.calculateHashCodeForMap(convertMapEntryListToMap((List) value)); + } + + /** Get a hash code for given fields and values, using the given seed. */ + @SuppressWarnings("unchecked") + protected static int hashFields(int hash, Map map) { + for (Map.Entry entry : map.entrySet()) { + FieldDescriptor field = entry.getKey(); + Object value = entry.getValue(); + hash = (37 * hash) + field.getNumber(); + if (field.isMapField()) { + hash = (53 * hash) + hashMapField(value); + } else if (field.getType() != FieldDescriptor.Type.ENUM){ + hash = (53 * hash) + value.hashCode(); + } else if (field.isRepeated()) { + List list = (List) value; + hash = (53 * hash) + Internal.hashEnumList(list); + } else { + hash = (53 * hash) + Internal.hashEnum((EnumLite) value); + } + } + return hash; + } + + /** + * Package private helper method for AbstractParser to create + * UninitializedMessageException with missing field information. + */ + @Override + UninitializedMessageException newUninitializedMessageException() { + return Builder.newUninitializedMessageException(this); + } + + // ================================================================= + + /** + * A partial implementation of the {@link Message.Builder} interface which + * implements as many methods of that interface as possible in terms of + * other methods. + */ + @SuppressWarnings("unchecked") + public static abstract class Builder> + extends AbstractMessageLite.Builder + implements Message.Builder { + // The compiler produces an error if this is not declared explicitly. + @Override + public abstract BuilderType clone(); + + /** TODO(jieluo): Clear it when all subclasses have implemented this method. */ + @Override + public boolean hasOneof(OneofDescriptor oneof) { + throw new UnsupportedOperationException("hasOneof() is not implemented."); + } + + /** TODO(jieluo): Clear it when all subclasses have implemented this method. */ + @Override + public FieldDescriptor getOneofFieldDescriptor(OneofDescriptor oneof) { + throw new UnsupportedOperationException( + "getOneofFieldDescriptor() is not implemented."); + } + + /** TODO(jieluo): Clear it when all subclasses have implemented this method. */ + @Override + public BuilderType clearOneof(OneofDescriptor oneof) { + throw new UnsupportedOperationException("clearOneof() is not implemented."); + } + + @Override + public BuilderType clear() { + for (final Map.Entry entry : + getAllFields().entrySet()) { + clearField(entry.getKey()); + } + return (BuilderType) this; + } + + @Override + public List findInitializationErrors() { + return MessageReflection.findMissingFields(this); + } + + @Override + public String getInitializationErrorString() { + return MessageReflection.delimitWithCommas(findInitializationErrors()); + } + + @Override + protected BuilderType internalMergeFrom(AbstractMessageLite other) { + return mergeFrom((Message) other); + } + + @Override + public BuilderType mergeFrom(final Message other) { + if (other.getDescriptorForType() != getDescriptorForType()) { + throw new IllegalArgumentException( + "mergeFrom(Message) can only merge messages of the same type."); + } + + // Note: We don't attempt to verify that other's fields have valid + // types. Doing so would be a losing battle. We'd have to verify + // all sub-messages as well, and we'd have to make copies of all of + // them to insure that they don't change after verification (since + // the Message interface itself cannot enforce immutability of + // implementations). + // TODO(kenton): Provide a function somewhere called makeDeepCopy() + // which allows people to make secure deep copies of messages. + + for (final Map.Entry entry : + other.getAllFields().entrySet()) { + final FieldDescriptor field = entry.getKey(); + if (field.isRepeated()) { + for (final Object element : (List)entry.getValue()) { + addRepeatedField(field, element); + } + } else if (field.getJavaType() == FieldDescriptor.JavaType.MESSAGE) { + final Message existingValue = (Message)getField(field); + if (existingValue == existingValue.getDefaultInstanceForType()) { + setField(field, entry.getValue()); + } else { + setField(field, + existingValue.newBuilderForType() + .mergeFrom(existingValue) + .mergeFrom((Message)entry.getValue()) + .build()); + } + } else { + setField(field, entry.getValue()); + } + } + + mergeUnknownFields(other.getUnknownFields()); + + return (BuilderType) this; + } + + @Override + public BuilderType mergeFrom(final CodedInputStream input) + throws IOException { + return mergeFrom(input, ExtensionRegistry.getEmptyRegistry()); + } + + @Override + public BuilderType mergeFrom( + final CodedInputStream input, + final ExtensionRegistryLite extensionRegistry) + throws IOException { + final UnknownFieldSet.Builder unknownFields = + UnknownFieldSet.newBuilder(getUnknownFields()); + while (true) { + final int tag = input.readTag(); + if (tag == 0) { + break; + } + + MessageReflection.BuilderAdapter builderAdapter = + new MessageReflection.BuilderAdapter(this); + if (!MessageReflection.mergeFieldFrom(input, unknownFields, + extensionRegistry, + getDescriptorForType(), + builderAdapter, + tag)) { + // end group tag + break; + } + } + setUnknownFields(unknownFields.build()); + return (BuilderType) this; + } + + @Override + public BuilderType mergeUnknownFields(final UnknownFieldSet unknownFields) { + setUnknownFields( + UnknownFieldSet.newBuilder(getUnknownFields()) + .mergeFrom(unknownFields) + .build()); + return (BuilderType) this; + } + + @Override + public Message.Builder getFieldBuilder(final FieldDescriptor field) { + throw new UnsupportedOperationException( + "getFieldBuilder() called on an unsupported message type."); + } + + @Override + public Message.Builder getRepeatedFieldBuilder(final FieldDescriptor field, int index) { + throw new UnsupportedOperationException( + "getRepeatedFieldBuilder() called on an unsupported message type."); + } + + @Override + public String toString() { + return TextFormat.printToString(this); + } + + /** + * Construct an UninitializedMessageException reporting missing fields in + * the given message. + */ + protected static UninitializedMessageException + newUninitializedMessageException(Message message) { + return new UninitializedMessageException( + MessageReflection.findMissingFields(message)); + } + + /** + * Used to support nested builders and called to mark this builder as clean. + * Clean builders will propagate the {@link BuilderParent#markDirty()} event + * to their parent builders, while dirty builders will not, as their parents + * should be dirty already. + * + * NOTE: Implementations that don't support nested builders don't need to + * override this method. + */ + void markClean() { + throw new IllegalStateException("Should be overridden by subclasses."); + } + + /** + * Used to support nested builders and called when this nested builder is + * no longer used by its parent builder and should release the reference + * to its parent builder. + * + * NOTE: Implementations that don't support nested builders don't need to + * override this method. + */ + void dispose() { + throw new IllegalStateException("Should be overridden by subclasses."); + } + + // =============================================================== + // The following definitions seem to be required in order to make javac + // not produce weird errors like: + // + // java/com/google/protobuf/DynamicMessage.java:203: types + // com.google.protobuf.AbstractMessage.Builder< + // com.google.protobuf.DynamicMessage.Builder> and + // com.google.protobuf.AbstractMessage.Builder< + // com.google.protobuf.DynamicMessage.Builder> are incompatible; both + // define mergeFrom(com.google.protobuf.ByteString), but with unrelated + // return types. + // + // Strangely, these lines are only needed if javac is invoked separately + // on AbstractMessage.java and AbstractMessageLite.java. If javac is + // invoked on both simultaneously, it works. (Or maybe the important + // point is whether or not DynamicMessage.java is compiled together with + // AbstractMessageLite.java -- not sure.) I suspect this is a compiler + // bug. + + @Override + public BuilderType mergeFrom(final ByteString data) + throws InvalidProtocolBufferException { + return (BuilderType) super.mergeFrom(data); + } + + @Override + public BuilderType mergeFrom( + final ByteString data, + final ExtensionRegistryLite extensionRegistry) + throws InvalidProtocolBufferException { + return (BuilderType) super.mergeFrom(data, extensionRegistry); + } + + @Override + public BuilderType mergeFrom(final byte[] data) + throws InvalidProtocolBufferException { + return (BuilderType) super.mergeFrom(data); + } + + @Override + public BuilderType mergeFrom( + final byte[] data, final int off, final int len) + throws InvalidProtocolBufferException { + return (BuilderType) super.mergeFrom(data, off, len); + } + + @Override + public BuilderType mergeFrom( + final byte[] data, + final ExtensionRegistryLite extensionRegistry) + throws InvalidProtocolBufferException { + return (BuilderType) super.mergeFrom(data, extensionRegistry); + } + + @Override + public BuilderType mergeFrom( + final byte[] data, final int off, final int len, + final ExtensionRegistryLite extensionRegistry) + throws InvalidProtocolBufferException { + return (BuilderType) super.mergeFrom(data, off, len, extensionRegistry); + } + + @Override + public BuilderType mergeFrom(final InputStream input) + throws IOException { + return (BuilderType) super.mergeFrom(input); + } + + @Override + public BuilderType mergeFrom( + final InputStream input, + final ExtensionRegistryLite extensionRegistry) + throws IOException { + return (BuilderType) super.mergeFrom(input, extensionRegistry); + } + + @Override + public boolean mergeDelimitedFrom(final InputStream input) + throws IOException { + return super.mergeDelimitedFrom(input); + } + + @Override + public boolean mergeDelimitedFrom( + final InputStream input, + final ExtensionRegistryLite extensionRegistry) + throws IOException { + return super.mergeDelimitedFrom(input, extensionRegistry); + } + } + + /** + * @deprecated from v3.0.0-beta-3+, for compatibility with v2.5.0 and v2.6.1 + * generated code. + */ + @Deprecated + protected static int hashLong(long n) { + return (int) (n ^ (n >>> 32)); + } + // + /** + * @deprecated from v3.0.0-beta-3+, for compatibility with v2.5.0 and v2.6.1 + * generated code. + */ + @Deprecated + protected static int hashBoolean(boolean b) { + return b ? 1231 : 1237; + } + // + /** + * @deprecated from v3.0.0-beta-3+, for compatibility with v2.5.0 and v2.6.1 + * generated code. + */ + @Deprecated + protected static int hashEnum(EnumLite e) { + return e.getNumber(); + } + // + /** + * @deprecated from v3.0.0-beta-3+, for compatibility with v2.5.0 and v2.6.1 + * generated code. + */ + @Deprecated + protected static int hashEnumList(List list) { + int hash = 1; + for (EnumLite e : list) { + hash = 31 * hash + hashEnum(e); + } + return hash; + } +} diff --git a/java/src/main/java/com/google/protobuf/AbstractMessageLite.java b/java/src/main/java/com/google/protobuf/AbstractMessageLite.java new file mode 100755 index 00000000..046030f3 --- /dev/null +++ b/java/src/main/java/com/google/protobuf/AbstractMessageLite.java @@ -0,0 +1,384 @@ +// 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. + +package com.google.protobuf; + +import java.io.FilterInputStream; +import java.io.IOException; +import java.io.InputStream; +import java.io.OutputStream; +import java.util.Collection; + +/** + * A partial implementation of the {@link MessageLite} interface which + * implements as many methods of that interface as possible in terms of other + * methods. + * + * @author kenton@google.com Kenton Varda + */ +public abstract class AbstractMessageLite< + MessageType extends AbstractMessageLite, + BuilderType extends AbstractMessageLite.Builder> + implements MessageLite { + protected int memoizedHashCode = 0; + + @Override + public ByteString toByteString() { + try { + final ByteString.CodedBuilder out = + ByteString.newCodedBuilder(getSerializedSize()); + writeTo(out.getCodedOutput()); + return out.build(); + } catch (IOException e) { + throw new RuntimeException(getSerializingExceptionMessage("ByteString"), e); + } + } + + @Override + public byte[] toByteArray() { + try { + final byte[] result = new byte[getSerializedSize()]; + final CodedOutputStream output = CodedOutputStream.newInstance(result); + writeTo(output); + output.checkNoSpaceLeft(); + return result; + } catch (IOException e) { + throw new RuntimeException(getSerializingExceptionMessage("byte array"), e); + } + } + + @Override + public void writeTo(final OutputStream output) throws IOException { + final int bufferSize = + CodedOutputStream.computePreferredBufferSize(getSerializedSize()); + final CodedOutputStream codedOutput = + CodedOutputStream.newInstance(output, bufferSize); + writeTo(codedOutput); + codedOutput.flush(); + } + + @Override + public void writeDelimitedTo(final OutputStream output) throws IOException { + final int serialized = getSerializedSize(); + final int bufferSize = CodedOutputStream.computePreferredBufferSize( + CodedOutputStream.computeRawVarint32Size(serialized) + serialized); + final CodedOutputStream codedOutput = + CodedOutputStream.newInstance(output, bufferSize); + codedOutput.writeRawVarint32(serialized); + writeTo(codedOutput); + codedOutput.flush(); + } + + + /** + * Package private helper method for AbstractParser to create + * UninitializedMessageException. + */ + UninitializedMessageException newUninitializedMessageException() { + return new UninitializedMessageException(this); + } + + private String getSerializingExceptionMessage(String target) { + return "Serializing " + getClass().getName() + " to a " + target + + " threw an IOException (should never happen)."; + } + + protected static void checkByteStringIsUtf8(ByteString byteString) + throws IllegalArgumentException { + if (!byteString.isValidUtf8()) { + throw new IllegalArgumentException("Byte string is not UTF-8."); + } + } + + protected static void addAll(final Iterable values, + final Collection list) { + Builder.addAll(values, list); + } + + /** + * A partial implementation of the {@link Message.Builder} interface which + * implements as many methods of that interface as possible in terms of + * other methods. + */ + @SuppressWarnings("unchecked") + public abstract static class Builder< + MessageType extends AbstractMessageLite, + BuilderType extends Builder> + implements MessageLite.Builder { + // The compiler produces an error if this is not declared explicitly. + @Override + public abstract BuilderType clone(); + + @Override + public BuilderType mergeFrom(final CodedInputStream input) throws IOException { + return mergeFrom(input, ExtensionRegistryLite.getEmptyRegistry()); + } + + // Re-defined here for return type covariance. + @Override + public abstract BuilderType mergeFrom( + final CodedInputStream input, final ExtensionRegistryLite extensionRegistry) + throws IOException; + + @Override + public BuilderType mergeFrom(final ByteString data) throws InvalidProtocolBufferException { + try { + final CodedInputStream input = data.newCodedInput(); + mergeFrom(input); + input.checkLastTagWas(0); + return (BuilderType) this; + } catch (InvalidProtocolBufferException e) { + throw e; + } catch (IOException e) { + throw new RuntimeException(getReadingExceptionMessage("ByteString"), e); + } + } + + @Override + public BuilderType mergeFrom( + final ByteString data, final ExtensionRegistryLite extensionRegistry) + throws InvalidProtocolBufferException { + try { + final CodedInputStream input = data.newCodedInput(); + mergeFrom(input, extensionRegistry); + input.checkLastTagWas(0); + return (BuilderType) this; + } catch (InvalidProtocolBufferException e) { + throw e; + } catch (IOException e) { + throw new RuntimeException(getReadingExceptionMessage("ByteString"), e); + } + } + + @Override + public BuilderType mergeFrom(final byte[] data) throws InvalidProtocolBufferException { + return mergeFrom(data, 0, data.length); + } + + @Override + public BuilderType mergeFrom(final byte[] data, final int off, final int len) + throws InvalidProtocolBufferException { + try { + final CodedInputStream input = + CodedInputStream.newInstance(data, off, len); + mergeFrom(input); + input.checkLastTagWas(0); + return (BuilderType) this; + } catch (InvalidProtocolBufferException e) { + throw e; + } catch (IOException e) { + throw new RuntimeException(getReadingExceptionMessage("byte array"), e); + } + } + + @Override + public BuilderType mergeFrom(final byte[] data, final ExtensionRegistryLite extensionRegistry) + throws InvalidProtocolBufferException { + return mergeFrom(data, 0, data.length, extensionRegistry); + } + + @Override + public BuilderType mergeFrom( + final byte[] data, + final int off, + final int len, + final ExtensionRegistryLite extensionRegistry) + throws InvalidProtocolBufferException { + try { + final CodedInputStream input = + CodedInputStream.newInstance(data, off, len); + mergeFrom(input, extensionRegistry); + input.checkLastTagWas(0); + return (BuilderType) this; + } catch (InvalidProtocolBufferException e) { + throw e; + } catch (IOException e) { + throw new RuntimeException(getReadingExceptionMessage("byte array"), e); + } + } + + @Override + public BuilderType mergeFrom(final InputStream input) throws IOException { + final CodedInputStream codedInput = CodedInputStream.newInstance(input); + mergeFrom(codedInput); + codedInput.checkLastTagWas(0); + return (BuilderType) this; + } + + @Override + public BuilderType mergeFrom( + final InputStream input, final ExtensionRegistryLite extensionRegistry) throws IOException { + final CodedInputStream codedInput = CodedInputStream.newInstance(input); + mergeFrom(codedInput, extensionRegistry); + codedInput.checkLastTagWas(0); + return (BuilderType) this; + } + + /** + * An InputStream implementations which reads from some other InputStream + * but is limited to a particular number of bytes. Used by + * mergeDelimitedFrom(). This is intentionally package-private so that + * UnknownFieldSet can share it. + */ + static final class LimitedInputStream extends FilterInputStream { + private int limit; + + LimitedInputStream(InputStream in, int limit) { + super(in); + this.limit = limit; + } + + @Override + public int available() throws IOException { + return Math.min(super.available(), limit); + } + + @Override + public int read() throws IOException { + if (limit <= 0) { + return -1; + } + final int result = super.read(); + if (result >= 0) { + --limit; + } + return result; + } + + @Override + public int read(final byte[] b, final int off, int len) + throws IOException { + if (limit <= 0) { + return -1; + } + len = Math.min(len, limit); + final int result = super.read(b, off, len); + if (result >= 0) { + limit -= result; + } + return result; + } + + @Override + public long skip(final long n) throws IOException { + final long result = super.skip(Math.min(n, limit)); + if (result >= 0) { + limit -= result; + } + return result; + } + } + + @Override + public boolean mergeDelimitedFrom( + final InputStream input, final ExtensionRegistryLite extensionRegistry) throws IOException { + final int firstByte = input.read(); + if (firstByte == -1) { + return false; + } + final int size = CodedInputStream.readRawVarint32(firstByte, input); + final InputStream limitedInput = new LimitedInputStream(input, size); + mergeFrom(limitedInput, extensionRegistry); + return true; + } + + @Override + public boolean mergeDelimitedFrom(final InputStream input) throws IOException { + return mergeDelimitedFrom(input, + ExtensionRegistryLite.getEmptyRegistry()); + } + + @Override + @SuppressWarnings("unchecked") // isInstance takes care of this + public BuilderType mergeFrom(final MessageLite other) { + if (!getDefaultInstanceForType().getClass().isInstance(other)) { + throw new IllegalArgumentException( + "mergeFrom(MessageLite) can only merge messages of the same type."); + } + + return internalMergeFrom((MessageType) other); + } + + protected abstract BuilderType internalMergeFrom(MessageType message); + + private String getReadingExceptionMessage(String target) { + return "Reading " + getClass().getName() + " from a " + target + + " threw an IOException (should never happen)."; + } + + /** + * Construct an UninitializedMessageException reporting missing fields in + * the given message. + */ + protected static UninitializedMessageException + newUninitializedMessageException(MessageLite message) { + return new UninitializedMessageException(message); + } + + /** + * Adds the {@code values} to the {@code list}. This is a helper method + * used by generated code. Users should ignore it. + * + * @throws NullPointerException if {@code values} or any of the elements of + * {@code values} is null. When that happens, some elements of + * {@code values} may have already been added to the result {@code list}. + */ + protected static void addAll(final Iterable values, + final Collection list) { + if (values == null) { + throw new NullPointerException(); + } + if (values instanceof LazyStringList) { + // For StringOrByteStringLists, check the underlying elements to avoid + // forcing conversions of ByteStrings to Strings. + checkForNullValues(((LazyStringList) values).getUnderlyingElements()); + list.addAll((Collection) values); + } else if (values instanceof Collection) { + checkForNullValues(values); + list.addAll((Collection) values); + } else { + for (final T value : values) { + if (value == null) { + throw new NullPointerException(); + } + list.add(value); + } + } + } + + private static void checkForNullValues(final Iterable values) { + for (final Object value : values) { + if (value == null) { + throw new NullPointerException(); + } + } + } + } +} diff --git a/java/src/main/java/com/google/protobuf/AbstractParser.java b/java/src/main/java/com/google/protobuf/AbstractParser.java new file mode 100755 index 00000000..66b0ee3b --- /dev/null +++ b/java/src/main/java/com/google/protobuf/AbstractParser.java @@ -0,0 +1,258 @@ +// 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. + +package com.google.protobuf; + +import com.google.protobuf.AbstractMessageLite.Builder.LimitedInputStream; + +import java.io.IOException; +import java.io.InputStream; + +/** + * A partial implementation of the {@link Parser} interface which implements + * as many methods of that interface as possible in terms of other methods. + * + * Note: This class implements all the convenience methods in the + * {@link Parser} interface. See {@link Parser} for related javadocs. + * Subclasses need to implement + * {@link Parser#parsePartialFrom(CodedInputStream, ExtensionRegistryLite)} + * + * @author liujisi@google.com (Pherl Liu) + */ +public abstract class AbstractParser + implements Parser { + /** + * Creates an UninitializedMessageException for MessageType. + */ + private UninitializedMessageException + newUninitializedMessageException(MessageType message) { + if (message instanceof AbstractMessageLite) { + return ((AbstractMessageLite) message).newUninitializedMessageException(); + } + return new UninitializedMessageException(message); + } + + /** + * Helper method to check if message is initialized. + * + * @throws InvalidProtocolBufferException if it is not initialized. + * @return The message to check. + */ + private MessageType checkMessageInitialized(MessageType message) + throws InvalidProtocolBufferException { + if (message != null && !message.isInitialized()) { + throw newUninitializedMessageException(message) + .asInvalidProtocolBufferException() + .setUnfinishedMessage(message); + } + return message; + } + + private static final ExtensionRegistryLite EMPTY_REGISTRY + = ExtensionRegistryLite.getEmptyRegistry(); + + @Override + public MessageType parsePartialFrom(CodedInputStream input) + throws InvalidProtocolBufferException { + return parsePartialFrom(input, EMPTY_REGISTRY); + } + + @Override + public MessageType parseFrom(CodedInputStream input, ExtensionRegistryLite extensionRegistry) + throws InvalidProtocolBufferException { + return checkMessageInitialized( + parsePartialFrom(input, extensionRegistry)); + } + + @Override + public MessageType parseFrom(CodedInputStream input) throws InvalidProtocolBufferException { + return parseFrom(input, EMPTY_REGISTRY); + } + + @Override + public MessageType parsePartialFrom(ByteString data, ExtensionRegistryLite extensionRegistry) + throws InvalidProtocolBufferException { + MessageType message; + try { + CodedInputStream input = data.newCodedInput(); + message = parsePartialFrom(input, extensionRegistry); + try { + input.checkLastTagWas(0); + } catch (InvalidProtocolBufferException e) { + throw e.setUnfinishedMessage(message); + } + return message; + } catch (InvalidProtocolBufferException e) { + throw e; + } + } + + @Override + public MessageType parsePartialFrom(ByteString data) throws InvalidProtocolBufferException { + return parsePartialFrom(data, EMPTY_REGISTRY); + } + + @Override + public MessageType parseFrom(ByteString data, ExtensionRegistryLite extensionRegistry) + throws InvalidProtocolBufferException { + return checkMessageInitialized(parsePartialFrom(data, extensionRegistry)); + } + + @Override + public MessageType parseFrom(ByteString data) throws InvalidProtocolBufferException { + return parseFrom(data, EMPTY_REGISTRY); + } + + @Override + public MessageType parsePartialFrom( + byte[] data, int off, int len, ExtensionRegistryLite extensionRegistry) + throws InvalidProtocolBufferException { + try { + CodedInputStream input = CodedInputStream.newInstance(data, off, len); + MessageType message = parsePartialFrom(input, extensionRegistry); + try { + input.checkLastTagWas(0); + } catch (InvalidProtocolBufferException e) { + throw e.setUnfinishedMessage(message); + } + return message; + } catch (InvalidProtocolBufferException e) { + throw e; + } + } + + @Override + public MessageType parsePartialFrom(byte[] data, int off, int len) + throws InvalidProtocolBufferException { + return parsePartialFrom(data, off, len, EMPTY_REGISTRY); + } + + @Override + public MessageType parsePartialFrom(byte[] data, ExtensionRegistryLite extensionRegistry) + throws InvalidProtocolBufferException { + return parsePartialFrom(data, 0, data.length, extensionRegistry); + } + + @Override + public MessageType parsePartialFrom(byte[] data) throws InvalidProtocolBufferException { + return parsePartialFrom(data, 0, data.length, EMPTY_REGISTRY); + } + + @Override + public MessageType parseFrom( + byte[] data, int off, int len, ExtensionRegistryLite extensionRegistry) + throws InvalidProtocolBufferException { + return checkMessageInitialized( + parsePartialFrom(data, off, len, extensionRegistry)); + } + + @Override + public MessageType parseFrom(byte[] data, int off, int len) + throws InvalidProtocolBufferException { + return parseFrom(data, off, len, EMPTY_REGISTRY); + } + + @Override + public MessageType parseFrom(byte[] data, ExtensionRegistryLite extensionRegistry) + throws InvalidProtocolBufferException { + return parseFrom(data, 0, data.length, extensionRegistry); + } + + @Override + public MessageType parseFrom(byte[] data) throws InvalidProtocolBufferException { + return parseFrom(data, EMPTY_REGISTRY); + } + + @Override + public MessageType parsePartialFrom(InputStream input, ExtensionRegistryLite extensionRegistry) + throws InvalidProtocolBufferException { + CodedInputStream codedInput = CodedInputStream.newInstance(input); + MessageType message = parsePartialFrom(codedInput, extensionRegistry); + try { + codedInput.checkLastTagWas(0); + } catch (InvalidProtocolBufferException e) { + throw e.setUnfinishedMessage(message); + } + return message; + } + + @Override + public MessageType parsePartialFrom(InputStream input) throws InvalidProtocolBufferException { + return parsePartialFrom(input, EMPTY_REGISTRY); + } + + @Override + public MessageType parseFrom(InputStream input, ExtensionRegistryLite extensionRegistry) + throws InvalidProtocolBufferException { + return checkMessageInitialized( + parsePartialFrom(input, extensionRegistry)); + } + + @Override + public MessageType parseFrom(InputStream input) throws InvalidProtocolBufferException { + return parseFrom(input, EMPTY_REGISTRY); + } + + @Override + public MessageType parsePartialDelimitedFrom( + InputStream input, ExtensionRegistryLite extensionRegistry) + throws InvalidProtocolBufferException { + int size; + try { + int firstByte = input.read(); + if (firstByte == -1) { + return null; + } + size = CodedInputStream.readRawVarint32(firstByte, input); + } catch (IOException e) { + throw new InvalidProtocolBufferException(e.getMessage()); + } + InputStream limitedInput = new LimitedInputStream(input, size); + return parsePartialFrom(limitedInput, extensionRegistry); + } + + @Override + public MessageType parsePartialDelimitedFrom(InputStream input) + throws InvalidProtocolBufferException { + return parsePartialDelimitedFrom(input, EMPTY_REGISTRY); + } + + @Override + public MessageType parseDelimitedFrom(InputStream input, ExtensionRegistryLite extensionRegistry) + throws InvalidProtocolBufferException { + return checkMessageInitialized( + parsePartialDelimitedFrom(input, extensionRegistry)); + } + + @Override + public MessageType parseDelimitedFrom(InputStream input) throws InvalidProtocolBufferException { + return parseDelimitedFrom(input, EMPTY_REGISTRY); + } +} diff --git a/java/src/main/java/com/google/protobuf/AbstractProtobufList.java b/java/src/main/java/com/google/protobuf/AbstractProtobufList.java new file mode 100755 index 00000000..b17db6e0 --- /dev/null +++ b/java/src/main/java/com/google/protobuf/AbstractProtobufList.java @@ -0,0 +1,180 @@ +// 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. + +package com.google.protobuf; + +import com.google.protobuf.Internal.ProtobufList; + +import java.util.AbstractList; +import java.util.Collection; +import java.util.List; +import java.util.RandomAccess; + +/** + * An abstract implementation of {@link ProtobufList} which manages mutability semantics. All mutate + * methods must check if the list is mutable before proceeding. Subclasses must invoke + * {@link #ensureIsMutable()} manually when overriding those methods. + *

+ * This implementation assumes all subclasses are array based, supporting random access. + */ +abstract class AbstractProtobufList extends AbstractList implements ProtobufList { + + protected static final int DEFAULT_CAPACITY = 10; + + /** + * Whether or not this list is modifiable. + */ + private boolean isMutable; + + /** + * Constructs a mutable list by default. + */ + AbstractProtobufList() { + isMutable = true; + } + + @Override + public boolean equals(Object o) { + if (o == this) { + return true; + } + if (!(o instanceof List)) { + return false; + } + // Handle lists that do not support RandomAccess as efficiently as possible by using an iterator + // based approach in our super class. Otherwise our index based approach will avoid those + // allocations. + if (!(o instanceof RandomAccess)) { + return super.equals(o); + } + + List other = (List) o; + final int size = size(); + if (size != other.size()) { + return false; + } + for (int i = 0; i < size; i++) { + if (!get(i).equals(other.get(i))) { + return false; + } + } + return true; + } + + @Override + public int hashCode() { + final int size = size(); + int hashCode = 1; + for (int i = 0; i < size; i++) { + hashCode = (31 * hashCode) + get(i).hashCode(); + } + return hashCode; + } + + @Override + public boolean add(E e) { + ensureIsMutable(); + return super.add(e); + } + + @Override + public void add(int index, E element) { + ensureIsMutable(); + super.add(index, element); + } + + @Override + public boolean addAll(Collection c) { + ensureIsMutable(); + return super.addAll(c); + } + + @Override + public boolean addAll(int index, Collection c) { + ensureIsMutable(); + return super.addAll(index, c); + } + + @Override + public void clear() { + ensureIsMutable(); + super.clear(); + } + + @Override + public boolean isModifiable() { + return isMutable; + } + + @Override + public final void makeImmutable() { + isMutable = false; + } + + @Override + public E remove(int index) { + ensureIsMutable(); + return super.remove(index); + } + + @Override + public boolean remove(Object o) { + ensureIsMutable(); + return super.remove(o); + } + + @Override + public boolean removeAll(Collection c) { + ensureIsMutable(); + return super.removeAll(c); + } + + @Override + public boolean retainAll(Collection c) { + ensureIsMutable(); + return super.retainAll(c); + } + + @Override + public E set(int index, E element) { + ensureIsMutable(); + return super.set(index, element); + } + + /** + * Throws an {@link UnsupportedOperationException} if the list is immutable. Subclasses are + * responsible for invoking this method on mutate operations. + */ + protected void ensureIsMutable() { + if (!isMutable) { + throw new UnsupportedOperationException(); + } + } +} diff --git a/java/src/main/java/com/google/protobuf/BlockingRpcChannel.java b/java/src/main/java/com/google/protobuf/BlockingRpcChannel.java new file mode 100755 index 00000000..d535efb9 --- /dev/null +++ b/java/src/main/java/com/google/protobuf/BlockingRpcChannel.java @@ -0,0 +1,51 @@ +// 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. + +package com.google.protobuf; + +/** + *

Abstract interface for a blocking RPC channel. {@code BlockingRpcChannel} + * is the blocking equivalent to {@link RpcChannel}. + * + * @author kenton@google.com Kenton Varda + * @author cpovirk@google.com Chris Povirk + */ +public interface BlockingRpcChannel { + /** + * Call the given method of the remote service and blocks until it returns. + * {@code callBlockingMethod()} is the blocking equivalent to + * {@link RpcChannel#callMethod}. + */ + Message callBlockingMethod( + Descriptors.MethodDescriptor method, + RpcController controller, + Message request, + Message responsePrototype) throws ServiceException; +} diff --git a/java/src/main/java/com/google/protobuf/BlockingService.java b/java/src/main/java/com/google/protobuf/BlockingService.java new file mode 100755 index 00000000..d01f0b8f --- /dev/null +++ b/java/src/main/java/com/google/protobuf/BlockingService.java @@ -0,0 +1,64 @@ +// 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. + +package com.google.protobuf; + +/** + * Blocking equivalent to {@link Service}. + * + * @author kenton@google.com Kenton Varda + * @author cpovirk@google.com Chris Povirk + */ +public interface BlockingService { + /** + * Equivalent to {@link Service#getDescriptorForType}. + */ + Descriptors.ServiceDescriptor getDescriptorForType(); + + /** + * Equivalent to {@link Service#callMethod}, except that + * {@code callBlockingMethod()} returns the result of the RPC or throws a + * {@link ServiceException} if there is a failure, rather than passing the + * information to a callback. + */ + Message callBlockingMethod(Descriptors.MethodDescriptor method, + RpcController controller, + Message request) throws ServiceException; + + /** + * Equivalent to {@link Service#getRequestPrototype}. + */ + Message getRequestPrototype(Descriptors.MethodDescriptor method); + + /** + * Equivalent to {@link Service#getResponsePrototype}. + */ + Message getResponsePrototype(Descriptors.MethodDescriptor method); +} diff --git a/java/util/src/main/java/com/google/protobuf/util/Durations.java b/java/util/src/main/java/com/google/protobuf/util/Durations.java index 5fe6ebca..9333168d 100644 --- a/java/util/src/main/java/com/google/protobuf/util/Durations.java +++ b/java/util/src/main/java/com/google/protobuf/util/Durations.java @@ -30,50 +30,86 @@ package com.google.protobuf.util; +import static com.google.common.base.Preconditions.checkArgument; +import static com.google.common.math.IntMath.checkedAdd; +import static com.google.common.math.IntMath.checkedSubtract; +import static com.google.common.math.LongMath.checkedAdd; +import static com.google.common.math.LongMath.checkedMultiply; +import static com.google.common.math.LongMath.checkedSubtract; import static com.google.protobuf.util.Timestamps.MICROS_PER_SECOND; import static com.google.protobuf.util.Timestamps.MILLIS_PER_SECOND; import static com.google.protobuf.util.Timestamps.NANOS_PER_MICROSECOND; import static com.google.protobuf.util.Timestamps.NANOS_PER_MILLISECOND; import static com.google.protobuf.util.Timestamps.NANOS_PER_SECOND; +import com.google.common.collect.ComparisonChain; import com.google.protobuf.Duration; - import java.text.ParseException; +import java.util.Comparator; /** - * Utilities to help create/manipulate {@code protobuf/duration.proto}. + * Utilities to help create/manipulate {@code protobuf/duration.proto}. All operations throw an + * {@link IllegalArgumentException} if the input(s) are not {@linkplain #isValid(Duration) valid}. */ public final class Durations { static final long DURATION_SECONDS_MIN = -315576000000L; static final long DURATION_SECONDS_MAX = 315576000000L; - // TODO(kak): Do we want to expose Duration constants for MAX/MIN? + /** A constant holding the minimum valid {@link Duration}, approximately {@code -10,000} years. */ + public static final Duration MIN_VALUE = + Duration.newBuilder().setSeconds(DURATION_SECONDS_MIN).setNanos(-999999999).build(); + + /** A constant holding the maximum valid {@link Duration}, approximately {@code +10,000} years. */ + public static final Duration MAX_VALUE = + Duration.newBuilder().setSeconds(DURATION_SECONDS_MAX).setNanos(999999999).build(); private Durations() {} + private static final Comparator COMPARATOR = + new Comparator() { + @Override + public int compare(Duration d1, Duration d2) { + checkValid(d1); + checkValid(d2); + + return ComparisonChain.start() + .compare(d1.getSeconds(), d2.getSeconds()) + .compare(d1.getNanos(), d2.getNanos()) + .result(); + } + }; + + /** + * Returns a {@link Comparator} for {@link Duration}s which sorts in increasing chronological + * order. Nulls and invalid {@link Duration}s are not allowed (see {@link #isValid}). + */ + public static Comparator comparator() { + return COMPARATOR; + } + /** * Returns true if the given {@link Duration} is valid. The {@code seconds} value must be in the * range [-315,576,000,000, +315,576,000,000]. The {@code nanos} value must be in the range * [-999,999,999, +999,999,999]. * - *

Note: Durations less than one second are represented with a 0 {@code seconds} field and a - * positive or negative {@code nanos} field. For durations of one second or more, a non-zero value - * for the {@code nanos} field must be of the same sign as the {@code seconds} field. + *

Note: Durations less than one second are represented with a 0 {@code seconds} field + * and a positive or negative {@code nanos} field. For durations of one second or more, a non-zero + * value for the {@code nanos} field must be of the same sign as the {@code seconds} field. */ public static boolean isValid(Duration duration) { return isValid(duration.getSeconds(), duration.getNanos()); } /** - * Returns true if the given number of seconds and nanos is a valid {@link Duration}. The - * {@code seconds} value must be in the range [-315,576,000,000, +315,576,000,000]. The - * {@code nanos} value must be in the range [-999,999,999, +999,999,999]. + * Returns true if the given number of seconds and nanos is a valid {@link Duration}. The {@code + * seconds} value must be in the range [-315,576,000,000, +315,576,000,000]. The {@code nanos} + * value must be in the range [-999,999,999, +999,999,999]. * - *

Note: Durations less than one second are represented with a 0 {@code seconds} field and a - * positive or negative {@code nanos} field. For durations of one second or more, a non-zero value - * for the {@code nanos} field must be of the same sign as the {@code seconds} field. + *

Note: Durations less than one second are represented with a 0 {@code seconds} field + * and a positive or negative {@code nanos} field. For durations of one second or more, a non-zero + * value for the {@code nanos} field must be of the same sign as the {@code seconds} field. */ - public static boolean isValid(long seconds, long nanos) { + public static boolean isValid(long seconds, int nanos) { if (seconds < DURATION_SECONDS_MIN || seconds > DURATION_SECONDS_MAX) { return false; } @@ -88,35 +124,35 @@ public final class Durations { return true; } - /** - * Throws an {@link IllegalArgumentException} if the given seconds/nanos are not - * a valid {@link Duration}. - */ - private static void checkValid(long seconds, int nanos) { - if (!isValid(seconds, nanos)) { - throw new IllegalArgumentException(String.format( - "Duration is not valid. See proto definition for valid values. " - + "Seconds (%s) must be in range [-315,576,000,000, +315,576,000,000]." - + "Nanos (%s) must be in range [-999,999,999, +999,999,999]. " - + "Nanos must have the same sign as seconds", seconds, nanos)); - } + /** Throws an {@link IllegalArgumentException} if the given {@link Duration} is not valid. */ + public static Duration checkValid(Duration duration) { + long seconds = duration.getSeconds(); + int nanos = duration.getNanos(); + checkArgument( + isValid(seconds, nanos), + "Duration is not valid. See proto definition for valid values. " + + "Seconds (%s) must be in range [-315,576,000,000, +315,576,000,000]. " + + "Nanos (%s) must be in range [-999,999,999, +999,999,999]. " + + "Nanos must have the same sign as seconds", + seconds, + nanos); + return duration; } /** - * Convert Duration to string format. The string format will contains 3, 6, - * or 9 fractional digits depending on the precision required to represent - * the exact Duration value. For example: "1s", "1.010s", "1.000000100s", - * "-3.100s" The range that can be represented by Duration is from + * Convert Duration to string format. The string format will contains 3, 6, or 9 fractional digits + * depending on the precision required to represent the exact Duration value. For example: "1s", + * "1.010s", "1.000000100s", "-3.100s" The range that can be represented by Duration is from * -315,576,000,000 to +315,576,000,000 inclusive (in seconds). * * @return The string representation of the given duration. - * @throws IllegalArgumentException if the given duration is not in the valid - * range. + * @throws IllegalArgumentException if the given duration is not in the valid range. */ public static String toString(Duration duration) { + checkValid(duration); + long seconds = duration.getSeconds(); int nanos = duration.getNanos(); - checkValid(seconds, nanos); StringBuilder result = new StringBuilder(); if (seconds < 0 || nanos < 0) { @@ -172,9 +208,20 @@ public final class Durations { } } + /** Create a Duration from the number of seconds. */ + public static Duration fromSeconds(long seconds) { + return normalizedDuration(seconds, 0); + } + /** - * Create a Duration from the number of milliseconds. + * Convert a Duration to the number of seconds. The result will be rounded towards 0 to the + * nearest second. E.g., if the duration represents -1 nanosecond, it will be rounded to 0. */ + public static long toSeconds(Duration duration) { + return checkValid(duration).getSeconds(); + } + + /** Create a Duration from the number of milliseconds. */ public static Duration fromMillis(long milliseconds) { return normalizedDuration( milliseconds / MILLIS_PER_SECOND, @@ -182,17 +229,17 @@ public final class Durations { } /** - * Convert a Duration to the number of milliseconds.The result will be - * rounded towards 0 to the nearest millisecond. E.g., if the duration - * represents -1 nanosecond, it will be rounded to 0. + * Convert a Duration to the number of milliseconds. The result will be rounded towards 0 to the + * nearest millisecond. E.g., if the duration represents -1 nanosecond, it will be rounded to 0. */ public static long toMillis(Duration duration) { - return duration.getSeconds() * MILLIS_PER_SECOND + duration.getNanos() / NANOS_PER_MILLISECOND; + checkValid(duration); + return checkedAdd( + checkedMultiply(duration.getSeconds(), MILLIS_PER_SECOND), + duration.getNanos() / NANOS_PER_MILLISECOND); } - /** - * Create a Duration from the number of microseconds. - */ + /** Create a Duration from the number of microseconds. */ public static Duration fromMicros(long microseconds) { return normalizedDuration( microseconds / MICROS_PER_SECOND, @@ -200,57 +247,60 @@ public final class Durations { } /** - * Convert a Duration to the number of microseconds.The result will be - * rounded towards 0 to the nearest microseconds. E.g., if the duration - * represents -1 nanosecond, it will be rounded to 0. + * Convert a Duration to the number of microseconds. The result will be rounded towards 0 to the + * nearest microseconds. E.g., if the duration represents -1 nanosecond, it will be rounded to 0. */ public static long toMicros(Duration duration) { - return duration.getSeconds() * MICROS_PER_SECOND + duration.getNanos() / NANOS_PER_MICROSECOND; + checkValid(duration); + return checkedAdd( + checkedMultiply(duration.getSeconds(), MICROS_PER_SECOND), + duration.getNanos() / NANOS_PER_MICROSECOND); } - /** - * Create a Duration from the number of nanoseconds. - */ + /** Create a Duration from the number of nanoseconds. */ public static Duration fromNanos(long nanoseconds) { return normalizedDuration( nanoseconds / NANOS_PER_SECOND, (int) (nanoseconds % NANOS_PER_SECOND)); } - /** - * Convert a Duration to the number of nanoseconds. - */ + /** Convert a Duration to the number of nanoseconds. */ public static long toNanos(Duration duration) { - return duration.getSeconds() * NANOS_PER_SECOND + duration.getNanos(); + checkValid(duration); + return checkedAdd( + checkedMultiply(duration.getSeconds(), NANOS_PER_SECOND), duration.getNanos()); } - /** - * Add two durations. - */ + /** Add two durations. */ public static Duration add(Duration d1, Duration d2) { - return normalizedDuration(d1.getSeconds() + d2.getSeconds(), d1.getNanos() + d2.getNanos()); + checkValid(d1); + checkValid(d2); + return normalizedDuration( + checkedAdd(d1.getSeconds(), d2.getSeconds()), checkedAdd(d1.getNanos(), d2.getNanos())); } - /** - * Subtract a duration from another. - */ + /** Subtract a duration from another. */ public static Duration subtract(Duration d1, Duration d2) { - return normalizedDuration(d1.getSeconds() - d2.getSeconds(), d1.getNanos() - d2.getNanos()); + checkValid(d1); + checkValid(d2); + return normalizedDuration( + checkedSubtract(d1.getSeconds(), d2.getSeconds()), + checkedSubtract(d1.getNanos(), d2.getNanos())); } static Duration normalizedDuration(long seconds, int nanos) { if (nanos <= -NANOS_PER_SECOND || nanos >= NANOS_PER_SECOND) { - seconds += nanos / NANOS_PER_SECOND; + seconds = checkedAdd(seconds, nanos / NANOS_PER_SECOND); nanos %= NANOS_PER_SECOND; } if (seconds > 0 && nanos < 0) { - nanos += NANOS_PER_SECOND; - seconds -= 1; + nanos += NANOS_PER_SECOND; // no overflow since nanos is negative (and we're adding) + seconds--; // no overflow since seconds is positive (and we're decrementing) } if (seconds < 0 && nanos > 0) { - nanos -= NANOS_PER_SECOND; - seconds += 1; + nanos -= NANOS_PER_SECOND; // no overflow since nanos is positive (and we're subtracting) + seconds++; // no overflow since seconds is negative (and we're incrementing) } - checkValid(seconds, nanos); - return Duration.newBuilder().setSeconds(seconds).setNanos(nanos).build(); + Duration duration = Duration.newBuilder().setSeconds(seconds).setNanos(nanos).build(); + return checkValid(duration); } } diff --git a/java/util/src/main/java/com/google/protobuf/util/JsonFormat.java b/java/util/src/main/java/com/google/protobuf/util/JsonFormat.java index d4db9c80..6361b4ac 100644 --- a/java/util/src/main/java/com/google/protobuf/util/JsonFormat.java +++ b/java/util/src/main/java/com/google/protobuf/util/JsonFormat.java @@ -640,6 +640,10 @@ public class JsonFormat { /** Prints google.protobuf.Any */ private void printAny(MessageOrBuilder message) throws IOException { + if (Any.getDefaultInstance().equals(message)) { + generator.print("{}"); + return; + } Descriptor descriptor = message.getDescriptorForType(); FieldDescriptor typeUrlField = descriptor.findFieldByName("type_url"); FieldDescriptor valueField = descriptor.findFieldByName("value"); @@ -1235,6 +1239,9 @@ public class JsonFormat { throw new InvalidProtocolBufferException("Expect message object but got: " + json); } JsonObject object = (JsonObject) json; + if (object.entrySet().isEmpty()) { + return; // builder never modified, so it will end up building the default instance of Any + } JsonElement typeUrlElement = object.get("@type"); if (typeUrlElement == null) { throw new InvalidProtocolBufferException("Missing type url when parsing: " + json); @@ -1327,6 +1334,9 @@ public class JsonFormat { Message.Builder listBuilder = builder.newBuilderForField(field); merge(json, listBuilder); builder.setField(field, listBuilder.build()); + } else if (json instanceof JsonNull) { + builder.setField( + type.findFieldByName("null_value"), NullValue.NULL_VALUE.getValueDescriptor()); } else { throw new IllegalStateException("Unexpected json data: " + json); } @@ -1620,11 +1630,6 @@ public class JsonFormat { } private ByteString parseBytes(JsonElement json) throws InvalidProtocolBufferException { - String encoded = json.getAsString(); - if (encoded.length() % 4 != 0) { - throw new InvalidProtocolBufferException( - "Bytes field is not encoded in standard BASE64 with paddings: " + encoded); - } return ByteString.copyFrom(BaseEncoding.base64().decode(json.getAsString())); } diff --git a/java/util/src/main/java/com/google/protobuf/util/Timestamps.java b/java/util/src/main/java/com/google/protobuf/util/Timestamps.java index f1f202da..52b1ab98 100644 --- a/java/util/src/main/java/com/google/protobuf/util/Timestamps.java +++ b/java/util/src/main/java/com/google/protobuf/util/Timestamps.java @@ -30,19 +30,29 @@ package com.google.protobuf.util; +import static com.google.common.base.Preconditions.checkArgument; +import static com.google.common.math.IntMath.checkedAdd; +import static com.google.common.math.IntMath.checkedSubtract; +import static com.google.common.math.LongMath.checkedAdd; +import static com.google.common.math.LongMath.checkedMultiply; +import static com.google.common.math.LongMath.checkedSubtract; + +import com.google.common.collect.ComparisonChain; import com.google.protobuf.Duration; import com.google.protobuf.Timestamp; - import java.text.ParseException; import java.text.SimpleDateFormat; +import java.util.Comparator; import java.util.Date; import java.util.GregorianCalendar; import java.util.TimeZone; /** - * Utilities to help create/manipulate {@code protobuf/timestamp.proto}. + * Utilities to help create/manipulate {@code protobuf/timestamp.proto}. All operations throw an + * {@link IllegalArgumentException} if the input(s) are not {@linkplain #isValid(Timestamp) valid}. */ public final class Timestamps { + // Timestamp for "0001-01-01T00:00:00Z" static final long TIMESTAMP_SECONDS_MIN = -62135596800L; @@ -55,10 +65,19 @@ public final class Timestamps { static final long MILLIS_PER_SECOND = 1000; static final long MICROS_PER_SECOND = 1000000; - // TODO(kak): Do we want to expose Timestamp constants for MAX/MIN? + /** A constant holding the minimum valid {@link Timestamp}, {@code 0001-01-01T00:00:00Z}. */ + public static final Timestamp MIN_VALUE = + Timestamp.newBuilder().setSeconds(TIMESTAMP_SECONDS_MIN).setNanos(0).build(); + + /** + * A constant holding the maximum valid {@link Timestamp}, {@code 9999-12-31T23:59:59.999999999Z}. + */ + public static final Timestamp MAX_VALUE = + Timestamp.newBuilder().setSeconds(TIMESTAMP_SECONDS_MAX).setNanos(999999999).build(); private static final ThreadLocal timestampFormat = new ThreadLocal() { + @Override protected SimpleDateFormat initialValue() { return createTimestampFormat(); } @@ -76,28 +95,50 @@ public final class Timestamps { private Timestamps() {} + private static final Comparator COMPARATOR = + new Comparator() { + @Override + public int compare(Timestamp t1, Timestamp t2) { + checkValid(t1); + checkValid(t2); + + return ComparisonChain.start() + .compare(t1.getSeconds(), t2.getSeconds()) + .compare(t1.getNanos(), t2.getNanos()) + .result(); + } + }; + + /** + * Returns a {@link Comparator} for {@link Timestamp}s which sorts in increasing chronological + * order. Nulls and invalid {@link Timestamp}s are not allowed (see {@link #isValid}). + */ + public static Comparator comparator() { + return COMPARATOR; + } + /** * Returns true if the given {@link Timestamp} is valid. The {@code seconds} value must be in the * range [-62,135,596,800, +253,402,300,799] (i.e., between 0001-01-01T00:00:00Z and * 9999-12-31T23:59:59Z). The {@code nanos} value must be in the range [0, +999,999,999]. * - *

Note: Negative second values with fractions must still have non-negative nanos value that - * counts forward in time. + *

Note: Negative second values with fractional seconds must still have non-negative + * nanos values that count forward in time. */ public static boolean isValid(Timestamp timestamp) { return isValid(timestamp.getSeconds(), timestamp.getNanos()); } /** - * Returns true if the given number of seconds and nanos is a valid {@link Timestamp}. The - * {@code seconds} value must be in the range [-62,135,596,800, +253,402,300,799] (i.e., between + * Returns true if the given number of seconds and nanos is a valid {@link Timestamp}. The {@code + * seconds} value must be in the range [-62,135,596,800, +253,402,300,799] (i.e., between * 0001-01-01T00:00:00Z and 9999-12-31T23:59:59Z). The {@code nanos} value must be in the range * [0, +999,999,999]. * - *

Note: Negative second values with fractions must still have non-negative nanos value that - * counts forward in time. + *

Note: Negative second values with fractional seconds must still have non-negative + * nanos values that count forward in time. */ - public static boolean isValid(long seconds, long nanos) { + public static boolean isValid(long seconds, int nanos) { if (seconds < TIMESTAMP_SECONDS_MIN || seconds > TIMESTAMP_SECONDS_MAX) { return false; } @@ -107,37 +148,37 @@ public final class Timestamps { return true; } - /** - * Throws an {@link IllegalArgumentException} if the given seconds/nanos are not - * a valid {@link Timestamp}. - */ - private static void checkValid(long seconds, int nanos) { - if (!isValid(seconds, nanos)) { - throw new IllegalArgumentException(String.format( - "Timestamp is not valid. See proto definition for valid values. " - + "Seconds (%s) must be in range [-62,135,596,800, +253,402,300,799]." - + "Nanos (%s) must be in range [0, +999,999,999].", - seconds, nanos)); - } + /** Throws an {@link IllegalArgumentException} if the given {@link Timestamp} is not valid. */ + public static Timestamp checkValid(Timestamp timestamp) { + long seconds = timestamp.getSeconds(); + int nanos = timestamp.getNanos(); + checkArgument( + isValid(seconds, nanos), + "Timestamp is not valid. See proto definition for valid values. " + + "Seconds (%s) must be in range [-62,135,596,800, +253,402,300,799]. " + + "Nanos (%s) must be in range [0, +999,999,999].", + seconds, + nanos); + return timestamp; } /** - * Convert Timestamp to RFC 3339 date string format. The output will always - * be Z-normalized and uses 3, 6 or 9 fractional digits as required to - * represent the exact value. Note that Timestamp can only represent time - * from 0001-01-01T00:00:00Z to 9999-12-31T23:59:59.999999999Z. See + * Convert Timestamp to RFC 3339 date string format. The output will always be Z-normalized and + * uses 3, 6 or 9 fractional digits as required to represent the exact value. Note that Timestamp + * can only represent time from 0001-01-01T00:00:00Z to 9999-12-31T23:59:59.999999999Z. See * https://www.ietf.org/rfc/rfc3339.txt * *

Example of generated format: "1972-01-01T10:00:20.021Z" * * @return The string representation of the given timestamp. - * @throws IllegalArgumentException if the given timestamp is not in the - * valid range. + * @throws IllegalArgumentException if the given timestamp is not in the valid range. */ public static String toString(Timestamp timestamp) { + checkValid(timestamp); + long seconds = timestamp.getSeconds(); int nanos = timestamp.getNanos(); - checkValid(seconds, nanos); + StringBuilder result = new StringBuilder(); // Format the seconds part. Date date = new Date(seconds * MILLIS_PER_SECOND); @@ -152,10 +193,9 @@ public final class Timestamps { } /** - * Parse from RFC 3339 date string to Timestamp. This method accepts all - * outputs of {@link #toString(Timestamp)} and it also accepts any fractional - * digits (or none) and any offset as long as they fit into nano-seconds - * precision. + * Parse from RFC 3339 date string to Timestamp. This method accepts all outputs of {@link + * #toString(Timestamp)} and it also accepts any fractional digits (or none) and any offset as + * long as they fit into nano-seconds precision. * *

Example of accepted format: "1972-01-01T10:00:20.021-05:00" * @@ -210,13 +250,26 @@ public final class Timestamps { try { return normalizedTimestamp(seconds, nanos); } catch (IllegalArgumentException e) { - throw new ParseException("Failed to parse timestmap: timestamp is out of range.", 0); + throw new ParseException("Failed to parse timestamp: timestamp is out of range.", 0); } } + /** Create a Timestamp from the number of seconds elapsed from the epoch. */ + public static Timestamp fromSeconds(long seconds) { + return normalizedTimestamp(seconds, 0); + } + /** - * Create a Timestamp from the number of milliseconds elapsed from the epoch. + * Convert a Timestamp to the number of seconds elapsed from the epoch. + * + *

The result will be rounded down to the nearest second. E.g., if the timestamp represents + * "1969-12-31T23:59:59.999999999Z", it will be rounded to -1 second. */ + public static long toSeconds(Timestamp timestamp) { + return checkValid(timestamp).getSeconds(); + } + + /** Create a Timestamp from the number of milliseconds elapsed from the epoch. */ public static Timestamp fromMillis(long milliseconds) { return normalizedTimestamp( milliseconds / MILLIS_PER_SECOND, @@ -226,18 +279,17 @@ public final class Timestamps { /** * Convert a Timestamp to the number of milliseconds elapsed from the epoch. * - *

The result will be rounded down to the nearest millisecond. E.g., if the - * timestamp represents "1969-12-31T23:59:59.999999999Z", it will be rounded - * to -1 millisecond. + *

The result will be rounded down to the nearest millisecond. E.g., if the timestamp + * represents "1969-12-31T23:59:59.999999999Z", it will be rounded to -1 millisecond. */ public static long toMillis(Timestamp timestamp) { - return timestamp.getSeconds() * MILLIS_PER_SECOND - + timestamp.getNanos() / NANOS_PER_MILLISECOND; + checkValid(timestamp); + return checkedAdd( + checkedMultiply(timestamp.getSeconds(), MILLIS_PER_SECOND), + timestamp.getNanos() / NANOS_PER_MILLISECOND); } - /** - * Create a Timestamp from the number of microseconds elapsed from the epoch. - */ + /** Create a Timestamp from the number of microseconds elapsed from the epoch. */ public static Timestamp fromMicros(long microseconds) { return normalizedTimestamp( microseconds / MICROS_PER_SECOND, @@ -247,65 +299,67 @@ public final class Timestamps { /** * Convert a Timestamp to the number of microseconds elapsed from the epoch. * - *

The result will be rounded down to the nearest microsecond. E.g., if the - * timestamp represents "1969-12-31T23:59:59.999999999Z", it will be rounded - * to -1 millisecond. + *

The result will be rounded down to the nearest microsecond. E.g., if the timestamp + * represents "1969-12-31T23:59:59.999999999Z", it will be rounded to -1 millisecond. */ public static long toMicros(Timestamp timestamp) { - return timestamp.getSeconds() * MICROS_PER_SECOND - + timestamp.getNanos() / NANOS_PER_MICROSECOND; + checkValid(timestamp); + return checkedAdd( + checkedMultiply(timestamp.getSeconds(), MICROS_PER_SECOND), + timestamp.getNanos() / NANOS_PER_MICROSECOND); } - /** - * Create a Timestamp from the number of nanoseconds elapsed from the epoch. - */ + /** Create a Timestamp from the number of nanoseconds elapsed from the epoch. */ public static Timestamp fromNanos(long nanoseconds) { return normalizedTimestamp( nanoseconds / NANOS_PER_SECOND, (int) (nanoseconds % NANOS_PER_SECOND)); } - /** - * Convert a Timestamp to the number of nanoseconds elapsed from the epoch. - */ + /** Convert a Timestamp to the number of nanoseconds elapsed from the epoch. */ public static long toNanos(Timestamp timestamp) { - return timestamp.getSeconds() * NANOS_PER_SECOND + timestamp.getNanos(); + checkValid(timestamp); + return checkedAdd( + checkedMultiply(timestamp.getSeconds(), NANOS_PER_SECOND), timestamp.getNanos()); } - /** - * Calculate the difference between two timestamps. - */ + /** Calculate the difference between two timestamps. */ public static Duration between(Timestamp from, Timestamp to) { + checkValid(from); + checkValid(to); return Durations.normalizedDuration( - to.getSeconds() - from.getSeconds(), to.getNanos() - from.getNanos()); + checkedSubtract(to.getSeconds(), from.getSeconds()), + checkedSubtract(to.getNanos(), from.getNanos())); } - /** - * Add a duration to a timestamp. - */ + /** Add a duration to a timestamp. */ public static Timestamp add(Timestamp start, Duration length) { + checkValid(start); + Durations.checkValid(length); return normalizedTimestamp( - start.getSeconds() + length.getSeconds(), start.getNanos() + length.getNanos()); + checkedAdd(start.getSeconds(), length.getSeconds()), + checkedAdd(start.getNanos(), length.getNanos())); } - /** - * Subtract a duration from a timestamp. - */ + /** Subtract a duration from a timestamp. */ public static Timestamp subtract(Timestamp start, Duration length) { + checkValid(start); + Durations.checkValid(length); return normalizedTimestamp( - start.getSeconds() - length.getSeconds(), start.getNanos() - length.getNanos()); + checkedSubtract(start.getSeconds(), length.getSeconds()), + checkedSubtract(start.getNanos(), length.getNanos())); } - private static Timestamp normalizedTimestamp(long seconds, int nanos) { + static Timestamp normalizedTimestamp(long seconds, int nanos) { if (nanos <= -NANOS_PER_SECOND || nanos >= NANOS_PER_SECOND) { - seconds += nanos / NANOS_PER_SECOND; + seconds = checkedAdd(seconds, nanos / NANOS_PER_SECOND); nanos %= NANOS_PER_SECOND; } if (nanos < 0) { - nanos += NANOS_PER_SECOND; - seconds -= 1; + nanos += NANOS_PER_SECOND; // no overflow since nanos is negative (and we're adding) + seconds = checkedSubtract(seconds, 1); } - checkValid(seconds, nanos); - return Timestamp.newBuilder().setSeconds(seconds).setNanos(nanos).build(); + Timestamp timestamp = Timestamp.newBuilder().setSeconds(seconds).setNanos(nanos).build(); + return checkValid(timestamp); } private static long parseTimezoneOffset(String value) throws ParseException { @@ -324,7 +378,7 @@ public final class Timestamps { result = result * 10; if (i < value.length()) { if (value.charAt(i) < '0' || value.charAt(i) > '9') { - throw new ParseException("Invalid nanosecnds.", 0); + throw new ParseException("Invalid nanoseconds.", 0); } result += value.charAt(i) - '0'; } @@ -332,11 +386,8 @@ public final class Timestamps { return result; } - /** - * Format the nano part of a timestamp or a duration. - */ + /** Format the nano part of a timestamp or a duration. */ static String formatNanos(int nanos) { - assert nanos >= 1 && nanos <= 999999999; // Determine whether to use 3, 6, or 9 digits for the nano part. if (nanos % NANOS_PER_MILLISECOND == 0) { return String.format("%1$03d", nanos / NANOS_PER_MILLISECOND); diff --git a/java/util/src/test/java/com/google/protobuf/util/JsonFormatTest.java b/java/util/src/test/java/com/google/protobuf/util/JsonFormatTest.java index c11114c0..32739d44 100644 --- a/java/util/src/test/java/com/google/protobuf/util/JsonFormatTest.java +++ b/java/util/src/test/java/com/google/protobuf/util/JsonFormatTest.java @@ -60,12 +60,10 @@ import com.google.protobuf.util.JsonTestProto.TestOneof; import com.google.protobuf.util.JsonTestProto.TestStruct; import com.google.protobuf.util.JsonTestProto.TestTimestamp; import com.google.protobuf.util.JsonTestProto.TestWrappers; - -import junit.framework.TestCase; - import java.io.IOException; import java.math.BigDecimal; import java.math.BigInteger; +import junit.framework.TestCase; public class JsonFormatTest extends TestCase { private void setAllFields(TestAllTypes.Builder builder) { @@ -819,6 +817,15 @@ public class JsonFormatTest extends TestCase { printer.print(message)); assertRoundTripEquals(message, registry); + TestAny messageWithDefaultAnyValue = + TestAny.newBuilder().setAnyValue(Any.getDefaultInstance()).build(); + assertEquals( + "{\n" + + " \"anyValue\": {}\n" + + "}", + printer.print(messageWithDefaultAnyValue)); + assertRoundTripEquals(messageWithDefaultAnyValue, registry); + // Well-known types have a special formatting when embedded in Any. // // 1. Any in Any. @@ -952,6 +959,8 @@ public class JsonFormatTest extends TestCase { + "}", printer.print(anyMessage)); assertRoundTripEquals(anyMessage, registry); + + // 7. Value (number type) in Any Value.Builder valueBuilder = Value.newBuilder(); valueBuilder.setNumberValue(1); anyMessage = Any.pack(valueBuilder.build()); @@ -962,6 +971,95 @@ public class JsonFormatTest extends TestCase { + "}", printer.print(anyMessage)); assertRoundTripEquals(anyMessage, registry); + + // 8. Value (null type) in Any + anyMessage = Any.pack(Value.newBuilder().setNullValue(NullValue.NULL_VALUE).build()); + assertEquals( + "{\n" + + " \"@type\": \"type.googleapis.com/google.protobuf.Value\",\n" + + " \"value\": null\n" + + "}", + printer.print(anyMessage)); + assertRoundTripEquals(anyMessage, registry); + } + + public void testAnyInMaps() throws Exception { + JsonFormat.TypeRegistry registry = + JsonFormat.TypeRegistry.newBuilder().add(TestAllTypes.getDescriptor()).build(); + JsonFormat.Printer printer = JsonFormat.printer().usingTypeRegistry(registry); + + TestAny.Builder testAny = TestAny.newBuilder(); + testAny.putAnyMap("int32_wrapper", Any.pack(Int32Value.newBuilder().setValue(123).build())); + testAny.putAnyMap("int64_wrapper", Any.pack(Int64Value.newBuilder().setValue(456).build())); + testAny.putAnyMap("timestamp", Any.pack(Timestamps.parse("1969-12-31T23:59:59Z"))); + testAny.putAnyMap("duration", Any.pack(Durations.parse("12345.1s"))); + testAny.putAnyMap("field_mask", Any.pack(FieldMaskUtil.fromString("foo.bar,baz"))); + Value numberValue = Value.newBuilder().setNumberValue(1.125).build(); + Struct.Builder struct = Struct.newBuilder(); + struct.putFields("number", numberValue); + testAny.putAnyMap("struct", Any.pack(struct.build())); + Value nullValue = Value.newBuilder().setNullValue(NullValue.NULL_VALUE).build(); + testAny.putAnyMap( + "list_value", + Any.pack(ListValue.newBuilder().addValues(numberValue).addValues(nullValue).build())); + testAny.putAnyMap("number_value", Any.pack(numberValue)); + testAny.putAnyMap("any_value_number", Any.pack(Any.pack(numberValue))); + testAny.putAnyMap("any_value_default", Any.pack(Any.getDefaultInstance())); + testAny.putAnyMap("default", Any.getDefaultInstance()); + + assertEquals( + "{\n" + + " \"anyMap\": {\n" + + " \"int32_wrapper\": {\n" + + " \"@type\": \"type.googleapis.com/google.protobuf.Int32Value\",\n" + + " \"value\": 123\n" + + " },\n" + + " \"int64_wrapper\": {\n" + + " \"@type\": \"type.googleapis.com/google.protobuf.Int64Value\",\n" + + " \"value\": \"456\"\n" + + " },\n" + + " \"timestamp\": {\n" + + " \"@type\": \"type.googleapis.com/google.protobuf.Timestamp\",\n" + + " \"value\": \"1969-12-31T23:59:59Z\"\n" + + " },\n" + + " \"duration\": {\n" + + " \"@type\": \"type.googleapis.com/google.protobuf.Duration\",\n" + + " \"value\": \"12345.100s\"\n" + + " },\n" + + " \"field_mask\": {\n" + + " \"@type\": \"type.googleapis.com/google.protobuf.FieldMask\",\n" + + " \"value\": \"foo.bar,baz\"\n" + + " },\n" + + " \"struct\": {\n" + + " \"@type\": \"type.googleapis.com/google.protobuf.Struct\",\n" + + " \"value\": {\n" + + " \"number\": 1.125\n" + + " }\n" + + " },\n" + + " \"list_value\": {\n" + + " \"@type\": \"type.googleapis.com/google.protobuf.ListValue\",\n" + + " \"value\": [1.125, null]\n" + + " },\n" + + " \"number_value\": {\n" + + " \"@type\": \"type.googleapis.com/google.protobuf.Value\",\n" + + " \"value\": 1.125\n" + + " },\n" + + " \"any_value_number\": {\n" + + " \"@type\": \"type.googleapis.com/google.protobuf.Any\",\n" + + " \"value\": {\n" + + " \"@type\": \"type.googleapis.com/google.protobuf.Value\",\n" + + " \"value\": 1.125\n" + + " }\n" + + " },\n" + + " \"any_value_default\": {\n" + + " \"@type\": \"type.googleapis.com/google.protobuf.Any\",\n" + + " \"value\": {}\n" + + " },\n" + + " \"default\": {}\n" + + " }\n" + + "}", + printer.print(testAny.build())); + assertRoundTripEquals(testAny.build(), registry); } public void testParserMissingTypeUrl() throws Exception { @@ -1016,8 +1114,10 @@ public class JsonFormatTest extends TestCase { public void testParserRejectInvalidBase64() throws Exception { assertRejects("optionalBytes", "!@#$"); - // We use standard BASE64 with paddings. - assertRejects("optionalBytes", "AQI"); + } + + public void testParserAcceptBase64Variants() throws Exception { + assertAccepts("optionalBytes", "AQI"); } public void testParserRejectInvalidEnumValue() throws Exception { diff --git a/java/util/src/test/java/com/google/protobuf/util/TimeUtilTest.java b/java/util/src/test/java/com/google/protobuf/util/TimeUtilTest.java index a41528ec..5af83d88 100644 --- a/java/util/src/test/java/com/google/protobuf/util/TimeUtilTest.java +++ b/java/util/src/test/java/com/google/protobuf/util/TimeUtilTest.java @@ -32,14 +32,11 @@ package com.google.protobuf.util; import com.google.protobuf.Duration; import com.google.protobuf.Timestamp; - -import junit.framework.TestCase; - -import org.junit.Assert; - import java.text.ParseException; import java.util.ArrayList; import java.util.List; +import junit.framework.TestCase; +import org.junit.Assert; /** Unit tests for {@link TimeUtil}. */ public class TimeUtilTest extends TestCase { diff --git a/java/util/src/test/proto/com/google/protobuf/util/json_test.proto b/java/util/src/test/proto/com/google/protobuf/util/json_test.proto index 4bf223f2..bd22f65a 100644 --- a/java/util/src/test/proto/com/google/protobuf/util/json_test.proto +++ b/java/util/src/test/proto/com/google/protobuf/util/json_test.proto @@ -195,6 +195,7 @@ message TestStruct { message TestAny { google.protobuf.Any any_value = 1; + map any_map = 2; } message TestCustomJsonName { diff --git a/js/binary/proto_test.js b/js/binary/proto_test.js index 14d0f42e..26e1d30f 100644 --- a/js/binary/proto_test.js +++ b/js/binary/proto_test.js @@ -496,7 +496,7 @@ describe('protoBinaryTest', function() { msg.setRepeatedBytesList([BYTES_B64, BYTES_B64]); assertGetters(); - msg.setRepeatedBytesList(null); + msg.setRepeatedBytesList([]); assertEquals(0, msg.getRepeatedBytesList().length); assertEquals(0, msg.getRepeatedBytesList_asB64().length); assertEquals(0, msg.getRepeatedBytesList_asU8().length); diff --git a/js/debug.js b/js/debug.js index 3c1ada02..46b24853 100644 --- a/js/debug.js +++ b/js/debug.js @@ -95,8 +95,7 @@ jspb.debug.dump_ = function(thing) { if (match && name != 'getExtension' && name != 'getJsPbMessageId') { var has = 'has' + match[1]; - if (!thing[has] || thing[has]()) - { + if (!thing[has] || thing[has]()) { var val = thing[name](); object[jspb.debug.formatFieldName_(match[1])] = jspb.debug.dump_(val); } diff --git a/js/debug_test.js b/js/debug_test.js index 01cbf891..702cc76e 100644 --- a/js/debug_test.js +++ b/js/debug_test.js @@ -65,7 +65,7 @@ describe('debugTest', function() { 'aBoolean': true }, jspb.debug.dump(message)); - message.setAString(undefined); + message.clearAString(); assertObjectEquals({ $name: 'proto.jspb.test.Simple1', diff --git a/js/map.js b/js/map.js index e6406a60..0f8401c4 100644 --- a/js/map.js +++ b/js/map.js @@ -103,7 +103,10 @@ jspb.Map.prototype.toArray = function() { var m = this.map_; for (var p in m) { if (Object.prototype.hasOwnProperty.call(m, p)) { - m[p].valueWrapper.toArray(); + var valueWrapper = /** @type {?jspb.Message} */ (m[p].valueWrapper); + if (valueWrapper) { + valueWrapper.toArray(); + } } } } @@ -343,13 +346,13 @@ jspb.Map.prototype.has = function(key) { * number. * @param {number} fieldNumber * @param {!jspb.BinaryWriter} writer - * @param {function(this:jspb.BinaryWriter,number,K)=} keyWriterFn + * @param {!function(this:jspb.BinaryWriter,number,K)} keyWriterFn * The method on BinaryWriter that writes type K to the stream. - * @param {function(this:jspb.BinaryWriter,number,V)| - * function(this:jspb.BinaryReader,V,?)=} valueWriterFn + * @param {!function(this:jspb.BinaryWriter,number,V)| + * function(this:jspb.BinaryReader,V,?)} valueWriterFn * The method on BinaryWriter that writes type V to the stream. May be * writeMessage, in which case the second callback arg form is used. - * @param {?function(V,!jspb.BinaryWriter)=} opt_valueWriterCallback + * @param {function(V,!jspb.BinaryWriter)=} opt_valueWriterCallback * The BinaryWriter serialization callback for type V, if V is a message * type. */ @@ -376,14 +379,15 @@ jspb.Map.prototype.serializeBinary = function( * Read one key/value message from the given BinaryReader. Compatible as the * `reader` callback parameter to jspb.BinaryReader.readMessage, to be called * when a key/value pair submessage is encountered. + * @template K, V * @param {!jspb.Map} map * @param {!jspb.BinaryReader} reader - * @param {function(this:jspb.BinaryReader):K=} keyReaderFn + * @param {!function(this:jspb.BinaryReader):K} keyReaderFn * The method on BinaryReader that reads type K from the stream. * - * @param {function(this:jspb.BinaryReader):V| - * function(this:jspb.BinaryReader,V, - * function(V,!jspb.BinaryReader))=} valueReaderFn + * @param {!function(this:jspb.BinaryReader):V| + * function(this:jspb.BinaryReader,V, + * function(V,!jspb.BinaryReader))} valueReaderFn * The method on BinaryReader that reads type V from the stream. May be * readMessage, in which case the second callback arg form is used. * diff --git a/js/maps_test.js b/js/maps_test.js new file mode 100755 index 00000000..3ffb510b --- /dev/null +++ b/js/maps_test.js @@ -0,0 +1,359 @@ +// 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. + +goog.require('goog.testing.asserts'); +goog.require('goog.userAgent'); +goog.require('proto.jspb.test.MapValueEnum'); +goog.require('proto.jspb.test.MapValueMessage'); +goog.require('proto.jspb.test.MapValueMessageNoBinary'); +goog.require('proto.jspb.test.TestMapFields'); +goog.require('proto.jspb.test.TestMapFieldsNoBinary'); + +/** + * Helper: check that the given map has exactly this set of (sorted) entries. + * @param {!jspb.Map} map + * @param {!Array>} entries + */ +function checkMapEquals(map, entries) { + var arr = map.toArray(); + assertEquals(arr.length, entries.length); + for (var i = 0; i < arr.length; i++) { + assertElementsEquals(arr[i], entries[i]); + } +} + +/** + * Converts an ES6 iterator to an array. + * @template T + * @param {!Iterator} iter an iterator + * @return {!Array} + */ +function toArray(iter) { + var arr = []; + while (true) { + var val = iter.next(); + if (val.done) { + break; + } + arr.push(val.value); + } + return arr; +} + + +/** + * Helper: generate test methods for this TestMapFields class. + * @param {?} msgInfo + * @param {?} submessageCtor + * @param {!string} suffix + */ +function makeTests(msgInfo, submessageCtor, suffix) { + /** + * Helper: fill all maps on a TestMapFields. + * @param {?} msg + */ + var fillMapFields = function(msg) { + msg.getMapStringStringMap().set('asdf', 'jkl;').set('key 2', 'hello world'); + msg.getMapStringInt32Map().set('a', 1).set('b', -2); + msg.getMapStringInt64Map().set('c', 0x100000000).set('d', 0x200000000); + msg.getMapStringBoolMap().set('e', true).set('f', false); + msg.getMapStringDoubleMap().set('g', 3.14159).set('h', 2.71828); + msg.getMapStringEnumMap() + .set('i', proto.jspb.test.MapValueEnum.MAP_VALUE_BAR) + .set('j', proto.jspb.test.MapValueEnum.MAP_VALUE_BAZ); + msg.getMapStringMsgMap() + .set('k', new submessageCtor()) + .set('l', new submessageCtor()); + msg.getMapStringMsgMap().get('k').setFoo(42); + msg.getMapStringMsgMap().get('l').setFoo(84); + msg.getMapInt32StringMap().set(-1, 'a').set(42, 'b'); + msg.getMapInt64StringMap().set(0x123456789abc, 'c').set(0xcba987654321, 'd'); + msg.getMapBoolStringMap().set(false, 'e').set(true, 'f'); + }; + + /** + * Helper: check all maps on a TestMapFields. + * @param {?} msg + */ + var checkMapFields = function(msg) { + checkMapEquals(msg.getMapStringStringMap(), [ + ['asdf', 'jkl;'], + ['key 2', 'hello world'] + ]); + checkMapEquals(msg.getMapStringInt32Map(), [ + ['a', 1], + ['b', -2] + ]); + checkMapEquals(msg.getMapStringInt64Map(), [ + ['c', 0x100000000], + ['d', 0x200000000] + ]); + checkMapEquals(msg.getMapStringBoolMap(), [ + ['e', true], + ['f', false] + ]); + checkMapEquals(msg.getMapStringDoubleMap(), [ + ['g', 3.14159], + ['h', 2.71828] + ]); + checkMapEquals(msg.getMapStringEnumMap(), [ + ['i', proto.jspb.test.MapValueEnum.MAP_VALUE_BAR], + ['j', proto.jspb.test.MapValueEnum.MAP_VALUE_BAZ] + ]); + checkMapEquals(msg.getMapInt32StringMap(), [ + [-1, 'a'], + [42, 'b'] + ]); + checkMapEquals(msg.getMapInt64StringMap(), [ + [0x123456789abc, 'c'], + [0xcba987654321, 'd'] + ]); + checkMapEquals(msg.getMapBoolStringMap(), [ + [false, 'e'], + [true, 'f'] + ]); + + assertEquals(msg.getMapStringMsgMap().getLength(), 2); + assertEquals(msg.getMapStringMsgMap().get('k').getFoo(), 42); + assertEquals(msg.getMapStringMsgMap().get('l').getFoo(), 84); + + var entries = toArray(msg.getMapStringMsgMap().entries()); + assertEquals(entries.length, 2); + entries.forEach(function(entry) { + var key = entry[0]; + var val = entry[1]; + assert(val === msg.getMapStringMsgMap().get(key)); + }); + + msg.getMapStringMsgMap().forEach(function(val, key) { + assert(val === msg.getMapStringMsgMap().get(key)); + }); + }; + + it('testMapStringStringField' + suffix, function() { + var msg = new msgInfo.constructor(); + assertEquals(msg.getMapStringStringMap().getLength(), 0); + assertEquals(msg.getMapStringInt32Map().getLength(), 0); + assertEquals(msg.getMapStringInt64Map().getLength(), 0); + assertEquals(msg.getMapStringBoolMap().getLength(), 0); + assertEquals(msg.getMapStringDoubleMap().getLength(), 0); + assertEquals(msg.getMapStringEnumMap().getLength(), 0); + assertEquals(msg.getMapStringMsgMap().getLength(), 0); + + // Re-create to clear out any internally-cached wrappers, etc. + msg = new msgInfo.constructor(); + var m = msg.getMapStringStringMap(); + assertEquals(m.has('asdf'), false); + assertEquals(m.get('asdf'), undefined); + m.set('asdf', 'hello world'); + assertEquals(m.has('asdf'), true); + assertEquals(m.get('asdf'), 'hello world'); + m.set('jkl;', 'key 2'); + assertEquals(m.has('jkl;'), true); + assertEquals(m.get('jkl;'), 'key 2'); + assertEquals(m.getLength(), 2); + var it = m.entries(); + assertElementsEquals(it.next().value, ['asdf', 'hello world']); + assertElementsEquals(it.next().value, ['jkl;', 'key 2']); + assertEquals(it.next().done, true); + checkMapEquals(m, [ + ['asdf', 'hello world'], + ['jkl;', 'key 2'] + ]); + m.del('jkl;'); + assertEquals(m.has('jkl;'), false); + assertEquals(m.get('jkl;'), undefined); + assertEquals(m.getLength(), 1); + it = m.keys(); + assertEquals(it.next().value, 'asdf'); + assertEquals(it.next().done, true); + it = m.values(); + assertEquals(it.next().value, 'hello world'); + assertEquals(it.next().done, true); + + var count = 0; + m.forEach(function(value, key, map) { + assertEquals(map, m); + assertEquals(key, 'asdf'); + assertEquals(value, 'hello world'); + count++; + }); + assertEquals(count, 1); + + m.clear(); + assertEquals(m.getLength(), 0); + }); + + + /** + * Tests operations on maps with all key and value types. + */ + it('testAllMapTypes' + suffix, function() { + var msg = new msgInfo.constructor(); + fillMapFields(msg); + checkMapFields(msg); + }); + + + if (msgInfo.deserializeBinary) { + /** + * Tests serialization and deserialization in binary format. + */ + it('testBinaryFormat' + suffix, function() { + if (goog.userAgent.IE && !goog.userAgent.isDocumentModeOrHigher(10)) { + // IE8/9 currently doesn't support binary format because they lack + // TypedArray. + return; + } + + // Check that the format is correct. + var msg = new msgInfo.constructor(); + msg.getMapStringStringMap().set('A', 'a'); + var serialized = msg.serializeBinary(); + var expectedSerialized = [ + 0x0a, 0x6, // field 1 (map_string_string), delimited, length 6 + 0x0a, 0x1, // field 1 in submessage (key), delimited, length 1 + 0x41, // ASCII 'A' + 0x12, 0x1, // field 2 in submessage (value), delimited, length 1 + 0x61 // ASCII 'a' + ]; + assertEquals(serialized.length, expectedSerialized.length); + for (var i = 0; i < serialized.length; i++) { + assertEquals(serialized[i], expectedSerialized[i]); + } + + // Check that all map fields successfully round-trip. + msg = new msgInfo.constructor(); + fillMapFields(msg); + serialized = msg.serializeBinary(); + var decoded = msgInfo.deserializeBinary(serialized); + checkMapFields(decoded); + }); + } + + + /** + * Tests serialization and deserialization in JSPB format. + */ + it('testJSPBFormat' + suffix, function() { + var msg = new msgInfo.constructor(); + fillMapFields(msg); + var serialized = msg.serialize(); + var decoded = msgInfo.deserialize(serialized); + checkMapFields(decoded); + }); + + /** + * Tests serialization and deserialization in JSPB format, when there is + * a submessage that also contains map entries. This tests recursive + * sync. + */ + it('testJSPBFormatNested' + suffix, function() { + var submsg = new msgInfo.constructor(); + var mapValue = new msgInfo.constructor(); + var msg = new msgInfo.constructor(); + + msg.getMapStringTestmapfieldsMap().set('test', mapValue); + msg.setTestMapFields(submsg); + + fillMapFields(submsg); + fillMapFields(msg); + fillMapFields(mapValue); + + var serialized = msg.serialize(); + + var decoded = msgInfo.deserialize(serialized); + checkMapFields(decoded); + + var decodedSubmsg = decoded.getTestMapFields(); + assertNotNull(decodedSubmsg); + checkMapFields(decodedSubmsg); + + var decodedMapValue = decoded.getMapStringTestmapfieldsMap().get('test'); + assertNotNull(decodedMapValue); + checkMapFields(decodedMapValue); + }); + + /** + * Tests toObject()/fromObject(). + */ + it('testToFromObject' + suffix, function() { + var msg = new msgInfo.constructor(); + fillMapFields(msg); + var obj = msg.toObject(); + var decoded = msgInfo.fromObject(obj); + checkMapFields(decoded); + obj = msgInfo.deserialize(msg.serialize()).toObject(); + decoded = msgInfo.fromObject(obj); + checkMapFields(decoded); + }); + + + /** + * Exercises the lazy map<->underlying array sync. + */ + it('testLazyMapSync' + suffix, function() { + // Start with a JSPB array containing a few map entries. + var entries = [ + ['a', 'entry 1'], + ['c', 'entry 2'], + ['b', 'entry 3'] + ]; + var msg = new msgInfo.constructor([entries]); + assertEquals(entries.length, 3); + assertEquals(entries[0][0], 'a'); + assertEquals(entries[1][0], 'c'); + assertEquals(entries[2][0], 'b'); + msg.getMapStringStringMap().del('a'); + assertEquals(entries.length, 3); // not yet sync'd + msg.toArray(); // force a sync + assertEquals(entries.length, 2); + assertEquals(entries[0][0], 'b'); // now in sorted order + assertEquals(entries[1][0], 'c'); + + var a = msg.toArray(); + assertEquals(a[0], entries); // retains original reference + }); +} + +describe('mapsTest', function() { + makeTests({ + constructor: proto.jspb.test.TestMapFields, + fromObject: proto.jspb.test.TestMapFields.fromObject, + deserialize: proto.jspb.test.TestMapFields.deserialize, + deserializeBinary: proto.jspb.test.TestMapFields.deserializeBinary + }, proto.jspb.test.MapValueMessage, "_Binary"); + makeTests({ + constructor: proto.jspb.test.TestMapFieldsNoBinary, + fromObject: proto.jspb.test.TestMapFieldsNoBinary.fromObject, + deserialize: proto.jspb.test.TestMapFieldsNoBinary.deserialize, + deserializeBinary: null + }, proto.jspb.test.MapValueMessageNoBinary, "_NoBinary"); +}); diff --git a/js/message.js b/js/message.js index 631ebe69..b150722a 100644 --- a/js/message.js +++ b/js/message.js @@ -106,17 +106,17 @@ jspb.ExtensionFieldInfo = function(fieldNumber, fieldName, ctor, toObjectFn, /** * Stores binary-related information for a single extension field. * @param {!jspb.ExtensionFieldInfo} fieldInfo - * @param {?function(number,?)=} binaryReaderFn - * @param {?function(number,?)|function(number,?,?,?,?,?)=} binaryWriterFn - * @param {?function(?,?)=} opt_binaryMessageSerializeFn - * @param {?function(?,?)=} opt_binaryMessageDeserializeFn - * @param {?boolean=} opt_isPacked + * @param {!function(number,?)} binaryReaderFn + * @param {!function(number,?)|function(number,?,?,?,?,?)} binaryWriterFn + * @param {function(?,?)=} opt_binaryMessageSerializeFn + * @param {function(?,?)=} opt_binaryMessageDeserializeFn + * @param {boolean=} opt_isPacked * @constructor * @struct * @template T */ jspb.ExtensionFieldBinaryInfo = function(fieldInfo, binaryReaderFn, binaryWriterFn, - binaryMessageSerializeFn, binaryMessageDeserializeFn, isPacked) { + opt_binaryMessageSerializeFn, opt_binaryMessageDeserializeFn, opt_isPacked) { /** @const */ this.fieldInfo = fieldInfo; /** @const */ @@ -124,11 +124,11 @@ jspb.ExtensionFieldBinaryInfo = function(fieldInfo, binaryReaderFn, binaryWriter /** @const */ this.binaryWriterFn = binaryWriterFn; /** @const */ - this.binaryMessageSerializeFn = binaryMessageSerializeFn; + this.binaryMessageSerializeFn = opt_binaryMessageSerializeFn; /** @const */ - this.binaryMessageDeserializeFn = binaryMessageDeserializeFn; + this.binaryMessageDeserializeFn = opt_binaryMessageDeserializeFn; /** @const */ - this.isPacked = isPacked; + this.isPacked = opt_isPacked; }; /** @@ -744,7 +744,7 @@ jspb.Message.assertConsistentTypes_ = function(array) { * @return {T} The field's value. * @protected */ -jspb.Message.getFieldProto3 = function(msg, fieldNumber, defaultValue) { +jspb.Message.getFieldWithDefault = function(msg, fieldNumber, defaultValue) { var value = jspb.Message.getField(msg, fieldNumber); if (value == null) { return defaultValue; @@ -810,6 +810,24 @@ jspb.Message.setField = function(msg, fieldNumber, value) { }; +/** + * Adds a value to a repeated, primitive field. + * @param {!jspb.Message} msg A jspb proto. + * @param {number} fieldNumber The field number. + * @param {string|number|boolean|!Uint8Array} value New value + * @param {number=} opt_index Index where to put new value. + * @protected + */ +jspb.Message.addToRepeatedField = function(msg, fieldNumber, value, opt_index) { + var arr = jspb.Message.getField(msg, fieldNumber); + if (opt_index != undefined) { + arr.splice(opt_index, 0, value); + } else { + arr.push(value); + } +}; + + /** * Sets the value of a field in a oneof union and clears all other fields in * the union. @@ -907,6 +925,24 @@ jspb.Message.getWrapperField = function(msg, ctor, fieldNumber, opt_required) { * @protected */ jspb.Message.getRepeatedWrapperField = function(msg, ctor, fieldNumber) { + jspb.Message.wrapRepeatedField_(msg, ctor, fieldNumber); + var val = msg.wrappers_[fieldNumber]; + if (val == jspb.Message.EMPTY_LIST_SENTINEL_) { + val = msg.wrappers_[fieldNumber] = []; + } + return /** @type {!Array} */ (val); +}; + + +/** + * Wraps underlying array into proto message representation if it wasn't done + * before. + * @param {!jspb.Message} msg A jspb proto. + * @param {function(new:jspb.Message, ?Array)} ctor Constructor for the field. + * @param {number} fieldNumber The field number. + * @private + */ +jspb.Message.wrapRepeatedField_ = function(msg, ctor, fieldNumber) { if (!msg.wrappers_) { msg.wrappers_ = {}; } @@ -917,11 +953,6 @@ jspb.Message.getRepeatedWrapperField = function(msg, ctor, fieldNumber) { } msg.wrappers_[fieldNumber] = wrappers; } - var val = msg.wrappers_[fieldNumber]; - if (val == jspb.Message.EMPTY_LIST_SENTINEL_) { - val = msg.wrappers_[fieldNumber] = []; - } - return /** @type {Array} */ (val); }; @@ -980,6 +1011,48 @@ jspb.Message.setRepeatedWrapperField = function(msg, fieldNumber, value) { }; +/** + * Add a message to a repeated proto field. + * @param {!jspb.Message} msg A jspb proto. + * @param {number} fieldNumber The field number. + * @param {T_CHILD|undefined} value Proto that will be added to the + * repeated field. + * @param {function(new:T_CHILD, ?Array=)} ctor The constructor of the + * message type. + * @param {number|undefined} index Index at which to insert the value. + * @return {T_CHILD_NOT_UNDEFINED} proto that was inserted to the repeated field + * @template MessageType + * Use go/closure-ttl to declare a non-undefined version of T_CHILD. Replace the + * undefined in blah|undefined with none. This is necessary because the compiler + * will infer T_CHILD to be |undefined. + * @template T_CHILD + * @template T_CHILD_NOT_UNDEFINED := + * cond(isUnknown(T_CHILD), unknown(), + * mapunion(T_CHILD, (X) => + * cond(eq(X, 'undefined'), none(), X))) + * =: + * @protected + */ +jspb.Message.addToRepeatedWrapperField = function( + msg, fieldNumber, value, ctor, index) { + jspb.Message.wrapRepeatedField_(msg, ctor, fieldNumber); + var wrapperArray = msg.wrappers_[fieldNumber]; + if (!wrapperArray) { + wrapperArray = msg.wrappers_[fieldNumber] = []; + } + var insertedValue = value ? value : new ctor(); + var array = jspb.Message.getField(msg, fieldNumber); + if (index != undefined) { + wrapperArray.splice(index, 0, insertedValue); + array.splice(index, 0, insertedValue.toArray()); + } else { + wrapperArray.push(insertedValue); + array.push(insertedValue.toArray()); + } + return insertedValue; +}; + + /** * Converts a JsPb repeated message field into a map. The map will contain * protos unless an optional toObject function is given, in which case it will @@ -1114,32 +1187,39 @@ jspb.Message.prototype.getExtension = function(fieldInfo) { * @param {jspb.ExtensionFieldInfo} fieldInfo Specifies the field to set. * @param {jspb.Message|string|Uint8Array|number|boolean|Array?} value The value * to set. + * @return {THIS} For chaining + * @this {THIS} + * @template THIS */ jspb.Message.prototype.setExtension = function(fieldInfo, value) { - if (!this.wrappers_) { - this.wrappers_ = {}; + // Cast self, since the inferred THIS is unknown inside the function body. + // https://github.com/google/closure-compiler/issues/1411#issuecomment-232442220 + var self = /** @type {!jspb.Message} */ (this); + if (!self.wrappers_) { + self.wrappers_ = {}; } - jspb.Message.maybeInitEmptyExtensionObject_(this); + jspb.Message.maybeInitEmptyExtensionObject_(self); var fieldNumber = fieldInfo.fieldIndex; if (fieldInfo.isRepeated) { value = value || []; if (fieldInfo.isMessageType()) { - this.wrappers_[fieldNumber] = value; - this.extensionObject_[fieldNumber] = goog.array.map( + self.wrappers_[fieldNumber] = value; + self.extensionObject_[fieldNumber] = goog.array.map( /** @type {Array} */ (value), function(msg) { return msg.toArray(); }); } else { - this.extensionObject_[fieldNumber] = value; + self.extensionObject_[fieldNumber] = value; } } else { if (fieldInfo.isMessageType()) { - this.wrappers_[fieldNumber] = value; - this.extensionObject_[fieldNumber] = value ? value.toArray() : value; + self.wrappers_[fieldNumber] = value; + self.extensionObject_[fieldNumber] = value ? value.toArray() : value; } else { - this.extensionObject_[fieldNumber] = value; + self.extensionObject_[fieldNumber] = value; } } + return self; }; @@ -1308,7 +1388,30 @@ jspb.Message.compareFields = function(field1, field2) { /** - * Static clone function. NOTE: A type-safe method called "cloneMessage" exists + * Templated, type-safe cloneMessage definition. + * @return {THIS} + * @this {THIS} + * @template THIS + */ +jspb.Message.prototype.cloneMessage = function() { + return jspb.Message.cloneMessage(/** @type {!jspb.Message} */ (this)); +}; + +/** + * Alias clone to cloneMessage. goog.object.unsafeClone uses clone to + * efficiently copy objects. Without this alias, copying jspb messages comes + * with a large performance penalty. + * @return {THIS} + * @this {THIS} + * @template THIS + */ +jspb.Message.prototype.clone = function() { + return jspb.Message.cloneMessage(/** @type {!jspb.Message} */ (this)); +}; + +/** + * Static clone function. NOTE: A type-safe method called "cloneMessage" + * exists * on each generated JsPb class. Do not call this function directly. * @param {!jspb.Message} msg A message to clone. * @return {!jspb.Message} A deep clone of the given message. @@ -1429,3 +1532,4 @@ jspb.Message.registry_ = {}; * @type {!Object.} */ jspb.Message.messageSetExtensions = {}; +jspb.Message.messageSetExtensionsBinary = {}; diff --git a/js/message_test.js b/js/message_test.js index b7791431..97c594c8 100644 --- a/js/message_test.js +++ b/js/message_test.js @@ -269,7 +269,7 @@ describe('Message test suite', function() { assertFalse(response.hasEnumField()); }); - it('testMessageRegistration', function() { + it('testMessageRegistration', /** @suppress {visibility} */ function() { // goog.require(SomeResponse) will include its library, which will in // turn add SomeResponse to the message registry. assertEquals(jspb.Message.registry_['res'], proto.jspb.test.SomeResponse); @@ -297,47 +297,9 @@ describe('Message test suite', function() { var expected = [,,, [], []]; expected[0] = expected[1] = expected[2] = undefined; assertObjectEquals(expected, foo.toArray()); - - // Test set(null). We could deprecated this in favor of clear(), but - // it's also convenient to have. - data = ['str', true, [11], [[22], [33]], ['s1', 's2']]; - foo = new proto.jspb.test.OptionalFields(data); - foo.setAString(null); - foo.setABool(null); - foo.setANestedMessage(null); - foo.setARepeatedMessageList(null); - foo.setARepeatedStringList(null); - assertEquals('', foo.getAString()); - assertEquals(false, foo.getABool()); - assertNull(foo.getANestedMessage()); - assertFalse(foo.hasAString()); - assertFalse(foo.hasABool()); - assertObjectEquals([], foo.getARepeatedMessageList()); - assertObjectEquals([], foo.getARepeatedStringList()); - assertObjectEquals([null, null, null, [], []], foo.toArray()); - - // Test set(undefined). Again, not something we really need, and not - // supported directly by our typing, but it should 'do the right thing'. - data = ['str', true, [11], [[22], [33]], ['s1', 's2']]; - foo = new proto.jspb.test.OptionalFields(data); - foo.setAString(undefined); - foo.setABool(undefined); - foo.setANestedMessage(undefined); - foo.setARepeatedMessageList(undefined); - foo.setARepeatedStringList(undefined); - assertEquals('', foo.getAString()); - assertEquals(false, foo.getABool()); - assertUndefined(foo.getANestedMessage()); - assertFalse(foo.hasAString()); - assertFalse(foo.hasABool()); - assertObjectEquals([], foo.getARepeatedMessageList()); - assertObjectEquals([], foo.getARepeatedStringList()); - expected = [,,, [], []]; - expected[0] = expected[1] = expected[2] = undefined; - assertObjectEquals(expected, foo.toArray()); }); - it('testDifferenceRawObject', function() { + it('testDifferenceRawObject', /** @suppress {visibility} */ function() { var p1 = new proto.jspb.test.HasExtensions(['hi', 'diff', {}]); var p2 = new proto.jspb.test.HasExtensions(['hi', 'what', {1000: 'unique'}]); @@ -477,7 +439,7 @@ describe('Message test suite', function() { var extension = new proto.jspb.test.CloneExtension(); extension.setExt('e1'); original.setExtension(proto.jspb.test.IsExtension.extField, extension); - var clone = original.cloneMessage(); + var clone = original.clone(); assertArrayEquals(['v1',, ['x1', ['y1', 'z1']],, [['x2', ['y2', 'z2']], ['x3', ['y3', 'z3']]], bytes1,, { 100: [, 'e1'] }], clone.toArray()); @@ -712,11 +674,12 @@ describe('Message test suite', function() { assertArrayEquals([1, 2, 3, {1: 'hi'}], msg.toArray()); }); - it('testExtendedMessageEnsureObject', function() { - var data = new proto.jspb.test.HasExtensions(['str1', - {'a_key': 'an_object'}]); - assertEquals('an_object', data.extensionObject_['a_key']); - }); + it('testExtendedMessageEnsureObject', + /** @suppress {visibility} */ function() { + var data = + new proto.jspb.test.HasExtensions(['str1', {'a_key': 'an_object'}]); + assertEquals('an_object', data.extensionObject_['a_key']); + }); it('testToObject_hasExtensionField', function() { var data = new proto.jspb.test.HasExtensions(['str1', {100: ['ext1']}]); diff --git a/js/proto3_test.js b/js/proto3_test.js index fab0fd44..3c929eff 100644 --- a/js/proto3_test.js +++ b/js/proto3_test.js @@ -294,7 +294,7 @@ describe('proto3Test', function() { msg.setOptionalForeignEnum(proto.jspb.test.Proto3Enum.PROTO3_BAR); msg.setOptionalForeignEnum(proto.jspb.test.Proto3Enum.PROTO3_FOO); msg.setOneofUint32(32); - msg.setOneofUint32(null); + msg.clearOneofUint32(); var serialized = msg.serializeBinary(); diff --git a/objectivec/google/protobuf/Duration.pbobjc.h b/objectivec/google/protobuf/Duration.pbobjc.h index 67380704..e70138a0 100644 --- a/objectivec/google/protobuf/Duration.pbobjc.h +++ b/objectivec/google/protobuf/Duration.pbobjc.h @@ -92,6 +92,12 @@ typedef GPB_ENUM(GPBDuration_FieldNumber) { * end.seconds += 1; * end.nanos -= 1000000000; * } + * + * Example 3: Compute Duration from datetime.timedelta in Python. + * + * td = datetime.timedelta(days=3, minutes=10) + * duration = Duration() + * duration.FromTimedelta(td) **/ @interface GPBDuration : GPBMessage diff --git a/objectivec/google/protobuf/FieldMask.pbobjc.h b/objectivec/google/protobuf/FieldMask.pbobjc.h index 6434ac18..07e60818 100644 --- a/objectivec/google/protobuf/FieldMask.pbobjc.h +++ b/objectivec/google/protobuf/FieldMask.pbobjc.h @@ -94,7 +94,7 @@ typedef GPB_ENUM(GPBFieldMask_FieldNumber) { * } * * A repeated field is not allowed except at the last position of a - * field mask. + * paths string. * * If a FieldMask object is not present in a get operation, the * operation applies to all fields (as if a FieldMask of all fields @@ -121,8 +121,8 @@ typedef GPB_ENUM(GPBFieldMask_FieldNumber) { * * If a repeated field is specified for an update operation, the existing * repeated values in the target resource will be overwritten by the new values. - * Note that a repeated field is only allowed in the last position of a field - * mask. + * Note that a repeated field is only allowed in the last position of a `paths` + * string. * * If a sub-message is specified in the last position of the field mask for an * update operation, then the existing sub-message in the target resource is diff --git a/objectivec/google/protobuf/Timestamp.pbobjc.h b/objectivec/google/protobuf/Timestamp.pbobjc.h index 898f88e3..9c83d094 100644 --- a/objectivec/google/protobuf/Timestamp.pbobjc.h +++ b/objectivec/google/protobuf/Timestamp.pbobjc.h @@ -101,16 +101,14 @@ typedef GPB_ENUM(GPBTimestamp_FieldNumber) { * * Example 5: Compute Timestamp from current time in Python. * - * now = time.time() - * seconds = int(now) - * nanos = int((now - seconds) * 10**9) - * timestamp = Timestamp(seconds=seconds, nanos=nanos) + * timestamp = Timestamp() + * timestamp.GetCurrentTime() **/ @interface GPBTimestamp : GPBMessage /** * Represents seconds of UTC time since Unix epoch - * 1970-01-01T00:00:00Z. Must be from from 0001-01-01T00:00:00Z to + * 1970-01-01T00:00:00Z. Must be from 0001-01-01T00:00:00Z to * 9999-12-31T23:59:59Z inclusive. **/ @property(nonatomic, readwrite) int64_t seconds; diff --git a/php/tests/test.pb.php b/php/tests/test.pb.php new file mode 100644 index 00000000..ed316b6e --- /dev/null +++ b/php/tests/test.pb.php @@ -0,0 +1,1385 @@ +optional_int32; + } + + public function setOptionalInt32($var) + { + GPBUtil::checkInt32($var); + $this->optional_int32 = $var; + } + + public function getOptionalInt64() + { + return $this->optional_int64; + } + + public function setOptionalInt64($var) + { + GPBUtil::checkInt64($var); + $this->optional_int64 = $var; + } + + public function getOptionalUint32() + { + return $this->optional_uint32; + } + + public function setOptionalUint32($var) + { + GPBUtil::checkUint32($var); + $this->optional_uint32 = $var; + } + + public function getOptionalUint64() + { + return $this->optional_uint64; + } + + public function setOptionalUint64($var) + { + GPBUtil::checkUint64($var); + $this->optional_uint64 = $var; + } + + public function getOptionalSint32() + { + return $this->optional_sint32; + } + + public function setOptionalSint32($var) + { + GPBUtil::checkInt32($var); + $this->optional_sint32 = $var; + } + + public function getOptionalSint64() + { + return $this->optional_sint64; + } + + public function setOptionalSint64($var) + { + GPBUtil::checkInt64($var); + $this->optional_sint64 = $var; + } + + public function getOptionalFixed32() + { + return $this->optional_fixed32; + } + + public function setOptionalFixed32($var) + { + GPBUtil::checkUint32($var); + $this->optional_fixed32 = $var; + } + + public function getOptionalFixed64() + { + return $this->optional_fixed64; + } + + public function setOptionalFixed64($var) + { + GPBUtil::checkUint64($var); + $this->optional_fixed64 = $var; + } + + public function getOptionalSfixed32() + { + return $this->optional_sfixed32; + } + + public function setOptionalSfixed32($var) + { + GPBUtil::checkInt32($var); + $this->optional_sfixed32 = $var; + } + + public function getOptionalSfixed64() + { + return $this->optional_sfixed64; + } + + public function setOptionalSfixed64($var) + { + GPBUtil::checkInt64($var); + $this->optional_sfixed64 = $var; + } + + public function getOptionalFloat() + { + return $this->optional_float; + } + + public function setOptionalFloat($var) + { + GPBUtil::checkFloat($var); + $this->optional_float = $var; + } + + public function getOptionalDouble() + { + return $this->optional_double; + } + + public function setOptionalDouble($var) + { + GPBUtil::checkDouble($var); + $this->optional_double = $var; + } + + public function getOptionalBool() + { + return $this->optional_bool; + } + + public function setOptionalBool($var) + { + GPBUtil::checkBool($var); + $this->optional_bool = $var; + } + + public function getOptionalString() + { + return $this->optional_string; + } + + public function setOptionalString($var) + { + GPBUtil::checkString($var, True); + $this->optional_string = $var; + } + + public function getOptionalBytes() + { + return $this->optional_bytes; + } + + public function setOptionalBytes($var) + { + GPBUtil::checkString($var, False); + $this->optional_bytes = $var; + } + + public function getOptionalEnum() + { + return $this->optional_enum; + } + + public function setOptionalEnum($var) + { + GPBUtil::checkEnum($var, \Foo\TestEnum::class); + $this->optional_enum = $var; + } + + public function getOptionalMessage() + { + return $this->optional_message; + } + + public function setOptionalMessage(&$var) + { + GPBUtil::checkMessage($var, \Foo\TestMessage_Sub::class); + $this->optional_message = $var; + } + + public function getOptionalIncludedMessage() + { + return $this->optional_included_message; + } + + public function setOptionalIncludedMessage(&$var) + { + GPBUtil::checkMessage($var, \Bar\TestInclude::class); + $this->optional_included_message = $var; + } + + public function getRecursive() + { + return $this->recursive; + } + + public function setRecursive(&$var) + { + GPBUtil::checkMessage($var, \Foo\TestMessage::class); + $this->recursive = $var; + } + + public function getRepeatedInt32() + { + return $this->repeated_int32; + } + + public function setRepeatedInt32(&$var) + { + GPBUtil::checkRepeatedField($var, GPBType::INT32); + $this->repeated_int32 = $var; + } + + public function getRepeatedInt64() + { + return $this->repeated_int64; + } + + public function setRepeatedInt64(&$var) + { + GPBUtil::checkRepeatedField($var, GPBType::INT64); + $this->repeated_int64 = $var; + } + + public function getRepeatedUint32() + { + return $this->repeated_uint32; + } + + public function setRepeatedUint32(&$var) + { + GPBUtil::checkRepeatedField($var, GPBType::UINT32); + $this->repeated_uint32 = $var; + } + + public function getRepeatedUint64() + { + return $this->repeated_uint64; + } + + public function setRepeatedUint64(&$var) + { + GPBUtil::checkRepeatedField($var, GPBType::UINT64); + $this->repeated_uint64 = $var; + } + + public function getRepeatedSint32() + { + return $this->repeated_sint32; + } + + public function setRepeatedSint32(&$var) + { + GPBUtil::checkRepeatedField($var, GPBType::SINT32); + $this->repeated_sint32 = $var; + } + + public function getRepeatedSint64() + { + return $this->repeated_sint64; + } + + public function setRepeatedSint64(&$var) + { + GPBUtil::checkRepeatedField($var, GPBType::SINT64); + $this->repeated_sint64 = $var; + } + + public function getRepeatedFixed32() + { + return $this->repeated_fixed32; + } + + public function setRepeatedFixed32(&$var) + { + GPBUtil::checkRepeatedField($var, GPBType::FIXED32); + $this->repeated_fixed32 = $var; + } + + public function getRepeatedFixed64() + { + return $this->repeated_fixed64; + } + + public function setRepeatedFixed64(&$var) + { + GPBUtil::checkRepeatedField($var, GPBType::FIXED64); + $this->repeated_fixed64 = $var; + } + + public function getRepeatedSfixed32() + { + return $this->repeated_sfixed32; + } + + public function setRepeatedSfixed32(&$var) + { + GPBUtil::checkRepeatedField($var, GPBType::SFIXED32); + $this->repeated_sfixed32 = $var; + } + + public function getRepeatedSfixed64() + { + return $this->repeated_sfixed64; + } + + public function setRepeatedSfixed64(&$var) + { + GPBUtil::checkRepeatedField($var, GPBType::SFIXED64); + $this->repeated_sfixed64 = $var; + } + + public function getRepeatedFloat() + { + return $this->repeated_float; + } + + public function setRepeatedFloat(&$var) + { + GPBUtil::checkRepeatedField($var, GPBType::FLOAT); + $this->repeated_float = $var; + } + + public function getRepeatedDouble() + { + return $this->repeated_double; + } + + public function setRepeatedDouble(&$var) + { + GPBUtil::checkRepeatedField($var, GPBType::DOUBLE); + $this->repeated_double = $var; + } + + public function getRepeatedBool() + { + return $this->repeated_bool; + } + + public function setRepeatedBool(&$var) + { + GPBUtil::checkRepeatedField($var, GPBType::BOOL); + $this->repeated_bool = $var; + } + + public function getRepeatedString() + { + return $this->repeated_string; + } + + public function setRepeatedString(&$var) + { + GPBUtil::checkRepeatedField($var, GPBType::STRING); + $this->repeated_string = $var; + } + + public function getRepeatedBytes() + { + return $this->repeated_bytes; + } + + public function setRepeatedBytes(&$var) + { + GPBUtil::checkRepeatedField($var, GPBType::BYTES); + $this->repeated_bytes = $var; + } + + public function getRepeatedEnum() + { + return $this->repeated_enum; + } + + public function setRepeatedEnum(&$var) + { + GPBUtil::checkRepeatedField($var, GPBType::ENUM, Foo\TestEnum::class); + $this->repeated_enum = $var; + } + + public function getRepeatedMessage() + { + return $this->repeated_message; + } + + public function setRepeatedMessage(&$var) + { + GPBUtil::checkRepeatedField($var, GPBType::MESSAGE, \Foo\TestMessage_Sub::class); + $this->repeated_message = $var; + } + + public function getRepeatedRecursive() + { + return $this->repeated_recursive; + } + + public function setRepeatedRecursive(&$var) + { + GPBUtil::checkRepeatedField($var, GPBType::MESSAGE, \Foo\TestMessage::class); + $this->repeated_recursive = $var; + } + + public function getOneofInt32() + { + return $this->readOneof(51); + } + + public function setOneofInt32($var) + { + GPBUtil::checkInt32($var); + $this->writeOneof(51, $var); + } + + public function getOneofInt64() + { + return $this->readOneof(52); + } + + public function setOneofInt64($var) + { + GPBUtil::checkInt64($var); + $this->writeOneof(52, $var); + } + + public function getOneofUint32() + { + return $this->readOneof(53); + } + + public function setOneofUint32($var) + { + GPBUtil::checkUint32($var); + $this->writeOneof(53, $var); + } + + public function getOneofUint64() + { + return $this->readOneof(54); + } + + public function setOneofUint64($var) + { + GPBUtil::checkUint64($var); + $this->writeOneof(54, $var); + } + + public function getOneofSint32() + { + return $this->readOneof(55); + } + + public function setOneofSint32($var) + { + GPBUtil::checkUint32($var); + $this->writeOneof(55, $var); + } + + public function getOneofSint64() + { + return $this->readOneof(56); + } + + public function setOneofSint64($var) + { + GPBUtil::checkUint64($var); + $this->writeOneof(56, $var); + } + + public function getOneofFixed32() + { + return $this->readOneof(57); + } + + public function setOneofFixed32($var) + { + GPBUtil::checkUint32($var); + $this->writeOneof(57, $var); + } + + public function getOneofFixed64() + { + return $this->readOneof(58); + } + + public function setOneofFixed64($var) + { + GPBUtil::checkUint64($var); + $this->writeOneof(58, $var); + } + + public function getOneofSfixed32() + { + return $this->readOneof(59); + } + + public function setOneofSfixed32($var) + { + GPBUtil::checkUint32($var); + $this->writeOneof(59, $var); + } + + public function getOneofSfixed64() + { + return $this->readOneof(60); + } + + public function setOneofSfixed64($var) + { + GPBUtil::checkUint64($var); + $this->writeOneof(60, $var); + } + + public function getOneofDouble() + { + return $this->readOneof(61); + } + + public function setOneofDouble($var) + { + GPBUtil::checkDouble($var); + $this->writeOneof(61, $var); + } + + public function getOneofFloat() + { + return $this->readOneof(62); + } + + public function setOneofFloat($var) + { + GPBUtil::checkFloat($var); + $this->writeOneof(62, $var); + } + + public function getOneofBool() + { + return $this->readOneof(63); + } + + public function setOneofBool($var) + { + GPBUtil::checkBool($var); + $this->writeOneof(63, $var); + } + + public function getOneofString() + { + return $this->readOneof(64); + } + + public function setOneofString($var) + { + GPBUtil::checkString($var, True); + $this->writeOneof(64, $var); + } + + public function getOneofBytes() + { + return $this->readOneof(65); + } + + public function setOneofBytes($var) + { + GPBUtil::checkString($var, False); + $this->writeOneof(65, $var); + } + + public function getOneofEnum() + { + return $this->readOneof(66); + } + + public function setOneofEnum($var) + { + GPBUtil::checkEnum($var, \Foo\TestEnum::class); + $this->writeOneof(66, $var); + } + + public function getOneofMessage() + { + return $this->readOneof(67); + } + + public function setOneofMessage(&$var) + { + GPBUtil::checkMessage($var, \Foo\TestMessage_Sub::class); + $this->writeOneof(67, $var); + } + + public function getMapInt32Int32() + { + return $this->map_int32_int32; + } + + public function setMapInt32Int32(&$var) + { + $this->map_int32_int32 = $var; + } + + public function getMapInt64Int64() + { + return $this->map_int64_int64; + } + + public function setMapInt64Int64(&$var) + { + $this->map_int64_int64 = $var; + } + + public function getMapUint32Uint32() + { + return $this->map_uint32_uint32; + } + + public function setMapUint32Uint32(&$var) + { + $this->map_uint32_uint32 = $var; + } + + public function getMapUint64Uint64() + { + return $this->map_uint64_uint64; + } + + public function setMapUint64Uint64(&$var) + { + $this->map_uint64_uint64 = $var; + } + + public function getMapSint32Sint32() + { + return $this->map_sint32_sint32; + } + + public function setMapSint32Sint32(&$var) + { + $this->map_sint32_sint32 = $var; + } + + public function getMapSint64Sint64() + { + return $this->map_sint64_sint64; + } + + public function setMapSint64Sint64(&$var) + { + $this->map_sint64_sint64 = $var; + } + + public function getMapFixed32Fixed32() + { + return $this->map_fixed32_fixed32; + } + + public function setMapFixed32Fixed32(&$var) + { + $this->map_fixed32_fixed32 = $var; + } + + public function getMapFixed64Fixed64() + { + return $this->map_fixed64_fixed64; + } + + public function setMapFixed64Fixed64(&$var) + { + $this->map_fixed64_fixed64 = $var; + } + + public function getMapSfixed32Sfixed32() + { + return $this->map_sfixed32_sfixed32; + } + + public function setMapSfixed32Sfixed32(&$var) + { + $this->map_sfixed32_sfixed32 = $var; + } + + public function getMapSfixed64Sfixed64() + { + return $this->map_sfixed64_sfixed64; + } + + public function setMapSfixed64Sfixed64(&$var) + { + $this->map_sfixed64_sfixed64 = $var; + } + + public function getMapInt32Float() + { + return $this->map_int32_float; + } + + public function setMapInt32Float(&$var) + { + $this->map_int32_float = $var; + } + + public function getMapInt32Double() + { + return $this->map_int32_double; + } + + public function setMapInt32Double(&$var) + { + $this->map_int32_double = $var; + } + + public function getMapBoolBool() + { + return $this->map_bool_bool; + } + + public function setMapBoolBool(&$var) + { + $this->map_bool_bool = $var; + } + + public function getMapStringString() + { + return $this->map_string_string; + } + + public function setMapStringString(&$var) + { + $this->map_string_string = $var; + } + + public function getMapInt32Bytes() + { + return $this->map_int32_bytes; + } + + public function setMapInt32Bytes(&$var) + { + $this->map_int32_bytes = $var; + } + + public function getMapInt32Enum() + { + return $this->map_int32_enum; + } + + public function setMapInt32Enum(&$var) + { + $this->map_int32_enum = $var; + } + + public function getMapInt32Message() + { + return $this->map_int32_message; + } + + public function setMapInt32Message(&$var) + { + $this->map_int32_message = $var; + } + + public function getMapRecursive() + { + return $this->map_recursive; + } + + public function setMapRecursive(&$var) + { + $this->map_recursive = $var; + } + + public function getMyOneof() + { + return $this->my_oneof; + } + +} + +class TestMessage_Sub extends \Google\Protobuf\Internal\Message +{ + private $a = 0; + + public function getA() + { + return $this->a; + } + + public function setA($var) + { + GPBUtil::checkInt32($var); + $this->a = $var; + } + +} + +class TestPackedMessage extends \Google\Protobuf\Internal\Message +{ + private $repeated_int32; + private $repeated_int64; + private $repeated_uint32; + private $repeated_uint64; + private $repeated_sint32; + private $repeated_sint64; + private $repeated_fixed32; + private $repeated_fixed64; + private $repeated_sfixed32; + private $repeated_sfixed64; + private $repeated_float; + private $repeated_double; + private $repeated_bool; + private $repeated_enum; + + public function getRepeatedInt32() + { + return $this->repeated_int32; + } + + public function setRepeatedInt32(&$var) + { + GPBUtil::checkRepeatedField($var, GPBType::INT32); + $this->repeated_int32 = $var; + } + + public function getRepeatedInt64() + { + return $this->repeated_int64; + } + + public function setRepeatedInt64(&$var) + { + GPBUtil::checkRepeatedField($var, GPBType::INT64); + $this->repeated_int64 = $var; + } + + public function getRepeatedUint32() + { + return $this->repeated_uint32; + } + + public function setRepeatedUint32(&$var) + { + GPBUtil::checkRepeatedField($var, GPBType::UINT32); + $this->repeated_uint32 = $var; + } + + public function getRepeatedUint64() + { + return $this->repeated_uint64; + } + + public function setRepeatedUint64(&$var) + { + GPBUtil::checkRepeatedField($var, GPBType::UINT64); + $this->repeated_uint64 = $var; + } + + public function getRepeatedSint32() + { + return $this->repeated_sint32; + } + + public function setRepeatedSint32(&$var) + { + GPBUtil::checkRepeatedField($var, GPBType::SINT32); + $this->repeated_sint32 = $var; + } + + public function getRepeatedSint64() + { + return $this->repeated_sint64; + } + + public function setRepeatedSint64(&$var) + { + GPBUtil::checkRepeatedField($var, GPBType::SINT64); + $this->repeated_sint64 = $var; + } + + public function getRepeatedFixed32() + { + return $this->repeated_fixed32; + } + + public function setRepeatedFixed32(&$var) + { + GPBUtil::checkRepeatedField($var, GPBType::FIXED32); + $this->repeated_fixed32 = $var; + } + + public function getRepeatedFixed64() + { + return $this->repeated_fixed64; + } + + public function setRepeatedFixed64(&$var) + { + GPBUtil::checkRepeatedField($var, GPBType::FIXED64); + $this->repeated_fixed64 = $var; + } + + public function getRepeatedSfixed32() + { + return $this->repeated_sfixed32; + } + + public function setRepeatedSfixed32(&$var) + { + GPBUtil::checkRepeatedField($var, GPBType::SFIXED32); + $this->repeated_sfixed32 = $var; + } + + public function getRepeatedSfixed64() + { + return $this->repeated_sfixed64; + } + + public function setRepeatedSfixed64(&$var) + { + GPBUtil::checkRepeatedField($var, GPBType::SFIXED64); + $this->repeated_sfixed64 = $var; + } + + public function getRepeatedFloat() + { + return $this->repeated_float; + } + + public function setRepeatedFloat(&$var) + { + GPBUtil::checkRepeatedField($var, GPBType::FLOAT); + $this->repeated_float = $var; + } + + public function getRepeatedDouble() + { + return $this->repeated_double; + } + + public function setRepeatedDouble(&$var) + { + GPBUtil::checkRepeatedField($var, GPBType::DOUBLE); + $this->repeated_double = $var; + } + + public function getRepeatedBool() + { + return $this->repeated_bool; + } + + public function setRepeatedBool(&$var) + { + GPBUtil::checkRepeatedField($var, GPBType::BOOL); + $this->repeated_bool = $var; + } + + public function getRepeatedEnum() + { + return $this->repeated_enum; + } + + public function setRepeatedEnum(&$var) + { + GPBUtil::checkRepeatedField($var, GPBType::ENUM, Foo\TestEnum::class); + $this->repeated_enum = $var; + } + +} + +class TestUnpackedMessage extends \Google\Protobuf\Internal\Message +{ + private $repeated_int32; + private $repeated_int64; + private $repeated_uint32; + private $repeated_uint64; + private $repeated_sint32; + private $repeated_sint64; + private $repeated_fixed32; + private $repeated_fixed64; + private $repeated_sfixed32; + private $repeated_sfixed64; + private $repeated_float; + private $repeated_double; + private $repeated_bool; + private $repeated_enum; + + public function getRepeatedInt32() + { + return $this->repeated_int32; + } + + public function setRepeatedInt32(&$var) + { + GPBUtil::checkRepeatedField($var, GPBType::INT32); + $this->repeated_int32 = $var; + } + + public function getRepeatedInt64() + { + return $this->repeated_int64; + } + + public function setRepeatedInt64(&$var) + { + GPBUtil::checkRepeatedField($var, GPBType::INT64); + $this->repeated_int64 = $var; + } + + public function getRepeatedUint32() + { + return $this->repeated_uint32; + } + + public function setRepeatedUint32(&$var) + { + GPBUtil::checkRepeatedField($var, GPBType::UINT32); + $this->repeated_uint32 = $var; + } + + public function getRepeatedUint64() + { + return $this->repeated_uint64; + } + + public function setRepeatedUint64(&$var) + { + GPBUtil::checkRepeatedField($var, GPBType::UINT64); + $this->repeated_uint64 = $var; + } + + public function getRepeatedSint32() + { + return $this->repeated_sint32; + } + + public function setRepeatedSint32(&$var) + { + GPBUtil::checkRepeatedField($var, GPBType::SINT32); + $this->repeated_sint32 = $var; + } + + public function getRepeatedSint64() + { + return $this->repeated_sint64; + } + + public function setRepeatedSint64(&$var) + { + GPBUtil::checkRepeatedField($var, GPBType::SINT64); + $this->repeated_sint64 = $var; + } + + public function getRepeatedFixed32() + { + return $this->repeated_fixed32; + } + + public function setRepeatedFixed32(&$var) + { + GPBUtil::checkRepeatedField($var, GPBType::FIXED32); + $this->repeated_fixed32 = $var; + } + + public function getRepeatedFixed64() + { + return $this->repeated_fixed64; + } + + public function setRepeatedFixed64(&$var) + { + GPBUtil::checkRepeatedField($var, GPBType::FIXED64); + $this->repeated_fixed64 = $var; + } + + public function getRepeatedSfixed32() + { + return $this->repeated_sfixed32; + } + + public function setRepeatedSfixed32(&$var) + { + GPBUtil::checkRepeatedField($var, GPBType::SFIXED32); + $this->repeated_sfixed32 = $var; + } + + public function getRepeatedSfixed64() + { + return $this->repeated_sfixed64; + } + + public function setRepeatedSfixed64(&$var) + { + GPBUtil::checkRepeatedField($var, GPBType::SFIXED64); + $this->repeated_sfixed64 = $var; + } + + public function getRepeatedFloat() + { + return $this->repeated_float; + } + + public function setRepeatedFloat(&$var) + { + GPBUtil::checkRepeatedField($var, GPBType::FLOAT); + $this->repeated_float = $var; + } + + public function getRepeatedDouble() + { + return $this->repeated_double; + } + + public function setRepeatedDouble(&$var) + { + GPBUtil::checkRepeatedField($var, GPBType::DOUBLE); + $this->repeated_double = $var; + } + + public function getRepeatedBool() + { + return $this->repeated_bool; + } + + public function setRepeatedBool(&$var) + { + GPBUtil::checkRepeatedField($var, GPBType::BOOL); + $this->repeated_bool = $var; + } + + public function getRepeatedEnum() + { + return $this->repeated_enum; + } + + public function setRepeatedEnum(&$var) + { + GPBUtil::checkRepeatedField($var, GPBType::ENUM, Foo\TestEnum::class); + $this->repeated_enum = $var; + } + +} + +class TestEnum +{ + const ZERO = 0; + const ONE = 1; +} + +$pool = DescriptorPool::getGeneratedPool(); + +$pool->internalAddGeneratedFile(hex2bin( + "0a83250a0a746573742e70726f746f1203666f6f1a12746573745f696e63" . + "6c7564652e70726f746f22be1d0a0b546573744d65737361676512160a0e" . + "6f7074696f6e616c5f696e74333218012001280512160a0e6f7074696f6e" . + "616c5f696e74363418022001280312170a0f6f7074696f6e616c5f75696e" . + "74333218032001280d12170a0f6f7074696f6e616c5f75696e7436341804" . + "2001280412170a0f6f7074696f6e616c5f73696e74333218052001281112" . + "170a0f6f7074696f6e616c5f73696e74363418062001281212180a106f70" . + "74696f6e616c5f6669786564333218072001280712180a106f7074696f6e" . + "616c5f6669786564363418082001280612190a116f7074696f6e616c5f73" . + "6669786564333218092001280f12190a116f7074696f6e616c5f73666978" . + "65643634180a2001281012160a0e6f7074696f6e616c5f666c6f6174180b" . + "2001280212170a0f6f7074696f6e616c5f646f75626c65180c2001280112" . + "150a0d6f7074696f6e616c5f626f6f6c180d2001280812170a0f6f707469" . + "6f6e616c5f737472696e67180e2001280912160a0e6f7074696f6e616c5f" . + "6279746573180f2001280c12240a0d6f7074696f6e616c5f656e756d1810" . + "2001280e320d2e666f6f2e54657374456e756d122e0a106f7074696f6e61" . + "6c5f6d65737361676518112001280b32142e666f6f2e546573744d657373" . + "6167652e53756212330a196f7074696f6e616c5f696e636c756465645f6d" . + "65737361676518122001280b32102e6261722e54657374496e636c756465" . + "12230a0972656375727369766518132001280b32102e666f6f2e54657374" . + "4d65737361676512160a0e72657065617465645f696e743332181f200328" . + "0512160a0e72657065617465645f696e74363418202003280312170a0f72" . + "657065617465645f75696e74333218212003280d12170a0f726570656174" . + "65645f75696e74363418222003280412170a0f72657065617465645f7369" . + "6e74333218232003281112170a0f72657065617465645f73696e74363418" . + "242003281212180a1072657065617465645f666978656433321825200328" . + "0712180a1072657065617465645f6669786564363418262003280612190a" . + "1172657065617465645f736669786564333218272003280f12190a117265" . + "7065617465645f736669786564363418282003281012160a0e7265706561" . + "7465645f666c6f617418292003280212170a0f72657065617465645f646f" . + "75626c65182a2003280112150a0d72657065617465645f626f6f6c182b20" . + "03280812170a0f72657065617465645f737472696e67182c200328091216" . + "0a0e72657065617465645f6279746573182d2003280c12240a0d72657065" . + "617465645f656e756d182e2003280e320d2e666f6f2e54657374456e756d" . + "122e0a1072657065617465645f6d657373616765182f2003280b32142e66" . + "6f6f2e546573744d6573736167652e537562122c0a127265706561746564" . + "5f72656375727369766518302003280b32102e666f6f2e546573744d6573" . + "7361676512150a0b6f6e656f665f696e743332183320012805480012150a" . + "0b6f6e656f665f696e743634183420012803480012160a0c6f6e656f665f" . + "75696e74333218352001280d480012160a0c6f6e656f665f75696e743634" . + "183620012804480012160a0c6f6e656f665f73696e74333218372001280d" . + "480012160a0c6f6e656f665f73696e743634183820012804480012170a0d" . + "6f6e656f665f6669786564333218392001280d480012170a0d6f6e656f66" . + "5f66697865643634183a20012804480012180a0e6f6e656f665f73666978" . + "65643332183b2001280d480012180a0e6f6e656f665f7366697865643634" . + "183c20012804480012160a0c6f6e656f665f646f75626c65183d20012801" . + "480012150a0b6f6e656f665f666c6f6174183e20012802480012140a0a6f" . + "6e656f665f626f6f6c183f20012808480012160a0c6f6e656f665f737472" . + "696e67184020012809480012150a0b6f6e656f665f627974657318412001" . + "280c480012230a0a6f6e656f665f656e756d18422001280e320d2e666f6f" . + "2e54657374456e756d4800122d0a0d6f6e656f665f6d6573736167651843" . + "2001280b32142e666f6f2e546573744d6573736167652e5375624800123c" . + "0a0f6d61705f696e7433325f696e74333218472003280b32232e666f6f2e" . + "546573744d6573736167652e4d6170496e743332496e743332456e747279" . + "123c0a0f6d61705f696e7436345f696e74363418482003280b32232e666f" . + "6f2e546573744d6573736167652e4d6170496e743634496e743634456e74" . + "727912400a116d61705f75696e7433325f75696e74333218492003280b32" . + "252e666f6f2e546573744d6573736167652e4d617055696e74333255696e" . + "743332456e74727912400a116d61705f75696e7436345f75696e74363418" . + "4a2003280b32252e666f6f2e546573744d6573736167652e4d617055696e" . + "74363455696e743634456e74727912400a116d61705f73696e7433325f73" . + "696e743332184b2003280b32252e666f6f2e546573744d6573736167652e" . + "4d617053696e74333253696e743332456e74727912400a116d61705f7369" . + "6e7436345f73696e743634184c2003280b32252e666f6f2e546573744d65" . + "73736167652e4d617053696e74363453696e743634456e74727912440a13" . + "6d61705f666978656433325f66697865643332184d2003280b32272e666f" . + "6f2e546573744d6573736167652e4d617046697865643332466978656433" . + "32456e74727912440a136d61705f666978656436345f6669786564363418" . + "4e2003280b32272e666f6f2e546573744d6573736167652e4d6170466978" . + "6564363446697865643634456e74727912480a156d61705f736669786564" . + "33325f7366697865643332184f2003280b32292e666f6f2e546573744d65" . + "73736167652e4d617053666978656433325366697865643332456e747279" . + "12480a156d61705f73666978656436345f73666978656436341850200328" . + "0b32292e666f6f2e546573744d6573736167652e4d617053666978656436" . + "345366697865643634456e747279123c0a0f6d61705f696e7433325f666c" . + "6f617418512003280b32232e666f6f2e546573744d6573736167652e4d61" . + "70496e743332466c6f6174456e747279123e0a106d61705f696e7433325f" . + "646f75626c6518522003280b32242e666f6f2e546573744d657373616765" . + "2e4d6170496e743332446f75626c65456e74727912380a0d6d61705f626f" . + "6f6c5f626f6f6c18532003280b32212e666f6f2e546573744d6573736167" . + "652e4d6170426f6f6c426f6f6c456e74727912400a116d61705f73747269" . + "6e675f737472696e6718542003280b32252e666f6f2e546573744d657373" . + "6167652e4d6170537472696e67537472696e67456e747279123c0a0f6d61" . + "705f696e7433325f627974657318552003280b32232e666f6f2e54657374" . + "4d6573736167652e4d6170496e7433324279746573456e747279123a0a0e" . + "6d61705f696e7433325f656e756d18562003280b32222e666f6f2e546573" . + "744d6573736167652e4d6170496e743332456e756d456e74727912400a11" . + "6d61705f696e7433325f6d65737361676518572003280b32252e666f6f2e" . + "546573744d6573736167652e4d6170496e7433324d657373616765456e74" . + "727912390a0d6d61705f72656375727369766518582003280b32222e666f" . + "6f2e546573744d6573736167652e4d6170526563757273697665456e7472" . + "791a340a124d6170496e743332496e743332456e747279120b0a036b6579" . + "180120012805120d0a0576616c75651802200128053a0238011a340a124d" . + "6170496e743634496e743634456e747279120b0a036b6579180120012803" . + "120d0a0576616c75651802200128033a0238011a360a144d617055696e74" . + "333255696e743332456e747279120b0a036b657918012001280d120d0a05" . + "76616c756518022001280d3a0238011a360a144d617055696e7436345569" . + "6e743634456e747279120b0a036b6579180120012804120d0a0576616c75" . + "651802200128043a0238011a360a144d617053696e74333253696e743332" . + "456e747279120b0a036b6579180120012811120d0a0576616c7565180220" . + "0128113a0238011a360a144d617053696e74363453696e743634456e7472" . + "79120b0a036b6579180120012812120d0a0576616c75651802200128123a" . + "0238011a380a164d61704669786564333246697865643332456e74727912" . + "0b0a036b6579180120012807120d0a0576616c75651802200128073a0238" . + "011a380a164d61704669786564363446697865643634456e747279120b0a" . + "036b6579180120012806120d0a0576616c75651802200128063a0238011a" . + "3a0a184d617053666978656433325366697865643332456e747279120b0a" . + "036b657918012001280f120d0a0576616c756518022001280f3a0238011a" . + "3a0a184d617053666978656436345366697865643634456e747279120b0a" . + "036b6579180120012810120d0a0576616c75651802200128103a0238011a" . + "340a124d6170496e743332466c6f6174456e747279120b0a036b65791801" . + "20012805120d0a0576616c75651802200128023a0238011a350a134d6170" . + "496e743332446f75626c65456e747279120b0a036b657918012001280512" . + "0d0a0576616c75651802200128013a0238011a320a104d6170426f6f6c42" . + "6f6f6c456e747279120b0a036b6579180120012808120d0a0576616c7565" . + "1802200128083a0238011a360a144d6170537472696e67537472696e6745" . + "6e747279120b0a036b6579180120012809120d0a0576616c756518022001" . + "28093a0238011a340a124d6170496e7433324279746573456e747279120b" . + "0a036b6579180120012805120d0a0576616c756518022001280c3a023801" . + "1a420a114d6170496e743332456e756d456e747279120b0a036b65791801" . + "20012805121c0a0576616c756518022001280e320d2e666f6f2e54657374" . + "456e756d3a0238011a4c0a144d6170496e7433324d657373616765456e74" . + "7279120b0a036b657918012001280512230a0576616c756518022001280b" . + "32142e666f6f2e546573744d6573736167652e5375623a0238011a450a11" . + "4d6170526563757273697665456e747279120b0a036b6579180120012805" . + "121f0a0576616c756518022001280b32102e666f6f2e546573744d657373" . + "6167653a0238011a100a0353756212090a0161180120012805420a0a086d" . + "795f6f6e656f6622b7030a11546573745061636b65644d65737361676512" . + "1a0a0e72657065617465645f696e743332185a2003280542021001121a0a" . + "0e72657065617465645f696e743634185b2003280342021001121b0a0f72" . + "657065617465645f75696e743332185c2003280d42021001121b0a0f7265" . + "7065617465645f75696e743634185d2003280442021001121b0a0f726570" . + "65617465645f73696e743332185e2003281142021001121b0a0f72657065" . + "617465645f73696e743634185f2003281242021001121c0a107265706561" . + "7465645f6669786564333218602003280742021001121c0a107265706561" . + "7465645f6669786564363418612003280642021001121d0a117265706561" . + "7465645f736669786564333218622003280f42021001121d0a1172657065" . + "617465645f736669786564363418632003281042021001121a0a0e726570" . + "65617465645f666c6f617418642003280242021001121b0a0f7265706561" . + "7465645f646f75626c651865200328014202100112190a0d726570656174" . + "65645f626f6f6c1866200328084202100112280a0d72657065617465645f" . + "656e756d18672003280e320d2e666f6f2e54657374456e756d4202100122" . + "b9030a1354657374556e7061636b65644d657373616765121a0a0e726570" . + "65617465645f696e743332185a2003280542021000121a0a0e7265706561" . + "7465645f696e743634185b2003280342021000121b0a0f72657065617465" . + "645f75696e743332185c2003280d42021000121b0a0f7265706561746564" . + "5f75696e743634185d2003280442021000121b0a0f72657065617465645f" . + "73696e743332185e2003281142021000121b0a0f72657065617465645f73" . + "696e743634185f2003281242021000121c0a1072657065617465645f6669" . + "786564333218602003280742021000121c0a1072657065617465645f6669" . + "786564363418612003280642021000121d0a1172657065617465645f7366" . + "69786564333218622003280f42021000121d0a1172657065617465645f73" . + "6669786564363418632003281042021000121a0a0e72657065617465645f" . + "666c6f617418642003280242021000121b0a0f72657065617465645f646f" . + "75626c651865200328014202100012190a0d72657065617465645f626f6f" . + "6c1866200328084202100012280a0d72657065617465645f656e756d1867" . + "2003280e320d2e666f6f2e54657374456e756d420210002a1d0a08546573" . + "74456e756d12080a045a45524f100012070a034f4e451001620670726f74" . + "6f33" +)); + diff --git a/php/tests/test_include.pb.php b/php/tests/test_include.pb.php new file mode 100644 index 00000000..2c43cc41 --- /dev/null +++ b/php/tests/test_include.pb.php @@ -0,0 +1,36 @@ +a; + } + + public function setA($var) + { + GPBUtil::checkInt32($var); + $this->a = $var; + } + +} + +$pool = DescriptorPool::getGeneratedPool(); + +$pool->internalAddGeneratedFile(hex2bin( + "0a3b0a12746573745f696e636c7564652e70726f746f120362617222180a" . + "0b54657374496e636c75646512090a0161180120012805620670726f746f" . + "33" +)); + diff --git a/python/google/protobuf/descriptor.py b/python/google/protobuf/descriptor.py index 873af306..e1f2e3b7 100755 --- a/python/google/protobuf/descriptor.py +++ b/python/google/protobuf/descriptor.py @@ -171,13 +171,6 @@ class _NestedDescriptorBase(DescriptorBase): self._serialized_start = serialized_start self._serialized_end = serialized_end - def GetTopLevelContainingType(self): - """Returns the root if this is a nested type, or itself if its the root.""" - desc = self - while desc.containing_type is not None: - desc = desc.containing_type - return desc - def CopyToProto(self, proto): """Copies this to the matching proto in descriptor_pb2. @@ -497,7 +490,7 @@ class FieldDescriptor(DescriptorBase): def __new__(cls, name, full_name, index, number, type, cpp_type, label, default_value, message_type, enum_type, containing_type, is_extension, extension_scope, options=None, - has_default_value=True, containing_oneof=None): + has_default_value=True, containing_oneof=None, json_name=None): _message.Message._CheckCalledFromGeneratedFile() if is_extension: return _message.default_pool.FindExtensionByName(full_name) @@ -507,7 +500,7 @@ class FieldDescriptor(DescriptorBase): def __init__(self, name, full_name, index, number, type, cpp_type, label, default_value, message_type, enum_type, containing_type, is_extension, extension_scope, options=None, - has_default_value=True, containing_oneof=None): + has_default_value=True, containing_oneof=None, json_name=None): """The arguments are as described in the description of FieldDescriptor attributes above. @@ -519,6 +512,10 @@ class FieldDescriptor(DescriptorBase): self.name = name self.full_name = full_name self._camelcase_name = None + if json_name is None: + self.json_name = _ToJsonName(name) + else: + self.json_name = json_name self.index = index self.number = number self.type = type @@ -894,6 +891,31 @@ def _ToCamelCase(name): return ''.join(result) +def _OptionsOrNone(descriptor_proto): + """Returns the value of the field `options`, or None if it is not set.""" + if descriptor_proto.HasField('options'): + return descriptor_proto.options + else: + return None + + +def _ToJsonName(name): + """Converts name to Json name and returns it.""" + capitalize_next = False + result = [] + + for c in name: + if c == '_': + capitalize_next = True + elif capitalize_next: + result.append(c.upper()) + capitalize_next = False + else: + result += c + + return ''.join(result) + + def MakeDescriptor(desc_proto, package='', build_file_if_cpp=True, syntax=None): """Make a protobuf Descriptor given a DescriptorProto protobuf. @@ -970,6 +992,10 @@ def MakeDescriptor(desc_proto, package='', build_file_if_cpp=True, full_name = '.'.join(full_message_name + [field_proto.name]) enum_desc = None nested_desc = None + if field_proto.json_name: + json_name = field_proto.json_name + else: + json_name = None if field_proto.HasField('type_name'): type_name = field_proto.type_name full_type_name = '.'.join(full_message_name + @@ -984,10 +1010,11 @@ def MakeDescriptor(desc_proto, package='', build_file_if_cpp=True, field_proto.number, field_proto.type, FieldDescriptor.ProtoTypeToCppProtoType(field_proto.type), field_proto.label, None, nested_desc, enum_desc, None, False, None, - options=field_proto.options, has_default_value=False) + options=_OptionsOrNone(field_proto), has_default_value=False, + json_name=json_name) fields.append(field) desc_name = '.'.join(full_message_name) return Descriptor(desc_proto.name, desc_name, None, None, fields, list(nested_types.values()), list(enum_types.values()), [], - options=desc_proto.options) + options=_OptionsOrNone(desc_proto)) diff --git a/python/google/protobuf/descriptor_pool.py b/python/google/protobuf/descriptor_pool.py index 5c055ab9..5f43ee5f 100644 --- a/python/google/protobuf/descriptor_pool.py +++ b/python/google/protobuf/descriptor_pool.py @@ -62,7 +62,7 @@ from google.protobuf import descriptor_database from google.protobuf import text_encoding -_USE_C_DESCRIPTORS = descriptor._USE_C_DESCRIPTORS +_USE_C_DESCRIPTORS = descriptor._USE_C_DESCRIPTORS # pylint: disable=protected-access def _NormalizeFullyQualifiedName(name): @@ -80,6 +80,14 @@ def _NormalizeFullyQualifiedName(name): return name.lstrip('.') +def _OptionsOrNone(descriptor_proto): + """Returns the value of the field `options`, or None if it is not set.""" + if descriptor_proto.HasField('options'): + return descriptor_proto.options + else: + return None + + class DescriptorPool(object): """A collection of protobufs dynamically constructed by descriptor protos.""" @@ -326,78 +334,61 @@ class DescriptorPool(object): name=file_proto.name, package=file_proto.package, syntax=file_proto.syntax, - options=file_proto.options, + options=_OptionsOrNone(file_proto), serialized_pb=file_proto.SerializeToString(), dependencies=direct_deps, public_dependencies=public_deps) - if _USE_C_DESCRIPTORS: - # When using C++ descriptors, all objects defined in the file were added - # to the C++ database when the FileDescriptor was built above. - # Just add them to this descriptor pool. - def _AddMessageDescriptor(message_desc): - self._descriptors[message_desc.full_name] = message_desc - for nested in message_desc.nested_types: - _AddMessageDescriptor(nested) - for enum_type in message_desc.enum_types: - _AddEnumDescriptor(enum_type) - def _AddEnumDescriptor(enum_desc): - self._enum_descriptors[enum_desc.full_name] = enum_desc - for message_type in file_descriptor.message_types_by_name.values(): - _AddMessageDescriptor(message_type) - for enum_type in file_descriptor.enum_types_by_name.values(): - _AddEnumDescriptor(enum_type) + scope = {} + + # This loop extracts all the message and enum types from all the + # dependencies of the file_proto. This is necessary to create the + # scope of available message types when defining the passed in + # file proto. + for dependency in built_deps: + scope.update(self._ExtractSymbols( + dependency.message_types_by_name.values())) + scope.update((_PrefixWithDot(enum.full_name), enum) + for enum in dependency.enum_types_by_name.values()) + + for message_type in file_proto.message_type: + message_desc = self._ConvertMessageDescriptor( + message_type, file_proto.package, file_descriptor, scope, + file_proto.syntax) + file_descriptor.message_types_by_name[message_desc.name] = ( + message_desc) + + for enum_type in file_proto.enum_type: + file_descriptor.enum_types_by_name[enum_type.name] = ( + self._ConvertEnumDescriptor(enum_type, file_proto.package, + file_descriptor, None, scope)) + + for index, extension_proto in enumerate(file_proto.extension): + extension_desc = self._MakeFieldDescriptor( + extension_proto, file_proto.package, index, is_extension=True) + extension_desc.containing_type = self._GetTypeFromScope( + file_descriptor.package, extension_proto.extendee, scope) + self._SetFieldType(extension_proto, extension_desc, + file_descriptor.package, scope) + file_descriptor.extensions_by_name[extension_desc.name] = ( + extension_desc) + + for desc_proto in file_proto.message_type: + self._SetAllFieldTypes(file_proto.package, desc_proto, scope) + + if file_proto.package: + desc_proto_prefix = _PrefixWithDot(file_proto.package) else: - scope = {} - - # This loop extracts all the message and enum types from all the - # dependencies of the file_proto. This is necessary to create the - # scope of available message types when defining the passed in - # file proto. - for dependency in built_deps: - scope.update(self._ExtractSymbols( - dependency.message_types_by_name.values())) - scope.update((_PrefixWithDot(enum.full_name), enum) - for enum in dependency.enum_types_by_name.values()) - - for message_type in file_proto.message_type: - message_desc = self._ConvertMessageDescriptor( - message_type, file_proto.package, file_descriptor, scope, - file_proto.syntax) - file_descriptor.message_types_by_name[message_desc.name] = ( - message_desc) - - for enum_type in file_proto.enum_type: - file_descriptor.enum_types_by_name[enum_type.name] = ( - self._ConvertEnumDescriptor(enum_type, file_proto.package, - file_descriptor, None, scope)) - - for index, extension_proto in enumerate(file_proto.extension): - extension_desc = self._MakeFieldDescriptor( - extension_proto, file_proto.package, index, is_extension=True) - extension_desc.containing_type = self._GetTypeFromScope( - file_descriptor.package, extension_proto.extendee, scope) - self._SetFieldType(extension_proto, extension_desc, - file_descriptor.package, scope) - file_descriptor.extensions_by_name[extension_desc.name] = ( - extension_desc) - - for desc_proto in file_proto.message_type: - self._SetAllFieldTypes(file_proto.package, desc_proto, scope) - - if file_proto.package: - desc_proto_prefix = _PrefixWithDot(file_proto.package) - else: - desc_proto_prefix = '' + desc_proto_prefix = '' - for desc_proto in file_proto.message_type: - desc = self._GetTypeFromScope( - desc_proto_prefix, desc_proto.name, scope) - file_descriptor.message_types_by_name[desc_proto.name] = desc + for desc_proto in file_proto.message_type: + desc = self._GetTypeFromScope( + desc_proto_prefix, desc_proto.name, scope) + file_descriptor.message_types_by_name[desc_proto.name] = desc - for index, service_proto in enumerate(file_proto.service): - file_descriptor.services_by_name[service_proto.name] = ( - self._MakeServiceDescriptor(service_proto, index, scope, - file_proto.package, file_descriptor)) + for index, service_proto in enumerate(file_proto.service): + file_descriptor.services_by_name[service_proto.name] = ( + self._MakeServiceDescriptor(service_proto, index, scope, + file_proto.package, file_descriptor)) self.Add(file_proto) self._file_descriptors[file_proto.name] = file_descriptor @@ -413,6 +404,7 @@ class DescriptorPool(object): package: The package the proto should be located in. file_desc: The file containing this message. scope: Dict mapping short and full symbols to message and enum types. + syntax: string indicating syntax of the file ("proto2" or "proto3") Returns: The added descriptor. @@ -463,7 +455,7 @@ class DescriptorPool(object): nested_types=nested, enum_types=enums, extensions=extensions, - options=desc_proto.options, + options=_OptionsOrNone(desc_proto), is_extendable=is_extendable, extension_ranges=extension_ranges, file=file_desc, @@ -517,7 +509,7 @@ class DescriptorPool(object): file=file_desc, values=values, containing_type=containing_type, - options=enum_proto.options) + options=_OptionsOrNone(enum_proto)) scope['.%s' % enum_name] = desc self._enum_descriptors[enum_name] = desc return desc @@ -562,7 +554,7 @@ class DescriptorPool(object): default_value=None, is_extension=is_extension, extension_scope=None, - options=field_proto.options) + options=_OptionsOrNone(field_proto)) def _SetAllFieldTypes(self, package, desc_proto, scope): """Sets all the descriptor's fields's types. @@ -681,7 +673,7 @@ class DescriptorPool(object): name=value_proto.name, index=index, number=value_proto.number, - options=value_proto.options, + options=_OptionsOrNone(value_proto), type=None) def _MakeServiceDescriptor(self, service_proto, service_index, scope, @@ -711,7 +703,7 @@ class DescriptorPool(object): full_name=service_name, index=service_index, methods=methods, - options=service_proto.options, + options=_OptionsOrNone(service_proto), file=file_desc) return desc @@ -740,7 +732,7 @@ class DescriptorPool(object): containing_service=None, input_type=input_type, output_type=output_type, - options=method_proto.options) + options=_OptionsOrNone(method_proto)) def _ExtractSymbols(self, descriptors): """Pulls out all the symbols from descriptor protos. diff --git a/python/google/protobuf/internal/any_test.proto b/python/google/protobuf/internal/any_test.proto index cd641ca0..76a7ebd6 100644 --- a/python/google/protobuf/internal/any_test.proto +++ b/python/google/protobuf/internal/any_test.proto @@ -30,13 +30,21 @@ // Author: jieluo@google.com (Jie Luo) -syntax = "proto3"; +syntax = "proto2"; package google.protobuf.internal; import "google/protobuf/any.proto"; message TestAny { - google.protobuf.Any value = 1; - int32 int_value = 2; + optional google.protobuf.Any value = 1; + optional int32 int_value = 2; + extensions 10 to max; +} + +message TestAnyExtension1 { + extend TestAny { + optional TestAnyExtension1 extension1 = 98418603; + } + optional int32 i = 15; } diff --git a/python/google/protobuf/internal/containers.py b/python/google/protobuf/internal/containers.py index ce46d08c..de13018e 100755 --- a/python/google/protobuf/internal/containers.py +++ b/python/google/protobuf/internal/containers.py @@ -436,9 +436,11 @@ class ScalarMap(MutableMapping): """Simple, type-checked, dict-like container for holding repeated scalars.""" # Disallows assignment to other attributes. - __slots__ = ['_key_checker', '_value_checker', '_values', '_message_listener'] + __slots__ = ['_key_checker', '_value_checker', '_values', '_message_listener', + '_entry_descriptor'] - def __init__(self, message_listener, key_checker, value_checker): + def __init__(self, message_listener, key_checker, value_checker, + entry_descriptor): """ Args: message_listener: A MessageListener implementation. @@ -448,10 +450,12 @@ class ScalarMap(MutableMapping): inserted into this container. value_checker: A type_checkers.ValueChecker instance to run on values inserted into this container. + entry_descriptor: The MessageDescriptor of a map entry: key and value. """ self._message_listener = message_listener self._key_checker = key_checker self._value_checker = value_checker + self._entry_descriptor = entry_descriptor self._values = {} def __getitem__(self, key): @@ -513,6 +517,9 @@ class ScalarMap(MutableMapping): self._values.clear() self._message_listener.Modified() + def GetEntryClass(self): + return self._entry_descriptor._concrete_class + class MessageMap(MutableMapping): @@ -520,9 +527,10 @@ class MessageMap(MutableMapping): # Disallows assignment to other attributes. __slots__ = ['_key_checker', '_values', '_message_listener', - '_message_descriptor'] + '_message_descriptor', '_entry_descriptor'] - def __init__(self, message_listener, message_descriptor, key_checker): + def __init__(self, message_listener, message_descriptor, key_checker, + entry_descriptor): """ Args: message_listener: A MessageListener implementation. @@ -532,10 +540,12 @@ class MessageMap(MutableMapping): inserted into this container. value_checker: A type_checkers.ValueChecker instance to run on values inserted into this container. + entry_descriptor: The MessageDescriptor of a map entry: key and value. """ self._message_listener = message_listener self._message_descriptor = message_descriptor self._key_checker = key_checker + self._entry_descriptor = entry_descriptor self._values = {} def __getitem__(self, key): @@ -613,3 +623,6 @@ class MessageMap(MutableMapping): def clear(self): self._values.clear() self._message_listener.Modified() + + def GetEntryClass(self): + return self._entry_descriptor._concrete_class diff --git a/python/google/protobuf/internal/descriptor_pool_test.py b/python/google/protobuf/internal/descriptor_pool_test.py index 3c8c7935..d4de2d81 100644 --- a/python/google/protobuf/internal/descriptor_pool_test.py +++ b/python/google/protobuf/internal/descriptor_pool_test.py @@ -119,6 +119,7 @@ class DescriptorPoolTest(unittest.TestCase): self.assertEqual('google.protobuf.python.internal.Factory1Message', msg1.full_name) self.assertEqual(None, msg1.containing_type) + self.assertFalse(msg1.has_options) nested_msg1 = msg1.nested_types[0] self.assertEqual('NestedFactory1Message', nested_msg1.name) @@ -202,6 +203,7 @@ class DescriptorPoolTest(unittest.TestCase): self.assertIsInstance(enum1, descriptor.EnumDescriptor) self.assertEqual(0, enum1.values_by_name['FACTORY_1_VALUE_0'].number) self.assertEqual(1, enum1.values_by_name['FACTORY_1_VALUE_1'].number) + self.assertFalse(enum1.has_options) nested_enum1 = self.pool.FindEnumTypeByName( 'google.protobuf.python.internal.Factory1Message.NestedFactory1Enum') @@ -234,6 +236,8 @@ class DescriptorPoolTest(unittest.TestCase): 'google.protobuf.python.internal.Factory1Message.list_value') self.assertEqual(field.name, 'list_value') self.assertEqual(field.label, field.LABEL_REPEATED) + self.assertFalse(field.has_options) + with self.assertRaises(KeyError): self.pool.FindFieldByName('Does not exist') @@ -448,6 +452,7 @@ class EnumField(object): test.assertTrue(field_desc.has_default_value) test.assertEqual(enum_desc.values_by_name[self.default_value].number, field_desc.default_value) + test.assertFalse(enum_desc.values_by_name[self.default_value].has_options) test.assertEqual(msg_desc, field_desc.containing_type) test.assertEqual(enum_desc, field_desc.enum_type) diff --git a/python/google/protobuf/internal/descriptor_test.py b/python/google/protobuf/internal/descriptor_test.py index 623198c8..1f148ab9 100755 --- a/python/google/protobuf/internal/descriptor_test.py +++ b/python/google/protobuf/internal/descriptor_test.py @@ -766,6 +766,8 @@ class MakeDescriptorTest(unittest.TestCase): 'Foo2.Sub.bar_field') self.assertEqual(result.nested_types[0].fields[0].enum_type, result.nested_types[0].enum_types[0]) + self.assertFalse(result.has_options) + self.assertFalse(result.fields[0].has_options) def testMakeDescriptorWithUnsignedIntField(self): file_descriptor_proto = descriptor_pb2.FileDescriptorProto() @@ -818,6 +820,23 @@ class MakeDescriptorTest(unittest.TestCase): self.assertEqual(result.fields[index].camelcase_name, camelcase_names[index]) + def testJsonName(self): + descriptor_proto = descriptor_pb2.DescriptorProto() + descriptor_proto.name = 'TestJsonName' + names = ['field_name', 'fieldName', 'FieldName', + '_field_name', 'FIELD_NAME', 'json_name'] + json_names = ['fieldName', 'fieldName', 'FieldName', + 'FieldName', 'FIELDNAME', '@type'] + for index in range(len(names)): + field = descriptor_proto.field.add() + field.number = index + 1 + field.name = names[index] + field.json_name = '@type' + result = descriptor.MakeDescriptor(descriptor_proto) + for index in range(len(json_names)): + self.assertEqual(result.fields[index].json_name, + json_names[index]) + if __name__ == '__main__': unittest.main() diff --git a/python/google/protobuf/internal/generator_test.py b/python/google/protobuf/internal/generator_test.py index 83ea5f50..7f13f9da 100755 --- a/python/google/protobuf/internal/generator_test.py +++ b/python/google/protobuf/internal/generator_test.py @@ -227,7 +227,8 @@ class GeneratorTest(unittest.TestCase): [unittest_import_pb2.DESCRIPTOR]) self.assertEqual(unittest_import_pb2.DESCRIPTOR.dependencies, [unittest_import_public_pb2.DESCRIPTOR]) - + self.assertEqual(unittest_import_pb2.DESCRIPTOR.public_dependencies, + [unittest_import_public_pb2.DESCRIPTOR]) def testNoGenericServices(self): self.assertTrue(hasattr(unittest_no_generic_services_pb2, "TestMessage")) self.assertTrue(hasattr(unittest_no_generic_services_pb2, "FOO")) diff --git a/python/google/protobuf/internal/json_format_test.py b/python/google/protobuf/internal/json_format_test.py index a5ee8ace..5ed65622 100644 --- a/python/google/protobuf/internal/json_format_test.py +++ b/python/google/protobuf/internal/json_format_test.py @@ -205,6 +205,15 @@ class JsonFormatTest(JsonFormatBase): parsed_message = json_format_proto3_pb2.TestMessage() self.CheckParseBack(message, parsed_message) + def testIntegersRepresentedAsFloat(self): + message = json_format_proto3_pb2.TestMessage() + json_format.Parse('{"int32Value": -2.147483648e9}', message) + self.assertEqual(message.int32_value, -2147483648) + json_format.Parse('{"int32Value": 1e5}', message) + self.assertEqual(message.int32_value, 100000) + json_format.Parse('{"int32Value": 1.0}', message) + self.assertEqual(message.int32_value, 1) + def testMapFields(self): message = json_format_proto3_pb2.TestMap() message.bool_map[True] = 1 @@ -428,6 +437,9 @@ class JsonFormatTest(JsonFormatBase): ' "value": "hello",' ' "repeatedValue": [11.1, false, null, null]' '}')) + message.Clear() + json_format.Parse('{"value": null}', message) + self.assertEqual(message.value.WhichOneof('kind'), 'null_value') def testListValueMessage(self): message = json_format_proto3_pb2.TestListValue() @@ -600,6 +612,11 @@ class JsonFormatTest(JsonFormatBase): '}', parsed_message) self.assertEqual(message, parsed_message) + # Null and {} should have different behavior for sub message. + self.assertFalse(parsed_message.HasField('message_value')) + json_format.Parse('{"messageValue": {}}', parsed_message) + self.assertTrue(parsed_message.HasField('message_value')) + # Null is not allowed to be used as an element in repeated field. self.assertRaisesRegexp( json_format.ParseError, 'Failed to parse repeatedInt32Value field: ' @@ -621,15 +638,16 @@ class JsonFormatTest(JsonFormatBase): self.CheckError('', r'Failed to load JSON: (Expecting value)|(No JSON).') - def testParseBadEnumValue(self): - self.CheckError( - '{"enumValue": 1}', - 'Enum value must be a string literal with double quotes. ' - 'Type "proto3.EnumType" has no value named 1.') + def testParseEnumValue(self): + message = json_format_proto3_pb2.TestMessage() + text = '{"enumValue": 0}' + json_format.Parse(text, message) + text = '{"enumValue": 1}' + json_format.Parse(text, message) self.CheckError( '{"enumValue": "baz"}', - 'Enum value must be a string literal with double quotes. ' - 'Type "proto3.EnumType" has no value named baz.') + 'Failed to parse enumValue field: Invalid enum value baz ' + 'for enum type proto3.EnumType.') def testParseBadIdentifer(self): self.CheckError('{int32Value: 1}', @@ -672,12 +690,12 @@ class JsonFormatTest(JsonFormatBase): text = '{"int32Value": 0x12345}' self.assertRaises(json_format.ParseError, json_format.Parse, text, message) + self.CheckError('{"int32Value": 1.5}', + 'Failed to parse int32Value field: ' + 'Couldn\'t parse integer: 1.5.') self.CheckError('{"int32Value": 012345}', (r'Failed to load JSON: Expecting \'?,\'? delimiter: ' r'line 1.')) - self.CheckError('{"int32Value": 1.0}', - 'Failed to parse int32Value field: ' - 'Couldn\'t parse integer: 1.0.') self.CheckError('{"int32Value": " 1 "}', 'Failed to parse int32Value field: ' 'Couldn\'t parse integer: " 1 ".') @@ -687,9 +705,6 @@ class JsonFormatTest(JsonFormatBase): self.CheckError('{"int32Value": 12345678901234567890}', 'Failed to parse int32Value field: Value out of range: ' '12345678901234567890.') - self.CheckError('{"int32Value": 1e5}', - 'Failed to parse int32Value field: ' - 'Couldn\'t parse integer: 100000.0.') self.CheckError('{"uint32Value": -1}', 'Failed to parse uint32Value field: ' 'Value out of range: -1.') @@ -810,6 +825,43 @@ class JsonFormatTest(JsonFormatBase): r'"value": 1234}') json_format.Parse(text, message) + def testPreservingProtoFieldNames(self): + message = json_format_proto3_pb2.TestMessage() + message.int32_value = 12345 + self.assertEqual('{\n "int32Value": 12345\n}', + json_format.MessageToJson(message)) + self.assertEqual('{\n "int32_value": 12345\n}', + json_format.MessageToJson(message, False, True)) + + # Parsers accept both original proto field names and lowerCamelCase names. + message = json_format_proto3_pb2.TestMessage() + json_format.Parse('{"int32Value": 54321}', message) + self.assertEqual(54321, message.int32_value) + json_format.Parse('{"int32_value": 12345}', message) + self.assertEqual(12345, message.int32_value) + + def testParseDict(self): + expected = 12345 + js_dict = {'int32Value': expected} + message = json_format_proto3_pb2.TestMessage() + json_format.ParseDict(js_dict, message) + self.assertEqual(expected, message.int32_value) + + def testMessageToDict(self): + message = json_format_proto3_pb2.TestMessage() + message.int32_value = 12345 + expected = {'int32Value': 12345} + self.assertEqual(expected, + json_format.MessageToDict(message)) + + def testJsonName(self): + message = json_format_proto3_pb2.TestCustomJsonName() + message.value = 12345 + self.assertEqual('{\n "@value": 12345\n}', + json_format.MessageToJson(message)) + parsed_message = json_format_proto3_pb2.TestCustomJsonName() + self.CheckParseBack(message, parsed_message) + if __name__ == '__main__': unittest.main() diff --git a/python/google/protobuf/internal/message_test.py b/python/google/protobuf/internal/message_test.py index 1e95adf9..9986c0d9 100755 --- a/python/google/protobuf/internal/message_test.py +++ b/python/google/protobuf/internal/message_test.py @@ -67,6 +67,7 @@ from google.protobuf import text_format from google.protobuf.internal import api_implementation from google.protobuf.internal import packed_field_test_pb2 from google.protobuf.internal import test_util +from google.protobuf.internal import testing_refleaks from google.protobuf import message from google.protobuf.internal import _parameterized @@ -88,10 +89,13 @@ def IsNegInf(val): return isinf(val) and (val < 0) -@_parameterized.Parameters( - (unittest_pb2), - (unittest_proto3_arena_pb2)) -class MessageTest(unittest.TestCase): +BaseTestCase = testing_refleaks.BaseTestCase + + +@_parameterized.NamedParameters( + ('_proto2', unittest_pb2), + ('_proto3', unittest_proto3_arena_pb2)) +class MessageTest(BaseTestCase): def testBadUtf8String(self, message_module): if api_implementation.Type() != 'python': @@ -957,7 +961,7 @@ class MessageTest(unittest.TestCase): # Class to test proto2-only features (required, extensions, etc.) -class Proto2Test(unittest.TestCase): +class Proto2Test(BaseTestCase): def testFieldPresence(self): message = unittest_pb2.TestAllTypes() @@ -1113,6 +1117,7 @@ class Proto2Test(unittest.TestCase): optional_bytes=b'x', optionalgroup={'a': 400}, optional_nested_message={'bb': 500}, + optional_foreign_message={}, optional_nested_enum='BAZ', repeatedgroup=[{'a': 600}, {'a': 700}], @@ -1125,8 +1130,12 @@ class Proto2Test(unittest.TestCase): self.assertEqual(300.5, message.optional_float) self.assertEqual(b'x', message.optional_bytes) self.assertEqual(400, message.optionalgroup.a) - self.assertIsInstance(message.optional_nested_message, unittest_pb2.TestAllTypes.NestedMessage) + self.assertIsInstance(message.optional_nested_message, + unittest_pb2.TestAllTypes.NestedMessage) self.assertEqual(500, message.optional_nested_message.bb) + self.assertTrue(message.HasField('optional_foreign_message')) + self.assertEqual(message.optional_foreign_message, + unittest_pb2.ForeignMessage()) self.assertEqual(unittest_pb2.TestAllTypes.BAZ, message.optional_nested_enum) self.assertEqual(2, len(message.repeatedgroup)) @@ -1164,7 +1173,7 @@ class Proto2Test(unittest.TestCase): # Class to test proto3-only features/behavior (updated field presence & enums) -class Proto3Test(unittest.TestCase): +class Proto3Test(BaseTestCase): # Utility method for comparing equality with a map. def assertMapIterEquals(self, map_iter, dict_value): @@ -1720,7 +1729,7 @@ class Proto3Test(unittest.TestCase): -class ValidTypeNamesTest(unittest.TestCase): +class ValidTypeNamesTest(BaseTestCase): def assertImportFromName(self, msg, base_name): # Parse to extra 'some.name' as a string. @@ -1741,7 +1750,7 @@ class ValidTypeNamesTest(unittest.TestCase): self.assertImportFromName(pb.repeated_int32, 'Scalar') self.assertImportFromName(pb.repeated_nested_message, 'Composite') -class PackedFieldTest(unittest.TestCase): +class PackedFieldTest(BaseTestCase): def setMessage(self, message): message.repeated_int32.append(1) @@ -1800,10 +1809,14 @@ class PackedFieldTest(unittest.TestCase): @unittest.skipIf(api_implementation.Type() != 'cpp', 'explicit tests of the C++ implementation') -class OversizeProtosTest(unittest.TestCase): - - def setUp(self): - self.file_desc = """ +class OversizeProtosTest(BaseTestCase): + + @classmethod + def setUpClass(cls): + # At the moment, reference cycles between DescriptorPool and Message classes + # are not detected and these objects are never freed. + # To avoid errors with ReferenceLeakChecker, we create the class only once. + file_desc = """ name: "f/f.msg2" package: "f" message_type { @@ -1828,10 +1841,12 @@ class OversizeProtosTest(unittest.TestCase): """ pool = descriptor_pool.DescriptorPool() desc = descriptor_pb2.FileDescriptorProto() - text_format.Parse(self.file_desc, desc) + text_format.Parse(file_desc, desc) pool.Add(desc) - self.proto_cls = message_factory.MessageFactory(pool).GetPrototype( + cls.proto_cls = message_factory.MessageFactory(pool).GetPrototype( pool.FindMessageTypeByName('f.msg2')) + + def setUp(self): self.p = self.proto_cls() self.p.field.payload = 'c' * (1024 * 1024 * 64 + 1) self.p_serialized = self.p.SerializeToString() diff --git a/python/google/protobuf/internal/python_message.py b/python/google/protobuf/internal/python_message.py index c0d0ad45..60b4baad 100755 --- a/python/google/protobuf/internal/python_message.py +++ b/python/google/protobuf/internal/python_message.py @@ -380,13 +380,15 @@ def _GetInitializeDefaultForMap(field): if _IsMessageMapField(field): def MakeMessageMapDefault(message): return containers.MessageMap( - message._listener_for_children, value_field.message_type, key_checker) + message._listener_for_children, value_field.message_type, key_checker, + field.message_type) return MakeMessageMapDefault else: value_checker = type_checkers.GetTypeChecker(value_field) def MakePrimitiveMapDefault(message): return containers.ScalarMap( - message._listener_for_children, key_checker, value_checker) + message._listener_for_children, key_checker, value_checker, + field.message_type) return MakePrimitiveMapDefault def _DefaultValueConstructorForField(field): diff --git a/python/google/protobuf/internal/reflection_test.py b/python/google/protobuf/internal/reflection_test.py index 6f3b818a..dad79c37 100755 --- a/python/google/protobuf/internal/reflection_test.py +++ b/python/google/protobuf/internal/reflection_test.py @@ -60,9 +60,13 @@ from google.protobuf.internal import more_messages_pb2 from google.protobuf.internal import message_set_extensions_pb2 from google.protobuf.internal import wire_format from google.protobuf.internal import test_util +from google.protobuf.internal import testing_refleaks from google.protobuf.internal import decoder +BaseTestCase = testing_refleaks.BaseTestCase + + class _MiniDecoder(object): """Decodes a stream of values from a string. @@ -108,7 +112,7 @@ class _MiniDecoder(object): return self._pos == len(self._bytes) -class ReflectionTest(unittest.TestCase): +class ReflectionTest(BaseTestCase): def assertListsEqual(self, values, others): self.assertEqual(len(values), len(others)) @@ -1552,6 +1556,20 @@ class ReflectionTest(unittest.TestCase): 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 + sub_message = m.foo_message + # Accessing another message's field does not clear the first one + self.assertEqual(m.foo_lazy_message.qux_int, 0) + self.assertEqual(m.foo_message.qux_int, 5) + # But mutating another message in the oneof detaches the first one. + m.foo_lazy_message.qux_int = 6 + self.assertEqual(m.foo_message.qux_int, 0) + # The reference we got above was detached and is still valid. + self.assertEqual(sub_message.qux_int, 5) + sub_message.qux_int = 7 + def testOneOf(self): proto = unittest_pb2.TestAllTypes() proto.oneof_uint32 = 10 @@ -1810,7 +1828,7 @@ class ReflectionTest(unittest.TestCase): # into separate TestCase classes. -class TestAllTypesEqualityTest(unittest.TestCase): +class TestAllTypesEqualityTest(BaseTestCase): def setUp(self): self.first_proto = unittest_pb2.TestAllTypes() @@ -1826,7 +1844,7 @@ class TestAllTypesEqualityTest(unittest.TestCase): self.assertEqual(self.first_proto, self.second_proto) -class FullProtosEqualityTest(unittest.TestCase): +class FullProtosEqualityTest(BaseTestCase): """Equality tests using completely-full protos as a starting point.""" @@ -1912,7 +1930,7 @@ class FullProtosEqualityTest(unittest.TestCase): self.assertEqual(self.first_proto, self.second_proto) -class ExtensionEqualityTest(unittest.TestCase): +class ExtensionEqualityTest(BaseTestCase): def testExtensionEquality(self): first_proto = unittest_pb2.TestAllExtensions() @@ -1945,7 +1963,7 @@ class ExtensionEqualityTest(unittest.TestCase): self.assertEqual(first_proto, second_proto) -class MutualRecursionEqualityTest(unittest.TestCase): +class MutualRecursionEqualityTest(BaseTestCase): def testEqualityWithMutualRecursion(self): first_proto = unittest_pb2.TestMutualRecursionA() @@ -1957,7 +1975,7 @@ class MutualRecursionEqualityTest(unittest.TestCase): self.assertEqual(first_proto, second_proto) -class ByteSizeTest(unittest.TestCase): +class ByteSizeTest(BaseTestCase): def setUp(self): self.proto = unittest_pb2.TestAllTypes() @@ -2253,7 +2271,7 @@ class ByteSizeTest(unittest.TestCase): # * Handling of empty submessages (with and without "has" # bits set). -class SerializationTest(unittest.TestCase): +class SerializationTest(BaseTestCase): def testSerializeEmtpyMessage(self): first_proto = unittest_pb2.TestAllTypes() @@ -2814,7 +2832,7 @@ class SerializationTest(unittest.TestCase): self.assertEqual(3, proto.repeated_int32[2]) -class OptionsTest(unittest.TestCase): +class OptionsTest(BaseTestCase): def testMessageOptions(self): proto = message_set_extensions_pb2.TestMessageSet() @@ -2841,7 +2859,7 @@ class OptionsTest(unittest.TestCase): -class ClassAPITest(unittest.TestCase): +class ClassAPITest(BaseTestCase): @unittest.skipIf( api_implementation.Type() == 'cpp' and api_implementation.Version() == 2, @@ -2924,6 +2942,9 @@ class ClassAPITest(unittest.TestCase): text_format.Merge(file_descriptor_str, file_descriptor) return file_descriptor.SerializeToString() + @testing_refleaks.SkipReferenceLeakChecker('MakeDescriptor is not repeatable') + # This test can only run once; the second time, it raises errors about + # conflicting message descriptors. def testParsingFlatClassWithExplicitClassDeclaration(self): """Test that the generated class can parse a flat message.""" # TODO(xiaofeng): This test fails with cpp implemetnation in the call @@ -2948,6 +2969,7 @@ class ClassAPITest(unittest.TestCase): text_format.Merge(msg_str, msg) self.assertEqual(msg.flat, [0, 1, 2]) + @testing_refleaks.SkipReferenceLeakChecker('MakeDescriptor is not repeatable') def testParsingFlatClass(self): """Test that the generated class can parse a flat message.""" file_descriptor = descriptor_pb2.FileDescriptorProto() @@ -2963,6 +2985,7 @@ class ClassAPITest(unittest.TestCase): text_format.Merge(msg_str, msg) self.assertEqual(msg.flat, [0, 1, 2]) + @testing_refleaks.SkipReferenceLeakChecker('MakeDescriptor is not repeatable') def testParsingNestedClass(self): """Test that the generated class can parse a nested message.""" file_descriptor = descriptor_pb2.FileDescriptorProto() diff --git a/python/google/protobuf/internal/testing_refleaks.py b/python/google/protobuf/internal/testing_refleaks.py new file mode 100644 index 00000000..b2787901 --- /dev/null +++ b/python/google/protobuf/internal/testing_refleaks.py @@ -0,0 +1,124 @@ +# 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. + +"""A subclass of unittest.TestCase which checks for reference leaks. + +To use: +- Use testing_refleak.BaseTestCase instead of unittest.TestCase +- Configure and compile Python with --with-pydebug + +If sys.gettotalrefcount() is not available (because Python was built without +the Py_DEBUG option), then this module is a no-op and tests will run normally. +""" + +import copy_reg +import gc +import sys + +try: + import unittest2 as unittest #PY26 +except ImportError: + import unittest + + +class LocalTestResult(unittest.TestResult): + """A TestResult which forwards events to a parent object, except for Skips.""" + + def __init__(self, parent_result): + unittest.TestResult.__init__(self) + self.parent_result = parent_result + + def addError(self, test, error): + self.parent_result.addError(test, error) + + def addFailure(self, test, error): + self.parent_result.addFailure(test, error) + + def addSkip(self, test, reason): + pass + + +class ReferenceLeakCheckerTestCase(unittest.TestCase): + """A TestCase which runs tests multiple times, collecting reference counts.""" + + NB_RUNS = 3 + + def run(self, result=None): + # python_message.py registers all Message classes to some pickle global + # registry, which makes the classes immortal. + # We save a copy of this registry, and reset it before we could references. + self._saved_pickle_registry = copy_reg.dispatch_table.copy() + + # Run the test twice, to warm up the instance attributes. + super(ReferenceLeakCheckerTestCase, self).run(result=result) + super(ReferenceLeakCheckerTestCase, self).run(result=result) + + oldrefcount = 0 + local_result = LocalTestResult(result) + + refcount_deltas = [] + for _ in range(self.NB_RUNS): + oldrefcount = self._getRefcounts() + super(ReferenceLeakCheckerTestCase, self).run(result=local_result) + newrefcount = self._getRefcounts() + refcount_deltas.append(newrefcount - oldrefcount) + print refcount_deltas, self + + try: + self.assertEqual(refcount_deltas, [0] * self.NB_RUNS) + except Exception: # pylint: disable=broad-except + result.addError(self, sys.exc_info()) + + def _getRefcounts(self): + copy_reg.dispatch_table.clear() + copy_reg.dispatch_table.update(self._saved_pickle_registry) + # It is sometimes necessary to gc.collect() multiple times, to ensure + # that all objects can be collected. + gc.collect() + gc.collect() + gc.collect() + return sys.gettotalrefcount() + + +if hasattr(sys, 'gettotalrefcount'): + BaseTestCase = ReferenceLeakCheckerTestCase + SkipReferenceLeakChecker = unittest.skip + +else: + # When PyDEBUG is not enabled, run the tests normally. + BaseTestCase = unittest.TestCase + + def SkipReferenceLeakChecker(reason): + del reason # Don't skip, so don't need a reason. + def Same(func): + return func + return Same + + diff --git a/python/google/protobuf/internal/text_format_test.py b/python/google/protobuf/internal/text_format_test.py index 0e38e0e9..ab481ab4 100755 --- a/python/google/protobuf/internal/text_format_test.py +++ b/python/google/protobuf/internal/text_format_test.py @@ -52,6 +52,7 @@ from google.protobuf import unittest_mset_pb2 from google.protobuf import unittest_pb2 from google.protobuf import unittest_proto3_arena_pb2 from google.protobuf.internal import api_implementation +from google.protobuf.internal import any_test_pb2 as test_extend_any from google.protobuf.internal import test_util from google.protobuf.internal import message_set_extensions_pb2 from google.protobuf import descriptor_pool @@ -684,6 +685,21 @@ class Proto2Tests(TextFormatBase): self.assertEqual(23, message.message_set.Extensions[ext1].i) self.assertEqual('foo', message.message_set.Extensions[ext2].str) + def testExtensionInsideAnyMessage(self): + message = test_extend_any.TestAny() + text = ('value {\n' + ' [type.googleapis.com/google.protobuf.internal.TestAny] {\n' + ' [google.protobuf.internal.TestAnyExtension1.extension1] {\n' + ' i: 10\n' + ' }\n' + ' }\n' + '}\n') + text_format.Merge(text, message, descriptor_pool=descriptor_pool.Default()) + self.CompareToGoldenText( + text_format.MessageToString( + message, descriptor_pool=descriptor_pool.Default()), + text) + def testParseMessageByFieldNumber(self): message = unittest_pb2.TestAllTypes() text = ('34: 1\n' 'repeated_uint64: 2\n') @@ -1184,7 +1200,8 @@ class TokenizerTest(unittest.TestCase): 'ID7 : "aa\\"bb"\n\n\n\n ID8: {A:inf B:-inf C:true D:false}\n' 'ID9: 22 ID10: -111111111111111111 ID11: -22\n' 'ID12: 2222222222222222222 ID13: 1.23456f ID14: 1.2e+2f ' - 'false_bool: 0 true_BOOL:t \n true_bool1: 1 false_BOOL1:f ') + 'false_bool: 0 true_BOOL:t \n true_bool1: 1 false_BOOL1:f ' + 'False_bool: False True_bool: True') tokenizer = text_format.Tokenizer(text.splitlines()) methods = [(tokenizer.ConsumeIdentifier, 'identifier1'), ':', (tokenizer.ConsumeString, 'string1'), @@ -1228,7 +1245,11 @@ class TokenizerTest(unittest.TestCase): (tokenizer.ConsumeIdentifier, 'true_bool1'), ':', (tokenizer.ConsumeBool, True), (tokenizer.ConsumeIdentifier, 'false_BOOL1'), ':', - (tokenizer.ConsumeBool, False)] + (tokenizer.ConsumeBool, False), + (tokenizer.ConsumeIdentifier, 'False_bool'), ':', + (tokenizer.ConsumeBool, False), + (tokenizer.ConsumeIdentifier, 'True_bool'), ':', + (tokenizer.ConsumeBool, True)] i = 0 while not tokenizer.AtEnd(): diff --git a/python/google/protobuf/internal/unknown_fields_test.py b/python/google/protobuf/internal/unknown_fields_test.py index 84073f1c..d614eaa8 100755 --- a/python/google/protobuf/internal/unknown_fields_test.py +++ b/python/google/protobuf/internal/unknown_fields_test.py @@ -47,16 +47,20 @@ from google.protobuf.internal import encoder from google.protobuf.internal import message_set_extensions_pb2 from google.protobuf.internal import missing_enum_values_pb2 from google.protobuf.internal import test_util +from google.protobuf.internal import testing_refleaks from google.protobuf.internal import type_checkers +BaseTestCase = testing_refleaks.BaseTestCase + + def SkipIfCppImplementation(func): return unittest.skipIf( api_implementation.Type() == 'cpp' and api_implementation.Version() == 2, 'C++ implementation does not expose unknown fields to Python')(func) -class UnknownFieldsTest(unittest.TestCase): +class UnknownFieldsTest(BaseTestCase): def setUp(self): self.descriptor = unittest_pb2.TestAllTypes.DESCRIPTOR @@ -140,7 +144,7 @@ class UnknownFieldsTest(unittest.TestCase): b'', message.repeated_nested_message[0].SerializeToString()) -class UnknownFieldsAccessorsTest(unittest.TestCase): +class UnknownFieldsAccessorsTest(BaseTestCase): def setUp(self): self.descriptor = unittest_pb2.TestAllTypes.DESCRIPTOR @@ -149,21 +153,18 @@ class UnknownFieldsAccessorsTest(unittest.TestCase): self.all_fields_data = self.all_fields.SerializeToString() self.empty_message = unittest_pb2.TestEmptyMessage() self.empty_message.ParseFromString(self.all_fields_data) - if api_implementation.Type() != 'cpp': - # _unknown_fields is an implementation detail. - self.unknown_fields = self.empty_message._unknown_fields - # All the tests that use GetField() check an implementation detail of the - # Python implementation, which stores unknown fields as serialized strings. - # These tests are skipped by the C++ implementation: it's enough to check that - # the message is correctly serialized. + # GetUnknownField() checks a detail of the Python implementation, which stores + # unknown fields as serialized strings. It cannot be used by the C++ + # implementation: it's enough to check that the message is correctly + # serialized. - def GetField(self, name): + def GetUnknownField(self, name): field_descriptor = self.descriptor.fields_by_name[name] wire_type = type_checkers.FIELD_TYPE_TO_WIRE_TYPE[field_descriptor.type] field_tag = encoder.TagBytes(field_descriptor.number, wire_type) result_dict = {} - for tag_bytes, value in self.unknown_fields: + for tag_bytes, value in self.empty_message._unknown_fields: if tag_bytes == field_tag: decoder = unittest_pb2.TestAllTypes._decoders_by_tag[tag_bytes][0] decoder(value, 0, len(value), self.all_fields, result_dict) @@ -171,37 +172,37 @@ class UnknownFieldsAccessorsTest(unittest.TestCase): @SkipIfCppImplementation def testEnum(self): - value = self.GetField('optional_nested_enum') + value = self.GetUnknownField('optional_nested_enum') self.assertEqual(self.all_fields.optional_nested_enum, value) @SkipIfCppImplementation def testRepeatedEnum(self): - value = self.GetField('repeated_nested_enum') + value = self.GetUnknownField('repeated_nested_enum') self.assertEqual(self.all_fields.repeated_nested_enum, value) @SkipIfCppImplementation def testVarint(self): - value = self.GetField('optional_int32') + value = self.GetUnknownField('optional_int32') self.assertEqual(self.all_fields.optional_int32, value) @SkipIfCppImplementation def testFixed32(self): - value = self.GetField('optional_fixed32') + value = self.GetUnknownField('optional_fixed32') self.assertEqual(self.all_fields.optional_fixed32, value) @SkipIfCppImplementation def testFixed64(self): - value = self.GetField('optional_fixed64') + value = self.GetUnknownField('optional_fixed64') self.assertEqual(self.all_fields.optional_fixed64, value) @SkipIfCppImplementation def testLengthDelimited(self): - value = self.GetField('optional_string') + value = self.GetUnknownField('optional_string') self.assertEqual(self.all_fields.optional_string, value) @SkipIfCppImplementation def testGroup(self): - value = self.GetField('optionalgroup') + value = self.GetUnknownField('optionalgroup') self.assertEqual(self.all_fields.optionalgroup, value) def testCopyFrom(self): @@ -241,43 +242,41 @@ class UnknownFieldsAccessorsTest(unittest.TestCase): self.assertEqual(message.SerializeToString(), self.all_fields_data) -class UnknownEnumValuesTest(unittest.TestCase): +class UnknownEnumValuesTest(BaseTestCase): def setUp(self): self.descriptor = missing_enum_values_pb2.TestEnumValues.DESCRIPTOR self.message = missing_enum_values_pb2.TestEnumValues() + # TestEnumValues.ZERO = 0, but does not exist in the other NestedEnum. self.message.optional_nested_enum = ( - missing_enum_values_pb2.TestEnumValues.ZERO) + missing_enum_values_pb2.TestEnumValues.ZERO) self.message.repeated_nested_enum.extend([ - missing_enum_values_pb2.TestEnumValues.ZERO, - missing_enum_values_pb2.TestEnumValues.ONE, - ]) + missing_enum_values_pb2.TestEnumValues.ZERO, + missing_enum_values_pb2.TestEnumValues.ONE, + ]) self.message.packed_nested_enum.extend([ - missing_enum_values_pb2.TestEnumValues.ZERO, - missing_enum_values_pb2.TestEnumValues.ONE, - ]) + missing_enum_values_pb2.TestEnumValues.ZERO, + missing_enum_values_pb2.TestEnumValues.ONE, + ]) self.message_data = self.message.SerializeToString() self.missing_message = missing_enum_values_pb2.TestMissingEnumValues() self.missing_message.ParseFromString(self.message_data) - if api_implementation.Type() != 'cpp': - # _unknown_fields is an implementation detail. - self.unknown_fields = self.missing_message._unknown_fields - # All the tests that use GetField() check an implementation detail of the - # Python implementation, which stores unknown fields as serialized strings. - # These tests are skipped by the C++ implementation: it's enough to check that - # the message is correctly serialized. + # GetUnknownField() checks a detail of the Python implementation, which stores + # unknown fields as serialized strings. It cannot be used by the C++ + # implementation: it's enough to check that the message is correctly + # serialized. - def GetField(self, name): + def GetUnknownField(self, name): field_descriptor = self.descriptor.fields_by_name[name] wire_type = type_checkers.FIELD_TYPE_TO_WIRE_TYPE[field_descriptor.type] field_tag = encoder.TagBytes(field_descriptor.number, wire_type) result_dict = {} - for tag_bytes, value in self.unknown_fields: + for tag_bytes, value in self.missing_message._unknown_fields: if tag_bytes == field_tag: decoder = missing_enum_values_pb2.TestEnumValues._decoders_by_tag[ - tag_bytes][0] + tag_bytes][0] decoder(value, 0, len(value), self.message, result_dict) return result_dict[field_descriptor] @@ -294,21 +293,39 @@ class UnknownEnumValuesTest(unittest.TestCase): # default value. self.assertEqual(missing.optional_nested_enum, 0) - @SkipIfCppImplementation def testUnknownEnumValue(self): + if api_implementation.Type() == 'cpp': + # The CPP implementation of protos (wrongly) allows unknown enum values + # for proto2. + self.assertTrue(self.missing_message.HasField('optional_nested_enum')) + self.assertEqual(self.message.optional_nested_enum, + self.missing_message.optional_nested_enum) + else: + # On the other hand, the Python implementation considers unknown values + # as unknown fields. This is the correct behavior. + self.assertFalse(self.missing_message.HasField('optional_nested_enum')) + value = self.GetUnknownField('optional_nested_enum') + self.assertEqual(self.message.optional_nested_enum, value) + self.missing_message.ClearField('optional_nested_enum') self.assertFalse(self.missing_message.HasField('optional_nested_enum')) - value = self.GetField('optional_nested_enum') - self.assertEqual(self.message.optional_nested_enum, value) - @SkipIfCppImplementation def testUnknownRepeatedEnumValue(self): - value = self.GetField('repeated_nested_enum') - self.assertEqual(self.message.repeated_nested_enum, value) + if api_implementation.Type() == 'cpp': + # For repeated enums, both implementations agree. + self.assertEqual([], self.missing_message.repeated_nested_enum) + else: + self.assertEqual([], self.missing_message.repeated_nested_enum) + value = self.GetUnknownField('repeated_nested_enum') + self.assertEqual(self.message.repeated_nested_enum, value) - @SkipIfCppImplementation def testUnknownPackedEnumValue(self): - value = self.GetField('packed_nested_enum') - self.assertEqual(self.message.packed_nested_enum, value) + if api_implementation.Type() == 'cpp': + # For repeated enums, both implementations agree. + self.assertEqual([], self.missing_message.packed_nested_enum) + else: + self.assertEqual([], self.missing_message.packed_nested_enum) + value = self.GetUnknownField('packed_nested_enum') + self.assertEqual(self.message.packed_nested_enum, value) def testRoundTrip(self): new_message = missing_enum_values_pb2.TestEnumValues() diff --git a/python/google/protobuf/internal/well_known_types.py b/python/google/protobuf/internal/well_known_types.py index 7c5dffd0..d631abee 100644 --- a/python/google/protobuf/internal/well_known_types.py +++ b/python/google/protobuf/internal/well_known_types.py @@ -53,6 +53,7 @@ _NANOS_PER_MICROSECOND = 1000 _MILLIS_PER_SECOND = 1000 _MICROS_PER_SECOND = 1000000 _SECONDS_PER_DAY = 24 * 3600 +_DURATION_SECONDS_MAX = 315576000000 class Error(Exception): @@ -247,6 +248,7 @@ class Duration(object): represent the exact Duration value. For example: "1s", "1.010s", "1.000000100s", "-3.100s" """ + _CheckDurationValid(self.seconds, self.nanos) if self.seconds < 0 or self.nanos < 0: result = '-' seconds = - self.seconds + int((0 - self.nanos) // 1e9) @@ -286,14 +288,17 @@ class Duration(object): try: pos = value.find('.') if pos == -1: - self.seconds = int(value[:-1]) - self.nanos = 0 + seconds = int(value[:-1]) + nanos = 0 else: - self.seconds = int(value[:pos]) + seconds = int(value[:pos]) if value[0] == '-': - self.nanos = int(round(float('-0{0}'.format(value[pos: -1])) *1e9)) + nanos = int(round(float('-0{0}'.format(value[pos: -1])) *1e9)) else: - self.nanos = int(round(float('0{0}'.format(value[pos: -1])) *1e9)) + nanos = int(round(float('0{0}'.format(value[pos: -1])) *1e9)) + _CheckDurationValid(seconds, nanos) + self.seconds = seconds + self.nanos = nanos except ValueError: raise ParseError( 'Couldn\'t parse duration: {0}.'.format(value)) @@ -359,6 +364,17 @@ class Duration(object): self.nanos = nanos +def _CheckDurationValid(seconds, nanos): + if seconds < -_DURATION_SECONDS_MAX or seconds > _DURATION_SECONDS_MAX: + raise Error( + 'Duration is not valid: Seconds {0} must be in range ' + '[-315576000000, 315576000000].'.format(seconds)) + if nanos <= -_NANOS_PER_SECOND or nanos >= _NANOS_PER_SECOND: + raise Error( + 'Duration is not valid: Nanos {0} must be in range ' + '[-999999999, 999999999].'.format(nanos)) + + def _RoundTowardZero(value, divider): """Truncates the remainder part after division.""" # For some languanges, the sign of the remainder is implementation @@ -379,13 +395,16 @@ class FieldMask(object): def ToJsonString(self): """Converts FieldMask to string according to proto3 JSON spec.""" - return ','.join(self.paths) + camelcase_paths = [] + for path in self.paths: + camelcase_paths.append(_SnakeCaseToCamelCase(path)) + return ','.join(camelcase_paths) def FromJsonString(self, value): """Converts string to FieldMask according to proto3 JSON spec.""" self.Clear() for path in value.split(','): - self.paths.append(path) + self.paths.append(_CamelCaseToSnakeCase(path)) def IsValidForDescriptor(self, message_descriptor): """Checks whether the FieldMask is valid for Message Descriptor.""" @@ -472,6 +491,48 @@ def _CheckFieldMaskMessage(message): message_descriptor.full_name)) +def _SnakeCaseToCamelCase(path_name): + """Converts a path name from snake_case to camelCase.""" + result = [] + after_underscore = False + for c in path_name: + if c.isupper(): + raise Error('Fail to print FieldMask to Json string: Path name ' + '{0} must not contain uppercase letters.'.format(path_name)) + if after_underscore: + if c.islower(): + result.append(c.upper()) + after_underscore = False + else: + raise Error('Fail to print FieldMask to Json string: The ' + 'character after a "_" must be a lowercase letter ' + 'in path name {0}.'.format(path_name)) + elif c == '_': + after_underscore = True + else: + result += c + + if after_underscore: + raise Error('Fail to print FieldMask to Json string: Trailing "_" ' + 'in path name {0}.'.format(path_name)) + return ''.join(result) + + +def _CamelCaseToSnakeCase(path_name): + """Converts a field name from camelCase to snake_case.""" + result = [] + for c in path_name: + if c == '_': + raise ParseError('Fail to parse FieldMask: Path name ' + '{0} must not contain "_"s.'.format(path_name)) + if c.isupper(): + result += '_' + result += c.lower() + else: + result += c + return ''.join(result) + + class _FieldMaskTree(object): """Represents a FieldMask in a tree structure. diff --git a/python/google/protobuf/internal/well_known_types_test.py b/python/google/protobuf/internal/well_known_types_test.py index 2f32ac99..077f630f 100644 --- a/python/google/protobuf/internal/well_known_types_test.py +++ b/python/google/protobuf/internal/well_known_types_test.py @@ -303,6 +303,25 @@ class TimeUtilTest(TimeUtilTestBase): well_known_types.ParseError, 'Couldn\'t parse duration: 1...2s.', message.FromJsonString, '1...2s') + text = '-315576000001.000000000s' + self.assertRaisesRegexp( + well_known_types.Error, + r'Duration is not valid\: Seconds -315576000001 must be in range' + r' \[-315576000000\, 315576000000\].', + message.FromJsonString, text) + text = '315576000001.000000000s' + self.assertRaisesRegexp( + well_known_types.Error, + r'Duration is not valid\: Seconds 315576000001 must be in range' + r' \[-315576000000\, 315576000000\].', + message.FromJsonString, text) + message.seconds = -315576000001 + message.nanos = 0 + self.assertRaisesRegexp( + well_known_types.Error, + r'Duration is not valid\: Seconds -315576000001 must be in range' + r' \[-315576000000\, 315576000000\].', + message.ToJsonString) class FieldMaskTest(unittest.TestCase): @@ -322,6 +341,20 @@ class FieldMaskTest(unittest.TestCase): mask.FromJsonString('foo,bar') self.assertEqual(['foo', 'bar'], mask.paths) + # Test camel case + mask.Clear() + mask.paths.append('foo_bar') + self.assertEqual('fooBar', mask.ToJsonString()) + mask.paths.append('bar_quz') + self.assertEqual('fooBar,barQuz', mask.ToJsonString()) + + mask.FromJsonString('') + self.assertEqual('', mask.ToJsonString()) + mask.FromJsonString('fooBar') + self.assertEqual(['foo_bar'], mask.paths) + mask.FromJsonString('fooBar,barQuz') + self.assertEqual(['foo_bar', 'bar_quz'], mask.paths) + def testDescriptorToFieldMask(self): mask = field_mask_pb2.FieldMask() msg_descriptor = unittest_pb2.TestAllTypes.DESCRIPTOR @@ -502,17 +535,68 @@ class FieldMaskTest(unittest.TestCase): nested_src.payload.repeated_int32.append(1234) nested_dst.payload.repeated_int32.append(5678) # Repeated fields will be appended by default. - mask.FromJsonString('payload.repeated_int32') + mask.FromJsonString('payload.repeatedInt32') mask.MergeMessage(nested_src, nested_dst) self.assertEqual(2, len(nested_dst.payload.repeated_int32)) self.assertEqual(5678, nested_dst.payload.repeated_int32[0]) self.assertEqual(1234, nested_dst.payload.repeated_int32[1]) # Change the behavior to replace repeated fields. - mask.FromJsonString('payload.repeated_int32') + mask.FromJsonString('payload.repeatedInt32') mask.MergeMessage(nested_src, nested_dst, False, True) self.assertEqual(1, len(nested_dst.payload.repeated_int32)) self.assertEqual(1234, nested_dst.payload.repeated_int32[0]) + def testSnakeCaseToCamelCase(self): + self.assertEqual('fooBar', + well_known_types._SnakeCaseToCamelCase('foo_bar')) + self.assertEqual('FooBar', + well_known_types._SnakeCaseToCamelCase('_foo_bar')) + self.assertEqual('foo3Bar', + well_known_types._SnakeCaseToCamelCase('foo3_bar')) + + # No uppercase letter is allowed. + self.assertRaisesRegexp( + well_known_types.Error, + 'Fail to print FieldMask to Json string: Path name Foo must ' + 'not contain uppercase letters.', + well_known_types._SnakeCaseToCamelCase, + 'Foo') + # Any character after a "_" must be a lowercase letter. + # 1. "_" cannot be followed by another "_". + # 2. "_" cannot be followed by a digit. + # 3. "_" cannot appear as the last character. + self.assertRaisesRegexp( + well_known_types.Error, + 'Fail to print FieldMask to Json string: The character after a ' + '"_" must be a lowercase letter in path name foo__bar.', + well_known_types._SnakeCaseToCamelCase, + 'foo__bar') + self.assertRaisesRegexp( + well_known_types.Error, + 'Fail to print FieldMask to Json string: The character after a ' + '"_" must be a lowercase letter in path name foo_3bar.', + well_known_types._SnakeCaseToCamelCase, + 'foo_3bar') + self.assertRaisesRegexp( + well_known_types.Error, + 'Fail to print FieldMask to Json string: Trailing "_" in path ' + 'name foo_bar_.', + well_known_types._SnakeCaseToCamelCase, + 'foo_bar_') + + def testCamelCaseToSnakeCase(self): + self.assertEqual('foo_bar', + well_known_types._CamelCaseToSnakeCase('fooBar')) + self.assertEqual('_foo_bar', + well_known_types._CamelCaseToSnakeCase('FooBar')) + self.assertEqual('foo3_bar', + well_known_types._CamelCaseToSnakeCase('foo3Bar')) + self.assertRaisesRegexp( + well_known_types.ParseError, + 'Fail to parse FieldMask: Path name foo_bar must not contain "_"s.', + well_known_types._CamelCaseToSnakeCase, + 'foo_bar') + class StructTest(unittest.TestCase): @@ -529,52 +613,52 @@ class StructTest(unittest.TestCase): struct_list.add_struct()['subkey2'] = 9 self.assertTrue(isinstance(struct, well_known_types.Struct)) - self.assertEquals(5, struct['key1']) - self.assertEquals('abc', struct['key2']) + self.assertEqual(5, struct['key1']) + self.assertEqual('abc', struct['key2']) self.assertIs(True, struct['key3']) - self.assertEquals(11, struct['key4']['subkey']) + self.assertEqual(11, struct['key4']['subkey']) inner_struct = struct_class() inner_struct['subkey2'] = 9 - self.assertEquals([6, 'seven', True, False, None, inner_struct], - list(struct['key5'].items())) + self.assertEqual([6, 'seven', True, False, None, inner_struct], + list(struct['key5'].items())) serialized = struct.SerializeToString() struct2 = struct_pb2.Struct() struct2.ParseFromString(serialized) - self.assertEquals(struct, struct2) + self.assertEqual(struct, struct2) self.assertTrue(isinstance(struct2, well_known_types.Struct)) - self.assertEquals(5, struct2['key1']) - self.assertEquals('abc', struct2['key2']) + self.assertEqual(5, struct2['key1']) + self.assertEqual('abc', struct2['key2']) self.assertIs(True, struct2['key3']) - self.assertEquals(11, struct2['key4']['subkey']) - self.assertEquals([6, 'seven', True, False, None, inner_struct], - list(struct2['key5'].items())) + self.assertEqual(11, struct2['key4']['subkey']) + self.assertEqual([6, 'seven', True, False, None, inner_struct], + list(struct2['key5'].items())) struct_list = struct2['key5'] - self.assertEquals(6, struct_list[0]) - self.assertEquals('seven', struct_list[1]) - self.assertEquals(True, struct_list[2]) - self.assertEquals(False, struct_list[3]) - self.assertEquals(None, struct_list[4]) - self.assertEquals(inner_struct, struct_list[5]) + self.assertEqual(6, struct_list[0]) + self.assertEqual('seven', struct_list[1]) + self.assertEqual(True, struct_list[2]) + self.assertEqual(False, struct_list[3]) + self.assertEqual(None, struct_list[4]) + self.assertEqual(inner_struct, struct_list[5]) struct_list[1] = 7 - self.assertEquals(7, struct_list[1]) + self.assertEqual(7, struct_list[1]) struct_list.add_list().extend([1, 'two', True, False, None]) - self.assertEquals([1, 'two', True, False, None], - list(struct_list[6].items())) + self.assertEqual([1, 'two', True, False, None], + list(struct_list[6].items())) text_serialized = str(struct) struct3 = struct_pb2.Struct() text_format.Merge(text_serialized, struct3) - self.assertEquals(struct, struct3) + self.assertEqual(struct, struct3) struct.get_or_create_struct('key3')['replace'] = 12 - self.assertEquals(12, struct['key3']['replace']) + self.assertEqual(12, struct['key3']['replace']) class AnyTest(unittest.TestCase): diff --git a/python/google/protobuf/json_format.py b/python/google/protobuf/json_format.py index edc0cb50..c42371d0 100644 --- a/python/google/protobuf/json_format.py +++ b/python/google/protobuf/json_format.py @@ -86,7 +86,9 @@ class ParseError(Error): """Thrown in case of parsing error.""" -def MessageToJson(message, including_default_value_fields=False): +def MessageToJson(message, + including_default_value_fields=False, + preserving_proto_field_name=False): """Converts protobuf message to JSON format. Args: @@ -95,14 +97,42 @@ def MessageToJson(message, including_default_value_fields=False): repeated fields, and map fields will always be serialized. If False, only serialize non-empty fields. Singular message fields and oneof fields are not affected by this option. + preserving_proto_field_name: If True, use the original proto field + names as defined in the .proto file. If False, convert the field + names to lowerCamelCase. Returns: A string containing the JSON formatted protocol buffer message. """ - printer = _Printer(including_default_value_fields) + printer = _Printer(including_default_value_fields, + preserving_proto_field_name) return printer.ToJsonString(message) +def MessageToDict(message, + including_default_value_fields=False, + preserving_proto_field_name=False): + """Converts protobuf message to a JSON dictionary. + + Args: + message: The protocol buffers message instance to serialize. + including_default_value_fields: If True, singular primitive fields, + repeated fields, and map fields will always be serialized. If + False, only serialize non-empty fields. Singular message fields + and oneof fields are not affected by this option. + preserving_proto_field_name: If True, use the original proto field + names as defined in the .proto file. If False, convert the field + names to lowerCamelCase. + + Returns: + A dict representation of the JSON formatted protocol buffer message. + """ + printer = _Printer(including_default_value_fields, + preserving_proto_field_name) + # pylint: disable=protected-access + return printer._MessageToJsonObject(message) + + def _IsMapEntry(field): return (field.type == descriptor.FieldDescriptor.TYPE_MESSAGE and field.message_type.has_options and @@ -113,8 +143,10 @@ class _Printer(object): """JSON format printer for protocol message.""" def __init__(self, - including_default_value_fields=False): + including_default_value_fields=False, + preserving_proto_field_name=False): self.including_default_value_fields = including_default_value_fields + self.preserving_proto_field_name = preserving_proto_field_name def ToJsonString(self, message): js = self._MessageToJsonObject(message) @@ -137,7 +169,10 @@ class _Printer(object): try: for field, value in fields: - name = field.camelcase_name + if self.preserving_proto_field_name: + name = field.name + else: + name = field.json_name if _IsMapEntry(field): # Convert a map field. v_field = field.message_type.fields_by_name['value'] @@ -169,7 +204,10 @@ class _Printer(object): field.cpp_type == descriptor.FieldDescriptor.CPPTYPE_MESSAGE) or field.containing_oneof): continue - name = field.camelcase_name + if self.preserving_proto_field_name: + name = field.name + else: + name = field.json_name if name in js: # Skip the field which has been serailized already. continue @@ -328,8 +366,22 @@ def Parse(text, message, ignore_unknown_fields=False): js = json.loads(text, object_pairs_hook=_DuplicateChecker) except ValueError as e: raise ParseError('Failed to load JSON: {0}.'.format(str(e))) + return ParseDict(js, message, ignore_unknown_fields) + + +def ParseDict(js_dict, message, ignore_unknown_fields=False): + """Parses a JSON dictionary representation into a message. + + Args: + js_dict: Dict representation of a JSON message. + message: A protocol buffer message to merge into. + ignore_unknown_fields: If True, do not raise errors for unknown fields. + + Returns: + The same message passed as argument. + """ parser = _Parser(ignore_unknown_fields) - parser.ConvertMessage(js, message) + parser.ConvertMessage(js_dict, message) return message @@ -374,9 +426,13 @@ class _Parser(object): """ names = [] message_descriptor = message.DESCRIPTOR + fields_by_json_name = dict((f.json_name, f) + for f in message_descriptor.fields) for name in js: try: - field = message_descriptor.fields_by_camelcase_name.get(name, None) + field = fields_by_json_name.get(name, None) + if not field: + field = message_descriptor.fields_by_name.get(name, None) if not field: if self.ignore_unknown_fields: continue @@ -399,7 +455,12 @@ class _Parser(object): value = js[name] if value is None: - message.ClearField(field.name) + if (field.cpp_type == descriptor.FieldDescriptor.CPPTYPE_MESSAGE + and field.message_type.full_name == 'google.protobuf.Value'): + sub_message = getattr(message, field.name) + sub_message.null_value = 0 + else: + message.ClearField(field.name) continue # Parse field value. @@ -431,6 +492,7 @@ class _Parser(object): _ConvertScalarFieldValue(item, field)) elif field.cpp_type == descriptor.FieldDescriptor.CPPTYPE_MESSAGE: sub_message = getattr(message, field.name) + sub_message.SetInParent() self.ConvertMessage(value, sub_message) else: setattr(message, field.name, _ConvertScalarFieldValue(value, field)) @@ -574,10 +636,15 @@ def _ConvertScalarFieldValue(value, field, require_str=False): # Convert an enum value. enum_value = field.enum_type.values_by_name.get(value, None) if enum_value is None: - raise ParseError( - 'Enum value must be a string literal with double quotes. ' - 'Type "{0}" has no value named {1}.'.format( - field.enum_type.full_name, value)) + try: + number = int(value) + enum_value = field.enum_type.values_by_number.get(number, None) + except ValueError: + raise ParseError('Invalid enum value {0} for enum type {1}.'.format( + value, field.enum_type.full_name)) + if enum_value is None: + raise ParseError('Invalid enum value {0} for enum type {1}.'.format( + value, field.enum_type.full_name)) return enum_value.number @@ -593,7 +660,7 @@ def _ConvertInteger(value): Raises: ParseError: If an integer couldn't be consumed. """ - if isinstance(value, float): + if isinstance(value, float) and not value.is_integer(): raise ParseError('Couldn\'t parse integer: {0}.'.format(value)) if isinstance(value, six.text_type) and value.find(' ') != -1: diff --git a/python/google/protobuf/message.py b/python/google/protobuf/message.py index 606f735f..aab250e4 100755 --- a/python/google/protobuf/message.py +++ b/python/google/protobuf/message.py @@ -225,10 +225,11 @@ class Message(object): # """ def ListFields(self): """Returns a list of (FieldDescriptor, value) tuples for all - fields in the message which are not empty. A singular field is non-empty - if HasField() would return true, and a repeated field is non-empty if - it contains at least one element. The fields are ordered by field - number""" + fields in the message which are not empty. A message field is + non-empty if HasField() would return true. A singular primitive field + is non-empty if HasField() would return true in proto2 or it is non zero + in proto3. A repeated field is non-empty if it contains at least one + element. The fields are ordered by field number""" raise NotImplementedError def HasField(self, field_name): diff --git a/python/google/protobuf/message_factory.py b/python/google/protobuf/message_factory.py index 1b059d13..8ab1c513 100644 --- a/python/google/protobuf/message_factory.py +++ b/python/google/protobuf/message_factory.py @@ -103,13 +103,8 @@ class MessageFactory(object): result = {} for file_name in files: file_desc = self.pool.FindFileByName(file_name) - for name, msg in file_desc.message_types_by_name.items(): - if file_desc.package: - full_name = '.'.join([file_desc.package, name]) - else: - full_name = msg.name - result[full_name] = self.GetPrototype( - self.pool.FindMessageTypeByName(full_name)) + for desc in file_desc.message_types_by_name.values(): + result[desc.full_name] = self.GetPrototype(desc) # While the extension FieldDescriptors are created by the descriptor pool, # the python classes created in the factory need them to be registered @@ -120,7 +115,7 @@ class MessageFactory(object): # ignore the registration if the original was the same, or raise # an error if they were different. - for name, extension in file_desc.extensions_by_name.items(): + for extension in file_desc.extensions_by_name.values(): if extension.containing_type.full_name not in self._classes: self.GetPrototype(extension.containing_type) extended_class = self._classes[extension.containing_type.full_name] diff --git a/python/google/protobuf/pyext/descriptor.cc b/python/google/protobuf/pyext/descriptor.cc index e6ef5ef5..924ae0b9 100644 --- a/python/google/protobuf/pyext/descriptor.cc +++ b/python/google/protobuf/pyext/descriptor.cc @@ -41,6 +41,7 @@ #include #include #include +#include #include #if PY_MAJOR_VERSION >= 3 @@ -204,8 +205,9 @@ static PyObject* GetOrBuildOptions(const DescriptorClass *descriptor) { // read-only instance. const Message& options(descriptor->options()); const Descriptor *message_type = options.GetDescriptor(); - CMessageClass* message_class( - cdescriptor_pool::GetMessageClass(pool, message_type)); + PyMessageFactory* message_factory = pool->py_message_factory; + CMessageClass* message_class = message_factory::GetMessageClass( + message_factory, message_type); if (message_class == NULL) { // The Options message was not found in the current DescriptorPool. // This means that the pool cannot contain any extensions to the Options @@ -213,7 +215,9 @@ static PyObject* GetOrBuildOptions(const DescriptorClass *descriptor) { // the chances of successfully parsing the options. PyErr_Clear(); pool = GetDefaultDescriptorPool(); - message_class = cdescriptor_pool::GetMessageClass(pool, message_type); + message_factory = pool->py_message_factory; + message_class = message_factory::GetMessageClass( + message_factory, message_type); } if (message_class == NULL) { PyErr_Format(PyExc_TypeError, "Could not retrieve class for Options: %s", @@ -243,7 +247,7 @@ static PyObject* GetOrBuildOptions(const DescriptorClass *descriptor) { options.SerializeToString(&serialized); io::CodedInputStream input( reinterpret_cast(serialized.c_str()), serialized.size()); - input.SetExtensionRegistry(pool->pool, pool->message_factory); + input.SetExtensionRegistry(pool->pool, message_factory->message_factory); bool success = cmsg->message->MergePartialFromCodedStream(&input); if (!success) { PyErr_Format(PyExc_ValueError, "Error parsing Options message"); @@ -439,8 +443,9 @@ static PyObject* GetConcreteClass(PyBaseDescriptor* self, void *closure) { // which contains this descriptor. // This might not be the one you expect! For example the returned object does // not know about extensions defined in a custom pool. - CMessageClass* concrete_class(cdescriptor_pool::GetMessageClass( - GetDescriptorPool_FromPool(_GetDescriptor(self)->file()->pool()), + CMessageClass* concrete_class(message_factory::GetMessageClass( + GetDescriptorPool_FromPool( + _GetDescriptor(self)->file()->pool())->py_message_factory, _GetDescriptor(self))); Py_XINCREF(concrete_class); return concrete_class->AsPyObject(); @@ -699,6 +704,10 @@ static PyObject* GetCamelcaseName(PyBaseDescriptor* self, void *closure) { return PyString_FromCppString(_GetDescriptor(self)->camelcase_name()); } +static PyObject* GetJsonName(PyBaseDescriptor* self, void *closure) { + return PyString_FromCppString(_GetDescriptor(self)->json_name()); +} + static PyObject* GetType(PyBaseDescriptor *self, void *closure) { return PyInt_FromLong(_GetDescriptor(self)->type()); } @@ -888,6 +897,7 @@ static PyGetSetDef Getters[] = { { "full_name", (getter)GetFullName, NULL, "Full name"}, { "name", (getter)GetName, NULL, "Unqualified name"}, { "camelcase_name", (getter)GetCamelcaseName, NULL, "Camelcase name"}, + { "json_name", (getter)GetJsonName, NULL, "Json name"}, { "type", (getter)GetType, NULL, "C++ Type"}, { "cpp_type", (getter)GetCppType, NULL, "C++ Type"}, { "label", (getter)GetLabel, NULL, "Label"}, diff --git a/python/google/protobuf/pyext/descriptor_pool.cc b/python/google/protobuf/pyext/descriptor_pool.cc index cfd98690..a42e5431 100644 --- a/python/google/protobuf/pyext/descriptor_pool.cc +++ b/python/google/protobuf/pyext/descriptor_pool.cc @@ -33,11 +33,11 @@ #include #include -#include #include #include #include #include +#include #include #if PY_MAJOR_VERSION >= 3 @@ -73,18 +73,16 @@ static PyDescriptorPool* _CreateDescriptorPool() { cpool->underlay = NULL; cpool->database = NULL; - DynamicMessageFactory* message_factory = new DynamicMessageFactory(); - // This option might be the default some day. - message_factory->SetDelegateToGeneratedFactory(true); - cpool->message_factory = message_factory; - - // TODO(amauryfa): Rewrite the SymbolDatabase in C so that it uses the same - // storage. - cpool->classes_by_descriptor = - new PyDescriptorPool::ClassesByMessageMap(); cpool->descriptor_options = new hash_map(); + cpool->py_message_factory = message_factory::NewMessageFactory( + &PyMessageFactory_Type, cpool); + if (cpool->py_message_factory == NULL) { + Py_DECREF(cpool); + return NULL; + } + return cpool; } @@ -151,20 +149,14 @@ static PyObject* New(PyTypeObject* type, } static void Dealloc(PyDescriptorPool* self) { - typedef PyDescriptorPool::ClassesByMessageMap::iterator iterator; descriptor_pool_map.erase(self->pool); - for (iterator it = self->classes_by_descriptor->begin(); - it != self->classes_by_descriptor->end(); ++it) { - Py_DECREF(it->second); - } - delete self->classes_by_descriptor; + Py_CLEAR(self->py_message_factory); for (hash_map::iterator it = self->descriptor_options->begin(); it != self->descriptor_options->end(); ++it) { Py_DECREF(it->second); } delete self->descriptor_options; - delete self->message_factory; delete self->database; delete self->pool; Py_TYPE(self)->tp_free(reinterpret_cast(self)); @@ -188,35 +180,8 @@ PyObject* FindMessageByName(PyDescriptorPool* self, PyObject* arg) { return PyMessageDescriptor_FromDescriptor(message_descriptor); } -// Add a message class to our database. -int RegisterMessageClass(PyDescriptorPool* self, - const Descriptor* message_descriptor, - CMessageClass* message_class) { - Py_INCREF(message_class); - typedef PyDescriptorPool::ClassesByMessageMap::iterator iterator; - std::pair ret = self->classes_by_descriptor->insert( - std::make_pair(message_descriptor, message_class)); - if (!ret.second) { - // Update case: DECREF the previous value. - Py_DECREF(ret.first->second); - ret.first->second = message_class; - } - return 0; -} -// Retrieve the message class added to our database. -CMessageClass* GetMessageClass(PyDescriptorPool* self, - const Descriptor* message_descriptor) { - typedef PyDescriptorPool::ClassesByMessageMap::iterator iterator; - iterator ret = self->classes_by_descriptor->find(message_descriptor); - if (ret == self->classes_by_descriptor->end()) { - PyErr_Format(PyExc_TypeError, "No message class registered for '%s'", - message_descriptor->full_name().c_str()); - return NULL; - } else { - return ret->second; - } -} + PyObject* FindFileByName(PyDescriptorPool* self, PyObject* arg) { Py_ssize_t name_size; @@ -228,11 +193,9 @@ PyObject* FindFileByName(PyDescriptorPool* self, PyObject* arg) { const FileDescriptor* file_descriptor = self->pool->FindFileByName(string(name, name_size)); if (file_descriptor == NULL) { - PyErr_Format(PyExc_KeyError, "Couldn't find file %.200s", - name); + PyErr_Format(PyExc_KeyError, "Couldn't find file %.200s", name); return NULL; } - return PyFileDescriptor_FromDescriptor(file_descriptor); } diff --git a/python/google/protobuf/pyext/descriptor_pool.h b/python/google/protobuf/pyext/descriptor_pool.h index 2a42c112..8de6c60b 100644 --- a/python/google/protobuf/pyext/descriptor_pool.h +++ b/python/google/protobuf/pyext/descriptor_pool.h @@ -38,10 +38,10 @@ namespace google { namespace protobuf { -class MessageFactory; - namespace python { +class PyMessageFactory; + // The (meta) type of all Messages classes. struct CMessageClass; @@ -69,20 +69,10 @@ typedef struct PyDescriptorPool { // This pointer is owned. const DescriptorDatabase* database; - // DynamicMessageFactory used to create C++ instances of messages. - // This object cache the descriptors that were used, so the DescriptorPool - // needs to get rid of it before it can delete itself. - // - // Note: A C++ MessageFactory is different from the Python MessageFactory. - // The C++ one creates messages, when the Python one creates classes. - MessageFactory* message_factory; - - // Make our own mapping to retrieve Python classes from C++ descriptors. - // - // Descriptor pointers stored here are owned by the DescriptorPool above. - // Python references to classes are owned by this PyDescriptorPool. - typedef hash_map ClassesByMessageMap; - ClassesByMessageMap* classes_by_descriptor; + // The preferred MessageFactory to be used by descriptors. + // TODO(amauryfa): Don't create the Factory from the DescriptorPool, but + // use the one passed while creating message classes. And remove this member. + PyMessageFactory* py_message_factory; // Cache the options for any kind of descriptor. // Descriptor pointers are owned by the DescriptorPool above. @@ -100,19 +90,6 @@ namespace cdescriptor_pool { const Descriptor* FindMessageTypeByName(PyDescriptorPool* self, const string& name); -// Registers a new Python class for the given message descriptor. -// On error, returns -1 with a Python exception set. -int RegisterMessageClass(PyDescriptorPool* self, - const Descriptor* message_descriptor, - CMessageClass* message_class); - -// Retrieves the Python class registered with the given message descriptor. -// -// Returns a *borrowed* reference if found, otherwise returns NULL with an -// exception set. -CMessageClass* GetMessageClass(PyDescriptorPool* self, - const Descriptor* message_descriptor); - // The functions below are also exposed as methods of the DescriptorPool type. // Looks up a message by name. Returns a PyMessageDescriptor corresponding to diff --git a/python/google/protobuf/pyext/extension_dict.cc b/python/google/protobuf/pyext/extension_dict.cc index 21bbb8c2..dbb7bca0 100644 --- a/python/google/protobuf/pyext/extension_dict.cc +++ b/python/google/protobuf/pyext/extension_dict.cc @@ -39,8 +39,8 @@ #include #include #include -#include #include +#include #include #include #include @@ -60,35 +60,6 @@ PyObject* len(ExtensionDict* self) { #endif } -// TODO(tibell): Use VisitCompositeField. -int ReleaseExtension(ExtensionDict* self, - PyObject* extension, - const FieldDescriptor* descriptor) { - if (descriptor->label() == FieldDescriptor::LABEL_REPEATED) { - if (descriptor->cpp_type() == FieldDescriptor::CPPTYPE_MESSAGE) { - if (repeated_composite_container::Release( - reinterpret_cast( - extension)) < 0) { - return -1; - } - } else { - if (repeated_scalar_container::Release( - reinterpret_cast( - extension)) < 0) { - return -1; - } - } - } else if (descriptor->cpp_type() == FieldDescriptor::CPPTYPE_MESSAGE) { - if (cmessage::ReleaseSubMessage( - self->parent, descriptor, - reinterpret_cast(extension)) < 0) { - return -1; - } - } - - return 0; -} - PyObject* subscript(ExtensionDict* self, PyObject* key) { const FieldDescriptor* descriptor = cmessage::GetExtensionDescriptor(key); if (descriptor == NULL) { @@ -130,8 +101,8 @@ PyObject* subscript(ExtensionDict* self, PyObject* key) { if (descriptor->label() == FieldDescriptor::LABEL_REPEATED) { if (descriptor->cpp_type() == FieldDescriptor::CPPTYPE_MESSAGE) { - CMessageClass* message_class = cdescriptor_pool::GetMessageClass( - cmessage::GetDescriptorPoolForMessage(self->parent), + CMessageClass* message_class = message_factory::GetMessageClass( + cmessage::GetFactoryForMessage(self->parent), descriptor->message_type()); if (message_class == NULL) { return NULL; @@ -183,47 +154,6 @@ int ass_subscript(ExtensionDict* self, PyObject* key, PyObject* value) { return 0; } -PyObject* ClearExtension(ExtensionDict* self, PyObject* extension) { - const FieldDescriptor* descriptor = - cmessage::GetExtensionDescriptor(extension); - if (descriptor == NULL) { - return NULL; - } - PyObject* value = PyDict_GetItem(self->values, extension); - if (self->parent) { - if (value != NULL) { - if (ReleaseExtension(self, value, descriptor) < 0) { - return NULL; - } - } - if (ScopedPyObjectPtr(cmessage::ClearFieldByDescriptor( - self->parent, descriptor)) == NULL) { - return NULL; - } - } - if (PyDict_DelItem(self->values, extension) < 0) { - PyErr_Clear(); - } - Py_RETURN_NONE; -} - -PyObject* HasExtension(ExtensionDict* self, PyObject* extension) { - const FieldDescriptor* descriptor = - cmessage::GetExtensionDescriptor(extension); - if (descriptor == NULL) { - return NULL; - } - if (self->parent) { - return cmessage::HasFieldByDescriptor(self->parent, descriptor); - } else { - int exists = PyDict_Contains(self->values, extension); - if (exists < 0) { - return NULL; - } - return PyBool_FromLong(exists); - } -} - PyObject* _FindExtensionByName(ExtensionDict* self, PyObject* name) { ScopedPyObjectPtr extensions_by_name(PyObject_GetAttrString( reinterpret_cast(self->parent), "_extensions_by_name")); @@ -282,8 +212,6 @@ static PyMappingMethods MpMethods = { #define EDMETHOD(name, args, doc) { #name, (PyCFunction)name, args, doc } static PyMethodDef Methods[] = { - EDMETHOD(ClearExtension, METH_O, "Clears an extension from the object."), - EDMETHOD(HasExtension, METH_O, "Checks if the object has an extension."), EDMETHOD(_FindExtensionByName, METH_O, "Finds an extension by name."), EDMETHOD(_FindExtensionByNumber, METH_O, diff --git a/python/google/protobuf/pyext/extension_dict.h b/python/google/protobuf/pyext/extension_dict.h index 2456eda1..65b87862 100644 --- a/python/google/protobuf/pyext/extension_dict.h +++ b/python/google/protobuf/pyext/extension_dict.h @@ -86,49 +86,6 @@ namespace extension_dict { // Builds an Extensions dict for a specific message. ExtensionDict* NewExtensionDict(CMessage *parent); -// Gets the number of extension values in this ExtensionDict as a python object. -// -// Returns a new reference. -PyObject* len(ExtensionDict* self); - -// Releases extensions referenced outside this dictionary to keep outside -// references alive. -// -// Returns 0 on success, -1 on failure. -int ReleaseExtension(ExtensionDict* self, - PyObject* extension, - const FieldDescriptor* descriptor); - -// Gets an extension from the dict for the given extension descriptor. -// -// Returns a new reference. -PyObject* subscript(ExtensionDict* self, PyObject* key); - -// Assigns a value to an extension in the dict. Can only be used for singular -// simple types. -// -// Returns 0 on success, -1 on failure. -int ass_subscript(ExtensionDict* self, PyObject* key, PyObject* value); - -// Clears an extension from the dict. Will release the extension if there -// is still an external reference left to it. -// -// Returns None on success. -PyObject* ClearExtension(ExtensionDict* self, - PyObject* extension); - -// Gets an extension from the dict given the extension name as opposed to -// descriptor. -// -// Returns a new reference. -PyObject* _FindExtensionByName(ExtensionDict* self, PyObject* name); - -// Gets an extension from the dict given the extension field number as -// opposed to descriptor. -// -// Returns a new reference. -PyObject* _FindExtensionByNumber(ExtensionDict* self, PyObject* number); - } // namespace extension_dict } // namespace python } // namespace protobuf diff --git a/python/google/protobuf/pyext/map_container.cc b/python/google/protobuf/pyext/map_container.cc index 0987b898..318c2e7c 100644 --- a/python/google/protobuf/pyext/map_container.cc +++ b/python/google/protobuf/pyext/map_container.cc @@ -42,7 +42,9 @@ #include #include #include +#include #include +#include #include #if PY_MAJOR_VERSION >= 3 @@ -328,6 +330,15 @@ PyObject* Clear(PyObject* _self) { Py_RETURN_NONE; } +PyObject* GetEntryClass(PyObject* _self) { + MapContainer* self = GetMap(_self); + CMessageClass* message_class = message_factory::GetMessageClass( + cmessage::GetFactoryForMessage(self->parent), + self->parent_field_descriptor->message_type()); + Py_XINCREF(message_class); + return reinterpret_cast(message_class); +} + PyObject* MapReflectionFriend::Contains(PyObject* _self, PyObject* key) { MapContainer* self = GetMap(_self); @@ -400,12 +411,7 @@ PyObject *NewScalarMapContainer( return NULL; } -#if PY_MAJOR_VERSION >= 3 - ScopedPyObjectPtr obj(PyType_GenericAlloc( - reinterpret_cast(ScalarMapContainer_Type), 0)); -#else - ScopedPyObjectPtr obj(PyType_GenericAlloc(&ScalarMapContainer_Type, 0)); -#endif + ScopedPyObjectPtr obj(PyType_GenericAlloc(ScalarMapContainer_Type, 0)); if (obj.get() == NULL) { return PyErr_Format(PyExc_RuntimeError, "Could not allocate new container."); @@ -527,6 +533,8 @@ static PyMethodDef ScalarMapMethods[] = { "Removes all elements from the map." }, { "get", ScalarMapGet, METH_VARARGS, "Gets the value for the given key if present, or otherwise a default" }, + { "GetEntryClass", (PyCFunction)GetEntryClass, METH_NOARGS, + "Return the class used to build Entries of (key, value) pairs." }, /* { "__deepcopy__", (PyCFunction)DeepCopy, METH_VARARGS, "Makes a deep copy of the class." }, @@ -536,6 +544,7 @@ static PyMethodDef ScalarMapMethods[] = { {NULL, NULL}, }; +PyTypeObject *ScalarMapContainer_Type; #if PY_MAJOR_VERSION >= 3 static PyType_Slot ScalarMapContainer_Type_slots[] = { {Py_tp_dealloc, (void *)ScalarMapDealloc}, @@ -554,7 +563,6 @@ static PyMethodDef ScalarMapMethods[] = { Py_TPFLAGS_DEFAULT, ScalarMapContainer_Type_slots }; - PyObject *ScalarMapContainer_Type; #else static PyMappingMethods ScalarMapMappingMethods = { MapReflectionFriend::Length, // mp_length @@ -562,7 +570,7 @@ static PyMethodDef ScalarMapMethods[] = { MapReflectionFriend::ScalarMapSetItem, // mp_ass_subscript }; - PyTypeObject ScalarMapContainer_Type = { + PyTypeObject _ScalarMapContainer_Type = { PyVarObject_HEAD_INIT(&PyType_Type, 0) FULL_MODULE_NAME ".ScalarMapContainer", // tp_name sizeof(MapContainer), // tp_basicsize @@ -643,12 +651,7 @@ PyObject* NewMessageMapContainer( return NULL; } -#if PY_MAJOR_VERSION >= 3 - PyObject* obj = PyType_GenericAlloc( - reinterpret_cast(MessageMapContainer_Type), 0); -#else - PyObject* obj = PyType_GenericAlloc(&MessageMapContainer_Type, 0); -#endif + PyObject* obj = PyType_GenericAlloc(MessageMapContainer_Type, 0); if (obj == NULL) { return PyErr_Format(PyExc_RuntimeError, "Could not allocate new container."); @@ -780,6 +783,8 @@ static PyMethodDef MessageMapMethods[] = { "Gets the value for the given key if present, or otherwise a default" }, { "get_or_create", MapReflectionFriend::MessageMapGetItem, METH_O, "Alias for getitem, useful to make explicit that the map is mutated." }, + { "GetEntryClass", (PyCFunction)GetEntryClass, METH_NOARGS, + "Return the class used to build Entries of (key, value) pairs." }, /* { "__deepcopy__", (PyCFunction)DeepCopy, METH_VARARGS, "Makes a deep copy of the class." }, @@ -789,6 +794,7 @@ static PyMethodDef MessageMapMethods[] = { {NULL, NULL}, }; +PyTypeObject *MessageMapContainer_Type; #if PY_MAJOR_VERSION >= 3 static PyType_Slot MessageMapContainer_Type_slots[] = { {Py_tp_dealloc, (void *)MessageMapDealloc}, @@ -807,8 +813,6 @@ static PyMethodDef MessageMapMethods[] = { Py_TPFLAGS_DEFAULT, MessageMapContainer_Type_slots }; - - PyObject *MessageMapContainer_Type; #else static PyMappingMethods MessageMapMappingMethods = { MapReflectionFriend::Length, // mp_length @@ -816,7 +820,7 @@ static PyMethodDef MessageMapMethods[] = { MapReflectionFriend::MessageMapSetItem, // mp_ass_subscript }; - PyTypeObject MessageMapContainer_Type = { + PyTypeObject _MessageMapContainer_Type = { PyVarObject_HEAD_INIT(&PyType_Type, 0) FULL_MODULE_NAME ".MessageMapContainer", // tp_name sizeof(MessageMapContainer), // tp_basicsize @@ -965,6 +969,63 @@ PyTypeObject MapIterator_Type = { 0, // tp_init }; +bool InitMapContainers() { + // ScalarMapContainer_Type derives from our MutableMapping type. + ScopedPyObjectPtr containers(PyImport_ImportModule( + "google.protobuf.internal.containers")); + if (containers == NULL) { + return false; + } + + ScopedPyObjectPtr mutable_mapping( + PyObject_GetAttrString(containers.get(), "MutableMapping")); + if (mutable_mapping == NULL) { + return false; + } + + if (!PyObject_TypeCheck(mutable_mapping.get(), &PyType_Type)) { + return false; + } + + Py_INCREF(mutable_mapping.get()); +#if PY_MAJOR_VERSION >= 3 + PyObject* bases = PyTuple_New(1); + PyTuple_SET_ITEM(bases, 0, mutable_mapping.get()); + + ScalarMapContainer_Type = reinterpret_cast( + PyType_FromSpecWithBases(&ScalarMapContainer_Type_spec, bases)); +#else + _ScalarMapContainer_Type.tp_base = + reinterpret_cast(mutable_mapping.get()); + + if (PyType_Ready(&_ScalarMapContainer_Type) < 0) { + return false; + } + + ScalarMapContainer_Type = &_ScalarMapContainer_Type; +#endif + + if (PyType_Ready(&MapIterator_Type) < 0) { + return false; + } + +#if PY_MAJOR_VERSION >= 3 + MessageMapContainer_Type = reinterpret_cast( + PyType_FromSpecWithBases(&MessageMapContainer_Type_spec, bases)); +#else + Py_INCREF(mutable_mapping.get()); + _MessageMapContainer_Type.tp_base = + reinterpret_cast(mutable_mapping.get()); + + if (PyType_Ready(&_MessageMapContainer_Type) < 0) { + return false; + } + + MessageMapContainer_Type = &_MessageMapContainer_Type; +#endif + return true; +} + } // namespace python } // namespace protobuf } // namespace google diff --git a/python/google/protobuf/pyext/map_container.h b/python/google/protobuf/pyext/map_container.h index fbd6713f..615657b0 100644 --- a/python/google/protobuf/pyext/map_container.h +++ b/python/google/protobuf/pyext/map_container.h @@ -112,16 +112,10 @@ struct MessageMapContainer : public MapContainer { PyObject* message_dict; }; -#if PY_MAJOR_VERSION >= 3 - extern PyObject *MessageMapContainer_Type; - extern PyType_Spec MessageMapContainer_Type_spec; - extern PyObject *ScalarMapContainer_Type; - extern PyType_Spec ScalarMapContainer_Type_spec; -#else - extern PyTypeObject MessageMapContainer_Type; - extern PyTypeObject ScalarMapContainer_Type; -#endif +bool InitMapContainers(); +extern PyTypeObject* MessageMapContainer_Type; +extern PyTypeObject* ScalarMapContainer_Type; extern PyTypeObject MapIterator_Type; // Both map types use the same iterator. // Builds a MapContainer object, from a parent message and a diff --git a/python/google/protobuf/pyext/message.cc b/python/google/protobuf/pyext/message.cc index 5535338d..1b325469 100644 --- a/python/google/protobuf/pyext/message.cc +++ b/python/google/protobuf/pyext/message.cc @@ -63,6 +63,7 @@ #include #include #include +#include #include #include @@ -244,6 +245,12 @@ static PyObject* New(PyTypeObject* type, return NULL; } + // Messages have no __dict__ + ScopedPyObjectPtr slots(PyTuple_New(0)); + if (PyDict_SetItemString(dict, "__slots__", slots.get()) < 0) { + return NULL; + } + // Build the arguments to the base metaclass. // We change the __bases__ classes. ScopedPyObjectPtr new_args; @@ -300,16 +307,19 @@ static PyObject* New(PyTypeObject* type, newtype->message_descriptor = descriptor; // TODO(amauryfa): Don't always use the canonical pool of the descriptor, // use the MessageFactory optionally passed in the class dict. - newtype->py_descriptor_pool = GetDescriptorPool_FromPool( - descriptor->file()->pool()); - if (newtype->py_descriptor_pool == NULL) { + PyDescriptorPool* py_descriptor_pool = + GetDescriptorPool_FromPool(descriptor->file()->pool()); + if (py_descriptor_pool == NULL) { return NULL; } - Py_INCREF(newtype->py_descriptor_pool); + newtype->py_message_factory = py_descriptor_pool->py_message_factory; + Py_INCREF(newtype->py_message_factory); - // Add the message to the DescriptorPool. - if (cdescriptor_pool::RegisterMessageClass(newtype->py_descriptor_pool, - descriptor, newtype) < 0) { + // Register the message in the MessageFactory. + // TODO(amauryfa): Move this call to MessageFactory.GetPrototype() when the + // MessageFactory is fully implemented in C++. + if (message_factory::RegisterMessageClass(newtype->py_message_factory, + descriptor, newtype) < 0) { return NULL; } @@ -321,8 +331,8 @@ static PyObject* New(PyTypeObject* type, } static void Dealloc(CMessageClass *self) { - Py_DECREF(self->py_message_descriptor); - Py_DECREF(self->py_descriptor_pool); + Py_XDECREF(self->py_message_descriptor); + Py_XDECREF(self->py_message_factory); Py_TYPE(self)->tp_free(reinterpret_cast(self)); } @@ -752,15 +762,9 @@ bool CheckFieldBelongsToMessage(const FieldDescriptor* field_descriptor, namespace cmessage { -PyDescriptorPool* GetDescriptorPoolForMessage(CMessage* message) { - // No need to check the type: the type of instances of CMessage is always - // an instance of CMessageClass. Let's prove it with a debug-only check. +PyMessageFactory* GetFactoryForMessage(CMessage* message) { GOOGLE_DCHECK(PyObject_TypeCheck(message, &CMessage_Type)); - return reinterpret_cast(Py_TYPE(message))->py_descriptor_pool; -} - -MessageFactory* GetFactoryForMessage(CMessage* message) { - return GetDescriptorPoolForMessage(message)->message_factory; + return reinterpret_cast(Py_TYPE(message))->py_message_factory; } static int MaybeReleaseOverlappingOneofField( @@ -813,7 +817,8 @@ static Message* GetMutableMessage( return NULL; } return reflection->MutableMessage( - parent_message, parent_field, GetFactoryForMessage(parent)); + parent_message, parent_field, + GetFactoryForMessage(parent)->message_factory); } struct FixupMessageReference : public ChildVisitor { @@ -1172,6 +1177,8 @@ int InitAttributes(CMessage* self, PyObject* args, PyObject* kwargs) { } CMessage* cmessage = reinterpret_cast(message.get()); if (PyDict_Check(value)) { + // Make the message exist even if the dict is empty. + AssureWritable(cmessage); if (InitAttributes(cmessage, NULL, value) < 0) { return -1; } @@ -1231,7 +1238,7 @@ static PyObject* New(PyTypeObject* cls, if (message_descriptor == NULL) { return NULL; } - const Message* default_message = type->py_descriptor_pool->message_factory + const Message* default_message = type->py_message_factory->message_factory ->GetPrototype(message_descriptor); if (default_message == NULL) { PyErr_SetString(PyExc_TypeError, message_descriptor->full_name().c_str()); @@ -1292,6 +1299,9 @@ struct ClearWeakReferences : public ChildVisitor { }; static void Dealloc(CMessage* self) { + if (self->weakreflist) { + PyObject_ClearWeakRefs(reinterpret_cast(self)); + } // Null out all weak references from children to this message. GOOGLE_CHECK_EQ(0, ForEachCompositeField(self, ClearWeakReferences())); if (self->extensions) { @@ -1459,18 +1469,20 @@ PyObject* HasField(CMessage* self, PyObject* arg) { } PyObject* ClearExtension(CMessage* self, PyObject* extension) { + const FieldDescriptor* descriptor = GetExtensionDescriptor(extension); + if (descriptor == NULL) { + return NULL; + } if (self->extensions != NULL) { - return extension_dict::ClearExtension(self->extensions, extension); - } else { - const FieldDescriptor* descriptor = GetExtensionDescriptor(extension); - if (descriptor == NULL) { - return NULL; - } - if (ScopedPyObjectPtr(ClearFieldByDescriptor(self, descriptor)) == NULL) { - return NULL; + PyObject* value = PyDict_GetItem(self->extensions->values, extension); + if (value != NULL) { + if (InternalReleaseFieldByDescriptor(self, descriptor, value) < 0) { + return NULL; + } + PyDict_DelItem(self->extensions->values, extension); } } - Py_RETURN_NONE; + return ClearFieldByDescriptor(self, descriptor); } PyObject* HasExtension(CMessage* self, PyObject* extension) { @@ -1556,7 +1568,7 @@ int SetOwner(CMessage* self, const shared_ptr& new_owner) { Message* ReleaseMessage(CMessage* self, const Descriptor* descriptor, const FieldDescriptor* field_descriptor) { - MessageFactory* message_factory = GetFactoryForMessage(self); + MessageFactory* message_factory = GetFactoryForMessage(self)->message_factory; Message* released_message = self->message->GetReflection()->ReleaseMessage( self->message, field_descriptor, message_factory); // ReleaseMessage will return NULL which differs from @@ -1624,12 +1636,19 @@ int InternalReleaseFieldByDescriptor( PyObject* ClearFieldByDescriptor( CMessage* self, - const FieldDescriptor* descriptor) { - if (!CheckFieldBelongsToMessage(descriptor, self->message)) { + const FieldDescriptor* field_descriptor) { + if (!CheckFieldBelongsToMessage(field_descriptor, self->message)) { return NULL; } AssureWritable(self); - self->message->GetReflection()->ClearField(self->message, descriptor); + Message* message = self->message; + message->GetReflection()->ClearField(message, field_descriptor); + if (field_descriptor->cpp_type() == FieldDescriptor::CPPTYPE_ENUM && + !message->GetReflection()->SupportsUnknownEnumValues()) { + UnknownFieldSet* unknown_field_set = + message->GetReflection()->MutableUnknownFields(message); + unknown_field_set->DeleteByNumber(field_descriptor->number()); + } Py_RETURN_NONE; } @@ -1665,27 +1684,17 @@ PyObject* ClearField(CMessage* self, PyObject* arg) { arg = arg_in_oneof.get(); } - PyObject* composite_field = self->composite_fields ? - PyDict_GetItem(self->composite_fields, arg) : NULL; - - // Only release the field if there's a possibility that there are - // references to it. - if (composite_field != NULL) { - if (InternalReleaseFieldByDescriptor(self, field_descriptor, - composite_field) < 0) { - return NULL; + // Release the field if it exists in the dict of composite fields. + if (self->composite_fields) { + PyObject* value = PyDict_GetItem(self->composite_fields, arg); + if (value != NULL) { + if (InternalReleaseFieldByDescriptor(self, field_descriptor, value) < 0) { + return NULL; + } + PyDict_DelItem(self->composite_fields, arg); } - PyDict_DelItem(self->composite_fields, arg); - } - message->GetReflection()->ClearField(message, field_descriptor); - if (field_descriptor->cpp_type() == FieldDescriptor::CPPTYPE_ENUM && - !message->GetReflection()->SupportsUnknownEnumValues()) { - UnknownFieldSet* unknown_field_set = - message->GetReflection()->MutableUnknownFields(message); - unknown_field_set->DeleteByNumber(field_descriptor->number()); } - - Py_RETURN_NONE; + return ClearFieldByDescriptor(self, field_descriptor); } PyObject* Clear(CMessage* self) { @@ -1927,8 +1936,8 @@ static PyObject* MergeFromString(CMessage* self, PyObject* arg) { if (allow_oversize_protos) { input.SetTotalBytesLimit(INT_MAX, INT_MAX); } - PyDescriptorPool* pool = GetDescriptorPoolForMessage(self); - input.SetExtensionRegistry(pool->pool, pool->message_factory); + PyMessageFactory* factory = GetFactoryForMessage(self); + input.SetExtensionRegistry(factory->pool->pool, factory->message_factory); bool success = self->message->MergePartialFromCodedStream(&input); if (success) { return PyInt_FromLong(input.CurrentPosition()); @@ -2108,8 +2117,8 @@ static PyObject* ListFields(CMessage* self) { // is no message class and we cannot retrieve the value. // TODO(amauryfa): consider building the class on the fly! if (fields[i]->message_type() != NULL && - cdescriptor_pool::GetMessageClass( - GetDescriptorPoolForMessage(self), + message_factory::GetMessageClass( + GetFactoryForMessage(self), fields[i]->message_type()) == NULL) { PyErr_Clear(); continue; @@ -2306,12 +2315,12 @@ PyObject* InternalGetScalar(const Message* message, PyObject* InternalGetSubMessage( CMessage* self, const FieldDescriptor* field_descriptor) { const Reflection* reflection = self->message->GetReflection(); - PyDescriptorPool* pool = GetDescriptorPoolForMessage(self); + PyMessageFactory* factory = GetFactoryForMessage(self); const Message& sub_message = reflection->GetMessage( - *self->message, field_descriptor, pool->message_factory); + *self->message, field_descriptor, factory->message_factory); - CMessageClass* message_class = cdescriptor_pool::GetMessageClass( - pool, field_descriptor->message_type()); + CMessageClass* message_class = message_factory::GetMessageClass( + factory, field_descriptor->message_type()); if (message_class == NULL) { return NULL; } @@ -2656,8 +2665,8 @@ PyObject* GetAttr(CMessage* self, PyObject* name) { const Descriptor* entry_type = field_descriptor->message_type(); const FieldDescriptor* value_type = entry_type->FindFieldByName("value"); if (value_type->cpp_type() == FieldDescriptor::CPPTYPE_MESSAGE) { - CMessageClass* value_class = cdescriptor_pool::GetMessageClass( - GetDescriptorPoolForMessage(self), value_type->message_type()); + CMessageClass* value_class = message_factory::GetMessageClass( + GetFactoryForMessage(self), value_type->message_type()); if (value_class == NULL) { return NULL; } @@ -2679,8 +2688,8 @@ PyObject* GetAttr(CMessage* self, PyObject* name) { if (field_descriptor->label() == FieldDescriptor::LABEL_REPEATED) { PyObject* py_container = NULL; if (field_descriptor->cpp_type() == FieldDescriptor::CPPTYPE_MESSAGE) { - CMessageClass* message_class = cdescriptor_pool::GetMessageClass( - GetDescriptorPoolForMessage(self), field_descriptor->message_type()); + CMessageClass* message_class = message_factory::GetMessageClass( + GetFactoryForMessage(self), field_descriptor->message_type()); if (message_class == NULL) { return NULL; } @@ -2775,7 +2784,7 @@ PyTypeObject CMessage_Type = { 0, // tp_traverse 0, // tp_clear (richcmpfunc)cmessage::RichCompare, // tp_richcompare - 0, // tp_weaklistoffset + offsetof(CMessage, weakreflist), // tp_weaklistoffset 0, // tp_iter 0, // tp_iternext cmessage::Methods, // tp_methods @@ -2863,6 +2872,11 @@ bool InitProto2MessageModule(PyObject *m) { return false; } + // Initialize types and globals in message_factory.cc + if (!InitMessageFactory()) { + return false; + } + // Initialize constants defined in this file. InitGlobals(); @@ -2944,69 +2958,15 @@ bool InitProto2MessageModule(PyObject *m) { } // Initialize Map container types. - { - // ScalarMapContainer_Type derives from our MutableMapping type. - ScopedPyObjectPtr containers(PyImport_ImportModule( - "google.protobuf.internal.containers")); - if (containers == NULL) { - return false; - } - - ScopedPyObjectPtr mutable_mapping( - PyObject_GetAttrString(containers.get(), "MutableMapping")); - if (mutable_mapping == NULL) { - return false; - } - - if (!PyObject_TypeCheck(mutable_mapping.get(), &PyType_Type)) { - return false; - } - - Py_INCREF(mutable_mapping.get()); -#if PY_MAJOR_VERSION >= 3 - PyObject* bases = PyTuple_New(1); - PyTuple_SET_ITEM(bases, 0, mutable_mapping.get()); - - ScalarMapContainer_Type = - PyType_FromSpecWithBases(&ScalarMapContainer_Type_spec, bases); - PyModule_AddObject(m, "ScalarMapContainer", ScalarMapContainer_Type); -#else - ScalarMapContainer_Type.tp_base = - reinterpret_cast(mutable_mapping.get()); - - if (PyType_Ready(&ScalarMapContainer_Type) < 0) { - return false; - } - - PyModule_AddObject(m, "ScalarMapContainer", - reinterpret_cast(&ScalarMapContainer_Type)); -#endif - - if (PyType_Ready(&MapIterator_Type) < 0) { - return false; - } - - PyModule_AddObject(m, "MapIterator", - reinterpret_cast(&MapIterator_Type)); - - -#if PY_MAJOR_VERSION >= 3 - MessageMapContainer_Type = - PyType_FromSpecWithBases(&MessageMapContainer_Type_spec, bases); - PyModule_AddObject(m, "MessageMapContainer", MessageMapContainer_Type); -#else - Py_INCREF(mutable_mapping.get()); - MessageMapContainer_Type.tp_base = - reinterpret_cast(mutable_mapping.get()); - - if (PyType_Ready(&MessageMapContainer_Type) < 0) { - return false; - } - - PyModule_AddObject(m, "MessageMapContainer", - reinterpret_cast(&MessageMapContainer_Type)); -#endif + if (!InitMapContainers()) { + return false; } + PyModule_AddObject(m, "ScalarMapContainer", + reinterpret_cast(ScalarMapContainer_Type)); + PyModule_AddObject(m, "MessageMapContainer", + reinterpret_cast(MessageMapContainer_Type)); + PyModule_AddObject(m, "MapIterator", + reinterpret_cast(&MapIterator_Type)); if (PyType_Ready(&ExtensionDict_Type) < 0) { return false; diff --git a/python/google/protobuf/pyext/message.h b/python/google/protobuf/pyext/message.h index c44a2ae2..1550724c 100644 --- a/python/google/protobuf/pyext/message.h +++ b/python/google/protobuf/pyext/message.h @@ -62,7 +62,7 @@ using internal::shared_ptr; namespace python { struct ExtensionDict; -struct PyDescriptorPool; +struct PyMessageFactory; typedef struct CMessage { PyObject_HEAD; @@ -112,6 +112,9 @@ typedef struct CMessage { // Similar to composite_fields, acting as a cache, but also contains the // required extension dict logic. ExtensionDict* extensions; + + // Implements the "weakref" protocol for this object. + PyObject* weakreflist; } CMessage; extern PyTypeObject CMessage_Type; @@ -132,14 +135,11 @@ struct CMessageClass { // Owned reference, used to keep the pointer above alive. PyObject* py_message_descriptor; - // The Python DescriptorPool used to create the class. It is needed to resolve + // The Python MessageFactory used to create the class. It is needed to resolve // fields descriptors, including extensions fields; its C++ MessageFactory is // used to instantiate submessages. - // This can be different from DESCRIPTOR.file.pool, in the case of a custom - // DescriptorPool which defines new extensions. - // We own the reference, because it's important to keep the descriptors and - // factory alive. - PyDescriptorPool* py_descriptor_pool; + // We own the reference, because it's important to keep the factory alive. + PyMessageFactory* py_message_factory; PyObject* AsPyObject() { return reinterpret_cast(this); @@ -154,14 +154,6 @@ namespace cmessage { // The caller must fill self->message, self->owner and eventually self->parent. CMessage* NewEmptyMessage(CMessageClass* type); -// Release a submessage from its proto tree, making it a new top-level messgae. -// A new message will be created if this is a read-only default instance. -// -// Corresponds to reflection api method ReleaseMessage. -int ReleaseSubMessage(CMessage* self, - const FieldDescriptor* field_descriptor, - CMessage* child_cmessage); - // Retrieves the C++ descriptor of a Python Extension descriptor. // On error, return NULL with an exception set. const FieldDescriptor* GetExtensionDescriptor(PyObject* extension); @@ -262,14 +254,13 @@ int SetOwner(CMessage* self, const shared_ptr& new_owner); int AssureWritable(CMessage* self); -// Returns the "best" DescriptorPool for the given message. -// This is often equivalent to message.DESCRIPTOR.pool, but not always, when -// the message class was created from a MessageFactory using a custom pool which -// uses the generated pool as an underlay. +// Returns the message factory for the given message. +// This is equivalent to message.MESSAGE_FACTORY // -// The returned pool is suitable for finding fields and building submessages, +// The returned factory is suitable for finding fields and building submessages, // even in the case of extensions. -PyDescriptorPool* GetDescriptorPoolForMessage(CMessage* message); +// Returns a *borrowed* reference, and never fails because we pass a CMessage. +PyMessageFactory* GetFactoryForMessage(CMessage* message); PyObject* SetAllowOversizeProtos(PyObject* m, PyObject* arg); diff --git a/python/google/protobuf/pyext/message_factory.cc b/python/google/protobuf/pyext/message_factory.cc new file mode 100644 index 00000000..2ad89022 --- /dev/null +++ b/python/google/protobuf/pyext/message_factory.cc @@ -0,0 +1,214 @@ +// Protocol Buffers - Google's data interchange format +// Copyright 2008 Google Inc. All rights reserved. +// https://developers.google.com/protocol-buffers/ +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following disclaimer +// in the documentation and/or other materials provided with the +// distribution. +// * Neither the name of Google Inc. nor the names of its +// contributors may be used to endorse or promote products derived from +// this software without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +#include + +#include +#include +#include +#include +#include + +#if PY_MAJOR_VERSION >= 3 + #if PY_VERSION_HEX < 0x03030000 + #error "Python 3.0 - 3.2 are not supported." + #endif + #define PyString_AsStringAndSize(ob, charpp, sizep) \ + (PyUnicode_Check(ob)? \ + ((*(charpp) = PyUnicode_AsUTF8AndSize(ob, (sizep))) == NULL? -1: 0): \ + PyBytes_AsStringAndSize(ob, (charpp), (sizep))) +#endif + +namespace google { +namespace protobuf { +namespace python { + +namespace message_factory { + +PyMessageFactory* NewMessageFactory(PyTypeObject* type, PyDescriptorPool* pool) { + PyMessageFactory* factory = reinterpret_cast( + PyType_GenericAlloc(type, 0)); + if (factory == NULL) { + return NULL; + } + + DynamicMessageFactory* message_factory = new DynamicMessageFactory(); + // This option might be the default some day. + message_factory->SetDelegateToGeneratedFactory(true); + factory->message_factory = message_factory; + + factory->pool = pool; + // TODO(amauryfa): When the MessageFactory is not created from the + // DescriptorPool this reference should be owned, not borrowed. + // Py_INCREF(pool); + + factory->classes_by_descriptor = new PyMessageFactory::ClassesByMessageMap(); + + return factory; +} + +PyObject* New(PyTypeObject* type, PyObject* args, PyObject* kwargs) { + static char* kwlist[] = {"pool", 0}; + PyObject* pool = NULL; + if (!PyArg_ParseTupleAndKeywords(args, kwargs, "|O", kwlist, &pool)) { + return NULL; + } + ScopedPyObjectPtr owned_pool; + if (pool == NULL || pool == Py_None) { + owned_pool.reset(PyObject_CallFunction( + reinterpret_cast(&PyDescriptorPool_Type), NULL)); + if (owned_pool == NULL) { + return NULL; + } + pool = owned_pool.get(); + } else { + if (!PyObject_TypeCheck(pool, &PyDescriptorPool_Type)) { + PyErr_Format(PyExc_TypeError, "Expected a DescriptorPool, got %s", + pool->ob_type->tp_name); + return NULL; + } + } + + return reinterpret_cast( + NewMessageFactory(type, reinterpret_cast(pool))); +} + +static void Dealloc(PyMessageFactory* self) { + // TODO(amauryfa): When the MessageFactory is not created from the + // DescriptorPool this reference should be owned, not borrowed. + // Py_CLEAR(self->pool); + typedef PyMessageFactory::ClassesByMessageMap::iterator iterator; + for (iterator it = self->classes_by_descriptor->begin(); + it != self->classes_by_descriptor->end(); ++it) { + Py_DECREF(it->second); + } + delete self->classes_by_descriptor; + delete self->message_factory; + Py_TYPE(self)->tp_free(reinterpret_cast(self)); +} + +// Add a message class to our database. +int RegisterMessageClass(PyMessageFactory* self, + const Descriptor* message_descriptor, + CMessageClass* message_class) { + Py_INCREF(message_class); + typedef PyMessageFactory::ClassesByMessageMap::iterator iterator; + std::pair ret = self->classes_by_descriptor->insert( + std::make_pair(message_descriptor, message_class)); + if (!ret.second) { + // Update case: DECREF the previous value. + Py_DECREF(ret.first->second); + ret.first->second = message_class; + } + return 0; +} + +// Retrieve the message class added to our database. +CMessageClass* GetMessageClass(PyMessageFactory* self, + const Descriptor* message_descriptor) { + typedef PyMessageFactory::ClassesByMessageMap::iterator iterator; + iterator ret = self->classes_by_descriptor->find(message_descriptor); + if (ret == self->classes_by_descriptor->end()) { + PyErr_Format(PyExc_TypeError, "No message class registered for '%s'", + message_descriptor->full_name().c_str()); + return NULL; + } else { + return ret->second; + } +} + +static PyMethodDef Methods[] = { + {NULL}}; + +static PyObject* GetPool(PyMessageFactory* self, void* closure) { + Py_INCREF(self->pool); + return reinterpret_cast(self->pool); +} + +static PyGetSetDef Getters[] = { + {"pool", (getter)GetPool, NULL, "DescriptorPool"}, + {NULL} +}; + +} // namespace message_factory + +PyTypeObject PyMessageFactory_Type = { + PyVarObject_HEAD_INIT(&PyType_Type, 0) FULL_MODULE_NAME + ".MessageFactory", // tp_name + sizeof(PyMessageFactory), // tp_basicsize + 0, // tp_itemsize + (destructor)message_factory::Dealloc, // tp_dealloc + 0, // tp_print + 0, // tp_getattr + 0, // tp_setattr + 0, // tp_compare + 0, // tp_repr + 0, // tp_as_number + 0, // tp_as_sequence + 0, // tp_as_mapping + 0, // tp_hash + 0, // tp_call + 0, // tp_str + 0, // tp_getattro + 0, // tp_setattro + 0, // tp_as_buffer + Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, // tp_flags + "A static Message Factory", // tp_doc + 0, // tp_traverse + 0, // tp_clear + 0, // tp_richcompare + 0, // tp_weaklistoffset + 0, // tp_iter + 0, // tp_iternext + message_factory::Methods, // tp_methods + 0, // tp_members + message_factory::Getters, // tp_getset + 0, // tp_base + 0, // tp_dict + 0, // tp_descr_get + 0, // tp_descr_set + 0, // tp_dictoffset + 0, // tp_init + 0, // tp_alloc + message_factory::New, // tp_new + PyObject_Del, // tp_free +}; + +bool InitMessageFactory() { + if (PyType_Ready(&PyMessageFactory_Type) < 0) { + return false; + } + + return true; +} + +} // namespace python +} // namespace protobuf +} // namespace google diff --git a/python/google/protobuf/pyext/message_factory.h b/python/google/protobuf/pyext/message_factory.h new file mode 100644 index 00000000..07cccbfb --- /dev/null +++ b/python/google/protobuf/pyext/message_factory.h @@ -0,0 +1,103 @@ +// 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. + +#ifndef GOOGLE_PROTOBUF_PYTHON_CPP_MESSAGE_FACTORY_H__ +#define GOOGLE_PROTOBUF_PYTHON_CPP_MESSAGE_FACTORY_H__ + +#include + +#include +#include +#include + +namespace google { +namespace protobuf { +class MessageFactory; + +namespace python { + +// The (meta) type of all Messages classes. +struct CMessageClass; + +struct PyMessageFactory { + PyObject_HEAD + + // DynamicMessageFactory used to create C++ instances of messages. + // This object cache the descriptors that were used, so the DescriptorPool + // needs to get rid of it before it can delete itself. + // + // Note: A C++ MessageFactory is different from the PyMessageFactory. + // The C++ one creates messages, when the Python one creates classes. + MessageFactory* message_factory; + + // borrowed reference to a Python DescriptorPool. + // TODO(amauryfa): invert the dependency: the MessageFactory owns the + // DescriptorPool, not the opposite. + PyDescriptorPool* pool; + + // Make our own mapping to retrieve Python classes from C++ descriptors. + // + // Descriptor pointers stored here are owned by the DescriptorPool above. + // Python references to classes are owned by this PyDescriptorPool. + typedef hash_map ClassesByMessageMap; + ClassesByMessageMap* classes_by_descriptor; +}; + +extern PyTypeObject PyMessageFactory_Type; + +namespace message_factory { + +// Creates a new MessageFactory instance. +PyMessageFactory* NewMessageFactory(PyTypeObject* type, PyDescriptorPool* pool); + +// Registers a new Python class for the given message descriptor. +// On error, returns -1 with a Python exception set. +int RegisterMessageClass(PyMessageFactory* self, + const Descriptor* message_descriptor, + CMessageClass* message_class); + +// Retrieves the Python class registered with the given message descriptor. +// +// Returns a *borrowed* reference if found, otherwise returns NULL with an +// exception set. +CMessageClass* GetMessageClass(PyMessageFactory* self, + const Descriptor* message_descriptor); + +} // namespace message_factory + +// Initialize objects used by this module. +// On error, returns false with a Python exception set. +bool InitMessageFactory(); + +} // namespace python +} // namespace protobuf + +} // namespace google +#endif // GOOGLE_PROTOBUF_PYTHON_CPP_MESSAGE_FACTORY_H__ diff --git a/python/google/protobuf/pyext/repeated_composite_container.cc b/python/google/protobuf/pyext/repeated_composite_container.cc index bb2f6db2..43a2bc12 100644 --- a/python/google/protobuf/pyext/repeated_composite_container.cc +++ b/python/google/protobuf/pyext/repeated_composite_container.cc @@ -364,7 +364,7 @@ static int SortPythonMessages(RepeatedCompositeContainer* self, ScopedPyObjectPtr m(PyObject_GetAttrString(self->child_messages, "sort")); if (m == NULL) return -1; - if (PyObject_Call(m.get(), args, kwds) == NULL) + if (ScopedPyObjectPtr(PyObject_Call(m.get(), args, kwds)) == NULL) return -1; if (self->message != NULL) { ReorderAttached(self); diff --git a/python/google/protobuf/symbol_database.py b/python/google/protobuf/symbol_database.py index aa466abd..ecbef211 100644 --- a/python/google/protobuf/symbol_database.py +++ b/python/google/protobuf/symbol_database.py @@ -129,7 +129,8 @@ class SymbolDatabase(message_factory.MessageFactory): Only messages already created and registered will be returned; (this is the case for imported _pb2 modules) - But unlike MessageFactory, this version also returns nested messages. + But unlike MessageFactory, this version also returns already defined nested + messages, but does not register any message extensions. Args: files: The file names to extract messages from. diff --git a/python/google/protobuf/text_format.py b/python/google/protobuf/text_format.py index 06b79d77..90f6ce42 100755 --- a/python/google/protobuf/text_format.py +++ b/python/google/protobuf/text_format.py @@ -228,13 +228,13 @@ def _BuildMessageFromTypeName(type_name, descriptor_pool): wasn't found matching type_name. """ # pylint: disable=g-import-not-at-top - from google.protobuf import message_factory - factory = message_factory.MessageFactory(descriptor_pool) + from google.protobuf import symbol_database + database = symbol_database.Default() try: message_descriptor = descriptor_pool.FindMessageTypeByName(type_name) except KeyError: return None - message_type = factory.GetPrototype(message_descriptor) + message_type = database.GetPrototype(message_descriptor) return message_type() @@ -317,8 +317,7 @@ class _Printer(object): # of this file to work around. # # TODO(haberman): refactor and optimize if this becomes an issue. - entry_submsg = field.message_type._concrete_class(key=key, - value=value[key]) + entry_submsg = value.GetEntryClass()(key=key, value=value[key]) self.PrintField(field, entry_submsg) elif field.label == descriptor.FieldDescriptor.LABEL_REPEATED: for element in value: @@ -749,8 +748,7 @@ class _Parser(object): if field.is_extension: sub_message = message.Extensions[field].add() elif is_map_entry: - # pylint: disable=protected-access - sub_message = field.message_type._concrete_class() + sub_message = getattr(message, field.name).GetEntryClass()() else: sub_message = getattr(message, field.name).add() else: @@ -1448,9 +1446,9 @@ def ParseBool(text): Raises: ValueError: If text is not a valid boolean. """ - if text in ('true', 't', '1'): + if text in ('true', 't', '1', 'True'): return True - elif text in ('false', 'f', '0'): + elif text in ('false', 'f', '0', 'False'): return False else: raise ValueError('Expected "true" or "false".') diff --git a/src/Makefile.am b/src/Makefile.am index c8b85447..aa0e7902 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -526,8 +526,10 @@ protoc_inputs = \ google/protobuf/util/internal/testdata/field_mask.proto \ google/protobuf/util/internal/testdata/maps.proto \ google/protobuf/util/internal/testdata/oneofs.proto \ + google/protobuf/util/internal/testdata/proto3.proto \ google/protobuf/util/internal/testdata/struct.proto \ google/protobuf/util/internal/testdata/timestamp_duration.proto \ + google/protobuf/util/internal/testdata/wrappers.proto \ google/protobuf/util/json_format_proto3.proto \ google/protobuf/util/message_differencer_unittest.proto \ google/protobuf/compiler/cpp/cpp_test_large_enum_value.proto @@ -643,10 +645,14 @@ protoc_outputs = \ google/protobuf/util/internal/testdata/maps.pb.h \ google/protobuf/util/internal/testdata/oneofs.pb.cc \ google/protobuf/util/internal/testdata/oneofs.pb.h \ + google/protobuf/util/internal/testdata/proto3.pb.cc \ + google/protobuf/util/internal/testdata/proto3.pb.h \ google/protobuf/util/internal/testdata/struct.pb.cc \ google/protobuf/util/internal/testdata/struct.pb.h \ google/protobuf/util/internal/testdata/timestamp_duration.pb.cc \ google/protobuf/util/internal/testdata/timestamp_duration.pb.h \ + google/protobuf/util/internal/testdata/wrappers.pb.cc \ + google/protobuf/util/internal/testdata/wrappers.pb.h \ google/protobuf/util/json_format_proto3.pb.cc \ google/protobuf/util/json_format_proto3.pb.h \ google/protobuf/util/message_differencer_unittest.pb.cc \ diff --git a/src/google/protobuf/any.pb.cc b/src/google/protobuf/any.pb.cc index 80e96528..fa9d18a2 100644 --- a/src/google/protobuf/any.pb.cc +++ b/src/google/protobuf/any.pb.cc @@ -44,20 +44,19 @@ void protobuf_AssignDesc_google_2fprotobuf_2fany_2eproto() { Any_reflection_ = ::google::protobuf::internal::GeneratedMessageReflection::NewGeneratedMessageReflection( Any_descriptor_, - Any::default_instance_, + Any::internal_default_instance(), Any_offsets_, -1, -1, -1, sizeof(Any), - GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(Any, _internal_metadata_), - GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(Any, _is_default_instance_)); + GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(Any, _internal_metadata_)); } namespace { GOOGLE_PROTOBUF_DECLARE_ONCE(protobuf_AssignDescriptors_once_); -inline void protobuf_AssignDescriptorsOnce() { +void protobuf_AssignDescriptorsOnce() { ::google::protobuf::GoogleOnceInit(&protobuf_AssignDescriptors_once_, &protobuf_AssignDesc_google_2fprotobuf_2fany_2eproto); } @@ -66,37 +65,49 @@ void protobuf_RegisterTypes(const ::std::string&) GOOGLE_ATTRIBUTE_COLD; void protobuf_RegisterTypes(const ::std::string&) { protobuf_AssignDescriptorsOnce(); ::google::protobuf::MessageFactory::InternalRegisterGeneratedMessage( - Any_descriptor_, &Any::default_instance()); + Any_descriptor_, Any::internal_default_instance()); } } // namespace void protobuf_ShutdownFile_google_2fprotobuf_2fany_2eproto() { - delete Any::default_instance_; delete Any_reflection_; } -void protobuf_AddDesc_google_2fprotobuf_2fany_2eproto() GOOGLE_ATTRIBUTE_COLD; -void protobuf_AddDesc_google_2fprotobuf_2fany_2eproto() { - static bool already_here = false; - if (already_here) return; - already_here = true; +void protobuf_InitDefaults_google_2fprotobuf_2fany_2eproto_impl() { + GOOGLE_PROTOBUF_VERIFY_VERSION; + + ::google::protobuf::internal::GetEmptyString(); + Any::default_instance_.DefaultConstruct(); + Any::default_instance_.get_mutable()->InitAsDefaultInstance(); +} + +GOOGLE_PROTOBUF_DECLARE_ONCE(protobuf_InitDefaults_google_2fprotobuf_2fany_2eproto_once_); +void protobuf_InitDefaults_google_2fprotobuf_2fany_2eproto() { + ::google::protobuf::GoogleOnceInit(&protobuf_InitDefaults_google_2fprotobuf_2fany_2eproto_once_, + &protobuf_InitDefaults_google_2fprotobuf_2fany_2eproto_impl); +} +void protobuf_AddDesc_google_2fprotobuf_2fany_2eproto_impl() { GOOGLE_PROTOBUF_VERIFY_VERSION; + protobuf_InitDefaults_google_2fprotobuf_2fany_2eproto(); ::google::protobuf::DescriptorPool::InternalAddGeneratedFile( "\n\031google/protobuf/any.proto\022\017google.prot" "obuf\"&\n\003Any\022\020\n\010type_url\030\001 \001(\t\022\r\n\005value\030\002" - " \001(\014Br\n\023com.google.protobufB\010AnyProtoP\001Z" - "%github.com/golang/protobuf/ptypes/any\240\001" - "\001\242\002\003GPB\252\002\036Google.Protobuf.WellKnownTypes" - "b\006proto3", 208); + " \001(\014Bo\n\023com.google.protobufB\010AnyProtoP\001Z" + "%github.com/golang/protobuf/ptypes/any\242\002" + "\003GPB\252\002\036Google.Protobuf.WellKnownTypesb\006p" + "roto3", 205); ::google::protobuf::MessageFactory::InternalRegisterGeneratedFile( "google/protobuf/any.proto", &protobuf_RegisterTypes); - Any::default_instance_ = new Any(); - Any::default_instance_->InitAsDefaultInstance(); ::google::protobuf::internal::OnShutdown(&protobuf_ShutdownFile_google_2fprotobuf_2fany_2eproto); } +GOOGLE_PROTOBUF_DECLARE_ONCE(protobuf_AddDesc_google_2fprotobuf_2fany_2eproto_once_); +void protobuf_AddDesc_google_2fprotobuf_2fany_2eproto() { + ::google::protobuf::GoogleOnceInit(&protobuf_AddDesc_google_2fprotobuf_2fany_2eproto_once_, + &protobuf_AddDesc_google_2fprotobuf_2fany_2eproto_impl); +} // Force AddDescriptors() to be called at static initialization time. struct StaticDescriptorInitializer_google_2fprotobuf_2fany_2eproto { StaticDescriptorInitializer_google_2fprotobuf_2fany_2eproto() { @@ -104,6 +115,16 @@ struct StaticDescriptorInitializer_google_2fprotobuf_2fany_2eproto { } } static_descriptor_initializer_google_2fprotobuf_2fany_2eproto_; +namespace { + +static void MergeFromFail(int line) GOOGLE_ATTRIBUTE_COLD GOOGLE_ATTRIBUTE_NORETURN; +static void MergeFromFail(int line) { + ::google::protobuf::internal::MergeFromFail(__FILE__, line); +} + +} // namespace + + // =================================================================== void Any::PackFrom(const ::google::protobuf::Message& message) { @@ -126,12 +147,12 @@ const int Any::kValueFieldNumber; Any::Any() : ::google::protobuf::Message(), _internal_metadata_(NULL), _any_metadata_(&type_url_, &value_) { + if (this != internal_default_instance()) protobuf_InitDefaults_google_2fprotobuf_2fany_2eproto(); SharedCtor(); // @@protoc_insertion_point(constructor:google.protobuf.Any) } void Any::InitAsDefaultInstance() { - _is_default_instance_ = true; } Any::Any(const Any& from) @@ -139,16 +160,14 @@ Any::Any(const Any& from) _internal_metadata_(NULL), _any_metadata_(&type_url_, &value_) { SharedCtor(); - MergeFrom(from); + UnsafeMergeFrom(from); // @@protoc_insertion_point(copy_constructor:google.protobuf.Any) } void Any::SharedCtor() { - _is_default_instance_ = false; - ::google::protobuf::internal::GetEmptyString(); - _cached_size_ = 0; type_url_.UnsafeSetDefault(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); value_.UnsafeSetDefault(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); + _cached_size_ = 0; } Any::~Any() { @@ -159,8 +178,6 @@ Any::~Any() { void Any::SharedDtor() { type_url_.DestroyNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); value_.DestroyNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); - if (this != default_instance_) { - } } void Any::SetCachedSize(int size) const { @@ -174,11 +191,11 @@ const ::google::protobuf::Descriptor* Any::descriptor() { } const Any& Any::default_instance() { - if (default_instance_ == NULL) protobuf_AddDesc_google_2fprotobuf_2fany_2eproto(); - return *default_instance_; + protobuf_InitDefaults_google_2fprotobuf_2fany_2eproto(); + return *internal_default_instance(); } -Any* Any::default_instance_ = NULL; +::google::protobuf::internal::ExplicitlyConstructed Any::default_instance_; Any* Any::New(::google::protobuf::Arena* arena) const { Any* n = new Any; @@ -302,9 +319,9 @@ void Any::SerializeWithCachedSizes( return target; } -int Any::ByteSize() const { +size_t Any::ByteSizeLong() const { // @@protoc_insertion_point(message_byte_size_start:google.protobuf.Any) - int total_size = 0; + size_t total_size = 0; // optional string type_url = 1; if (this->type_url().size() > 0) { @@ -320,18 +337,17 @@ int Any::ByteSize() const { this->value()); } + int cached_size = ::google::protobuf::internal::ToCachedSize(total_size); GOOGLE_SAFE_CONCURRENT_WRITES_BEGIN(); - _cached_size_ = total_size; + _cached_size_ = cached_size; GOOGLE_SAFE_CONCURRENT_WRITES_END(); return total_size; } void Any::MergeFrom(const ::google::protobuf::Message& from) { // @@protoc_insertion_point(generalized_merge_from_start:google.protobuf.Any) - if (GOOGLE_PREDICT_FALSE(&from == this)) { - ::google::protobuf::internal::MergeFromFail(__FILE__, __LINE__); - } - const Any* source = + if (GOOGLE_PREDICT_FALSE(&from == this)) MergeFromFail(__LINE__); + const Any* source = ::google::protobuf::internal::DynamicCastToGenerated( &from); if (source == NULL) { @@ -339,15 +355,21 @@ void Any::MergeFrom(const ::google::protobuf::Message& from) { ::google::protobuf::internal::ReflectionOps::Merge(from, this); } else { // @@protoc_insertion_point(generalized_merge_from_cast_success:google.protobuf.Any) - MergeFrom(*source); + UnsafeMergeFrom(*source); } } void Any::MergeFrom(const Any& from) { // @@protoc_insertion_point(class_specific_merge_from_start:google.protobuf.Any) - if (GOOGLE_PREDICT_FALSE(&from == this)) { - ::google::protobuf::internal::MergeFromFail(__FILE__, __LINE__); + if (GOOGLE_PREDICT_TRUE(&from != this)) { + UnsafeMergeFrom(from); + } else { + MergeFromFail(__LINE__); } +} + +void Any::UnsafeMergeFrom(const Any& from) { + GOOGLE_DCHECK(&from != this); if (from.type_url().size() > 0) { type_url_.AssignWithDefault(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), from.type_url_); @@ -369,7 +391,7 @@ void Any::CopyFrom(const Any& from) { // @@protoc_insertion_point(class_specific_copy_from_start:google.protobuf.Any) if (&from == this) return; Clear(); - MergeFrom(from); + UnsafeMergeFrom(from); } bool Any::IsInitialized() const { @@ -403,37 +425,37 @@ void Any::InternalSwap(Any* other) { void Any::clear_type_url() { type_url_.ClearToEmptyNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); } - const ::std::string& Any::type_url() const { +const ::std::string& Any::type_url() const { // @@protoc_insertion_point(field_get:google.protobuf.Any.type_url) return type_url_.GetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); } - void Any::set_type_url(const ::std::string& value) { +void Any::set_type_url(const ::std::string& value) { type_url_.SetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), value); // @@protoc_insertion_point(field_set:google.protobuf.Any.type_url) } - void Any::set_type_url(const char* value) { +void Any::set_type_url(const char* value) { type_url_.SetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), ::std::string(value)); // @@protoc_insertion_point(field_set_char:google.protobuf.Any.type_url) } - void Any::set_type_url(const char* value, size_t size) { +void Any::set_type_url(const char* value, size_t size) { type_url_.SetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), ::std::string(reinterpret_cast(value), size)); // @@protoc_insertion_point(field_set_pointer:google.protobuf.Any.type_url) } - ::std::string* Any::mutable_type_url() { +::std::string* Any::mutable_type_url() { // @@protoc_insertion_point(field_mutable:google.protobuf.Any.type_url) return type_url_.MutableNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); } - ::std::string* Any::release_type_url() { +::std::string* Any::release_type_url() { // @@protoc_insertion_point(field_release:google.protobuf.Any.type_url) return type_url_.ReleaseNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); } - void Any::set_allocated_type_url(::std::string* type_url) { +void Any::set_allocated_type_url(::std::string* type_url) { if (type_url != NULL) { } else { @@ -447,37 +469,37 @@ void Any::clear_type_url() { void Any::clear_value() { value_.ClearToEmptyNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); } - const ::std::string& Any::value() const { +const ::std::string& Any::value() const { // @@protoc_insertion_point(field_get:google.protobuf.Any.value) return value_.GetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); } - void Any::set_value(const ::std::string& value) { +void Any::set_value(const ::std::string& value) { value_.SetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), value); // @@protoc_insertion_point(field_set:google.protobuf.Any.value) } - void Any::set_value(const char* value) { +void Any::set_value(const char* value) { value_.SetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), ::std::string(value)); // @@protoc_insertion_point(field_set_char:google.protobuf.Any.value) } - void Any::set_value(const void* value, size_t size) { +void Any::set_value(const void* value, size_t size) { value_.SetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), ::std::string(reinterpret_cast(value), size)); // @@protoc_insertion_point(field_set_pointer:google.protobuf.Any.value) } - ::std::string* Any::mutable_value() { +::std::string* Any::mutable_value() { // @@protoc_insertion_point(field_mutable:google.protobuf.Any.value) return value_.MutableNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); } - ::std::string* Any::release_value() { +::std::string* Any::release_value() { // @@protoc_insertion_point(field_release:google.protobuf.Any.value) return value_.ReleaseNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); } - void Any::set_allocated_value(::std::string* value) { +void Any::set_allocated_value(::std::string* value) { if (value != NULL) { } else { diff --git a/src/google/protobuf/any.pb.h b/src/google/protobuf/any.pb.h index 4ccdfb24..e4061bc7 100644 --- a/src/google/protobuf/any.pb.h +++ b/src/google/protobuf/any.pb.h @@ -35,6 +35,7 @@ namespace protobuf { // Internal implementation detail -- do not call these. void LIBPROTOBUF_EXPORT protobuf_AddDesc_google_2fprotobuf_2fany_2eproto(); +void LIBPROTOBUF_EXPORT protobuf_InitDefaults_google_2fprotobuf_2fany_2eproto(); void protobuf_AssignDesc_google_2fprotobuf_2fany_2eproto(); void protobuf_ShutdownFile_google_2fprotobuf_2fany_2eproto(); @@ -57,6 +58,10 @@ class LIBPROTOBUF_EXPORT Any : public ::google::protobuf::Message /* @@protoc_in static const ::google::protobuf::Descriptor* descriptor(); static const Any& default_instance(); + static inline const Any* internal_default_instance() { + return &default_instance_.get(); + } + // implements Any ----------------------------------------------- void PackFrom(const ::google::protobuf::Message& message); @@ -81,7 +86,7 @@ class LIBPROTOBUF_EXPORT Any : public ::google::protobuf::Message /* @@protoc_in void Clear(); bool IsInitialized() const; - int ByteSize() const; + size_t ByteSizeLong() const; bool MergePartialFromCodedStream( ::google::protobuf::io::CodedInputStream* input); void SerializeWithCachedSizes( @@ -97,6 +102,7 @@ class LIBPROTOBUF_EXPORT Any : public ::google::protobuf::Message /* @@protoc_in void SharedDtor(); void SetCachedSize(int size) const; void InternalSwap(Any* other); + void UnsafeMergeFrom(const Any& from); private: inline ::google::protobuf::Arena* GetArenaNoVirtual() const { return _internal_metadata_.arena(); @@ -138,17 +144,17 @@ class LIBPROTOBUF_EXPORT Any : public ::google::protobuf::Message /* @@protoc_in private: ::google::protobuf::internal::InternalMetadataWithArena _internal_metadata_; - bool _is_default_instance_; ::google::protobuf::internal::ArenaStringPtr type_url_; ::google::protobuf::internal::ArenaStringPtr value_; mutable int _cached_size_; ::google::protobuf::internal::AnyMetadata _any_metadata_; - friend void LIBPROTOBUF_EXPORT protobuf_AddDesc_google_2fprotobuf_2fany_2eproto(); + friend void LIBPROTOBUF_EXPORT protobuf_InitDefaults_google_2fprotobuf_2fany_2eproto_impl(); + friend void LIBPROTOBUF_EXPORT protobuf_AddDesc_google_2fprotobuf_2fany_2eproto_impl(); friend void protobuf_AssignDesc_google_2fprotobuf_2fany_2eproto(); friend void protobuf_ShutdownFile_google_2fprotobuf_2fany_2eproto(); void InitAsDefaultInstance(); - static Any* default_instance_; + static ::google::protobuf::internal::ExplicitlyConstructed default_instance_; }; // =================================================================== diff --git a/src/google/protobuf/any.proto b/src/google/protobuf/any.proto index 81dcf46c..9bd3f50a 100644 --- a/src/google/protobuf/any.proto +++ b/src/google/protobuf/any.proto @@ -37,7 +37,6 @@ option go_package = "github.com/golang/protobuf/ptypes/any"; option java_package = "com.google.protobuf"; option java_outer_classname = "AnyProto"; option java_multiple_files = true; -option java_generate_equals_and_hash = true; option objc_class_prefix = "GPB"; // `Any` contains an arbitrary serialized protocol buffer message along with a diff --git a/src/google/protobuf/api.pb.cc b/src/google/protobuf/api.pb.cc index d7fb644c..bd85bbdb 100644 --- a/src/google/protobuf/api.pb.cc +++ b/src/google/protobuf/api.pb.cc @@ -55,14 +55,13 @@ void protobuf_AssignDesc_google_2fprotobuf_2fapi_2eproto() { Api_reflection_ = ::google::protobuf::internal::GeneratedMessageReflection::NewGeneratedMessageReflection( Api_descriptor_, - Api::default_instance_, + Api::internal_default_instance(), Api_offsets_, -1, -1, -1, sizeof(Api), - GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(Api, _internal_metadata_), - GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(Api, _is_default_instance_)); + GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(Api, _internal_metadata_)); Method_descriptor_ = file->message_type(1); static const int Method_offsets_[7] = { GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(Method, name_), @@ -76,14 +75,13 @@ void protobuf_AssignDesc_google_2fprotobuf_2fapi_2eproto() { Method_reflection_ = ::google::protobuf::internal::GeneratedMessageReflection::NewGeneratedMessageReflection( Method_descriptor_, - Method::default_instance_, + Method::internal_default_instance(), Method_offsets_, -1, -1, -1, sizeof(Method), - GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(Method, _internal_metadata_), - GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(Method, _is_default_instance_)); + GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(Method, _internal_metadata_)); Mixin_descriptor_ = file->message_type(2); static const int Mixin_offsets_[2] = { GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(Mixin, name_), @@ -92,20 +90,19 @@ void protobuf_AssignDesc_google_2fprotobuf_2fapi_2eproto() { Mixin_reflection_ = ::google::protobuf::internal::GeneratedMessageReflection::NewGeneratedMessageReflection( Mixin_descriptor_, - Mixin::default_instance_, + Mixin::internal_default_instance(), Mixin_offsets_, -1, -1, -1, sizeof(Mixin), - GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(Mixin, _internal_metadata_), - GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(Mixin, _is_default_instance_)); + GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(Mixin, _internal_metadata_)); } namespace { GOOGLE_PROTOBUF_DECLARE_ONCE(protobuf_AssignDescriptors_once_); -inline void protobuf_AssignDescriptorsOnce() { +void protobuf_AssignDescriptorsOnce() { ::google::protobuf::GoogleOnceInit(&protobuf_AssignDescriptors_once_, &protobuf_AssignDesc_google_2fprotobuf_2fapi_2eproto); } @@ -114,33 +111,46 @@ void protobuf_RegisterTypes(const ::std::string&) GOOGLE_ATTRIBUTE_COLD; void protobuf_RegisterTypes(const ::std::string&) { protobuf_AssignDescriptorsOnce(); ::google::protobuf::MessageFactory::InternalRegisterGeneratedMessage( - Api_descriptor_, &Api::default_instance()); + Api_descriptor_, Api::internal_default_instance()); ::google::protobuf::MessageFactory::InternalRegisterGeneratedMessage( - Method_descriptor_, &Method::default_instance()); + Method_descriptor_, Method::internal_default_instance()); ::google::protobuf::MessageFactory::InternalRegisterGeneratedMessage( - Mixin_descriptor_, &Mixin::default_instance()); + Mixin_descriptor_, Mixin::internal_default_instance()); } } // namespace void protobuf_ShutdownFile_google_2fprotobuf_2fapi_2eproto() { - delete Api::default_instance_; delete Api_reflection_; - delete Method::default_instance_; delete Method_reflection_; - delete Mixin::default_instance_; delete Mixin_reflection_; } -void protobuf_AddDesc_google_2fprotobuf_2fapi_2eproto() GOOGLE_ATTRIBUTE_COLD; -void protobuf_AddDesc_google_2fprotobuf_2fapi_2eproto() { - static bool already_here = false; - if (already_here) return; - already_here = true; +void protobuf_InitDefaults_google_2fprotobuf_2fapi_2eproto_impl() { GOOGLE_PROTOBUF_VERIFY_VERSION; - ::google::protobuf::protobuf_AddDesc_google_2fprotobuf_2fsource_5fcontext_2eproto(); - ::google::protobuf::protobuf_AddDesc_google_2fprotobuf_2ftype_2eproto(); + ::google::protobuf::protobuf_InitDefaults_google_2fprotobuf_2fsource_5fcontext_2eproto(); + ::google::protobuf::protobuf_InitDefaults_google_2fprotobuf_2ftype_2eproto(); + ::google::protobuf::internal::GetEmptyString(); + Api::default_instance_.DefaultConstruct(); + ::google::protobuf::internal::GetEmptyString(); + Method::default_instance_.DefaultConstruct(); + ::google::protobuf::internal::GetEmptyString(); + Mixin::default_instance_.DefaultConstruct(); + Api::default_instance_.get_mutable()->InitAsDefaultInstance(); + Method::default_instance_.get_mutable()->InitAsDefaultInstance(); + Mixin::default_instance_.get_mutable()->InitAsDefaultInstance(); +} + +GOOGLE_PROTOBUF_DECLARE_ONCE(protobuf_InitDefaults_google_2fprotobuf_2fapi_2eproto_once_); +void protobuf_InitDefaults_google_2fprotobuf_2fapi_2eproto() { + ::google::protobuf::GoogleOnceInit(&protobuf_InitDefaults_google_2fprotobuf_2fapi_2eproto_once_, + &protobuf_InitDefaults_google_2fprotobuf_2fapi_2eproto_impl); +} +void protobuf_AddDesc_google_2fprotobuf_2fapi_2eproto_impl() { + GOOGLE_PROTOBUF_VERIFY_VERSION; + + protobuf_InitDefaults_google_2fprotobuf_2fapi_2eproto(); ::google::protobuf::DescriptorPool::InternalAddGeneratedFile( "\n\031google/protobuf/api.proto\022\017google.prot" "obuf\032$google/protobuf/source_context.pro" @@ -157,20 +167,21 @@ void protobuf_AddDesc_google_2fprotobuf_2fapi_2eproto() { "esponse_streaming\030\005 \001(\010\022(\n\007options\030\006 \003(\013" "2\027.google.protobuf.Option\022\'\n\006syntax\030\007 \001(" "\0162\027.google.protobuf.Syntax\"#\n\005Mixin\022\014\n\004n" - "ame\030\001 \001(\t\022\014\n\004root\030\002 \001(\tBK\n\023com.google.pr" - "otobufB\010ApiProtoP\001\240\001\001\242\002\003GPB\252\002\036Google.Pro" - "tobuf.WellKnownTypesb\006proto3", 708); + "ame\030\001 \001(\t\022\014\n\004root\030\002 \001(\tBH\n\023com.google.pr" + "otobufB\010ApiProtoP\001\242\002\003GPB\252\002\036Google.Protob" + "uf.WellKnownTypesb\006proto3", 705); ::google::protobuf::MessageFactory::InternalRegisterGeneratedFile( "google/protobuf/api.proto", &protobuf_RegisterTypes); - Api::default_instance_ = new Api(); - Method::default_instance_ = new Method(); - Mixin::default_instance_ = new Mixin(); - Api::default_instance_->InitAsDefaultInstance(); - Method::default_instance_->InitAsDefaultInstance(); - Mixin::default_instance_->InitAsDefaultInstance(); + ::google::protobuf::protobuf_AddDesc_google_2fprotobuf_2fsource_5fcontext_2eproto(); + ::google::protobuf::protobuf_AddDesc_google_2fprotobuf_2ftype_2eproto(); ::google::protobuf::internal::OnShutdown(&protobuf_ShutdownFile_google_2fprotobuf_2fapi_2eproto); } +GOOGLE_PROTOBUF_DECLARE_ONCE(protobuf_AddDesc_google_2fprotobuf_2fapi_2eproto_once_); +void protobuf_AddDesc_google_2fprotobuf_2fapi_2eproto() { + ::google::protobuf::GoogleOnceInit(&protobuf_AddDesc_google_2fprotobuf_2fapi_2eproto_once_, + &protobuf_AddDesc_google_2fprotobuf_2fapi_2eproto_impl); +} // Force AddDescriptors() to be called at static initialization time. struct StaticDescriptorInitializer_google_2fprotobuf_2fapi_2eproto { StaticDescriptorInitializer_google_2fprotobuf_2fapi_2eproto() { @@ -178,6 +189,16 @@ struct StaticDescriptorInitializer_google_2fprotobuf_2fapi_2eproto { } } static_descriptor_initializer_google_2fprotobuf_2fapi_2eproto_; +namespace { + +static void MergeFromFail(int line) GOOGLE_ATTRIBUTE_COLD GOOGLE_ATTRIBUTE_NORETURN; +static void MergeFromFail(int line) { + ::google::protobuf::internal::MergeFromFail(__FILE__, line); +} + +} // namespace + + // =================================================================== #if !defined(_MSC_VER) || _MSC_VER >= 1900 @@ -192,31 +213,30 @@ const int Api::kSyntaxFieldNumber; Api::Api() : ::google::protobuf::Message(), _internal_metadata_(NULL) { + if (this != internal_default_instance()) protobuf_InitDefaults_google_2fprotobuf_2fapi_2eproto(); SharedCtor(); // @@protoc_insertion_point(constructor:google.protobuf.Api) } void Api::InitAsDefaultInstance() { - _is_default_instance_ = true; - source_context_ = const_cast< ::google::protobuf::SourceContext*>(&::google::protobuf::SourceContext::default_instance()); + source_context_ = const_cast< ::google::protobuf::SourceContext*>( + ::google::protobuf::SourceContext::internal_default_instance()); } Api::Api(const Api& from) : ::google::protobuf::Message(), _internal_metadata_(NULL) { SharedCtor(); - MergeFrom(from); + UnsafeMergeFrom(from); // @@protoc_insertion_point(copy_constructor:google.protobuf.Api) } void Api::SharedCtor() { - _is_default_instance_ = false; - ::google::protobuf::internal::GetEmptyString(); - _cached_size_ = 0; name_.UnsafeSetDefault(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); version_.UnsafeSetDefault(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); source_context_ = NULL; syntax_ = 0; + _cached_size_ = 0; } Api::~Api() { @@ -227,9 +247,7 @@ Api::~Api() { void Api::SharedDtor() { name_.DestroyNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); version_.DestroyNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); - if (this != default_instance_) { - delete source_context_; - } + delete source_context_; } void Api::SetCachedSize(int size) const { @@ -243,11 +261,11 @@ const ::google::protobuf::Descriptor* Api::descriptor() { } const Api& Api::default_instance() { - if (default_instance_ == NULL) protobuf_AddDesc_google_2fprotobuf_2fapi_2eproto(); - return *default_instance_; + protobuf_InitDefaults_google_2fprotobuf_2fapi_2eproto(); + return *internal_default_instance(); } -Api* Api::default_instance_ = NULL; +::google::protobuf::internal::ExplicitlyConstructed Api::default_instance_; Api* Api::New(::google::protobuf::Arena* arena) const { Api* n = new Api; @@ -532,9 +550,9 @@ void Api::SerializeWithCachedSizes( return target; } -int Api::ByteSize() const { +size_t Api::ByteSizeLong() const { // @@protoc_insertion_point(message_byte_size_start:google.protobuf.Api) - int total_size = 0; + size_t total_size = 0; // optional string name = 1; if (this->name().size() > 0) { @@ -564,41 +582,49 @@ int Api::ByteSize() const { } // repeated .google.protobuf.Method methods = 2; - total_size += 1 * this->methods_size(); - for (int i = 0; i < this->methods_size(); i++) { - total_size += - ::google::protobuf::internal::WireFormatLite::MessageSizeNoVirtual( - this->methods(i)); + { + unsigned int count = this->methods_size(); + total_size += 1UL * count; + for (unsigned int i = 0; i < count; i++) { + total_size += + ::google::protobuf::internal::WireFormatLite::MessageSizeNoVirtual( + this->methods(i)); + } } // repeated .google.protobuf.Option options = 3; - total_size += 1 * this->options_size(); - for (int i = 0; i < this->options_size(); i++) { - total_size += - ::google::protobuf::internal::WireFormatLite::MessageSizeNoVirtual( - this->options(i)); + { + unsigned int count = this->options_size(); + total_size += 1UL * count; + for (unsigned int i = 0; i < count; i++) { + total_size += + ::google::protobuf::internal::WireFormatLite::MessageSizeNoVirtual( + this->options(i)); + } } // repeated .google.protobuf.Mixin mixins = 6; - total_size += 1 * this->mixins_size(); - for (int i = 0; i < this->mixins_size(); i++) { - total_size += - ::google::protobuf::internal::WireFormatLite::MessageSizeNoVirtual( - this->mixins(i)); + { + unsigned int count = this->mixins_size(); + total_size += 1UL * count; + for (unsigned int i = 0; i < count; i++) { + total_size += + ::google::protobuf::internal::WireFormatLite::MessageSizeNoVirtual( + this->mixins(i)); + } } + int cached_size = ::google::protobuf::internal::ToCachedSize(total_size); GOOGLE_SAFE_CONCURRENT_WRITES_BEGIN(); - _cached_size_ = total_size; + _cached_size_ = cached_size; GOOGLE_SAFE_CONCURRENT_WRITES_END(); return total_size; } void Api::MergeFrom(const ::google::protobuf::Message& from) { // @@protoc_insertion_point(generalized_merge_from_start:google.protobuf.Api) - if (GOOGLE_PREDICT_FALSE(&from == this)) { - ::google::protobuf::internal::MergeFromFail(__FILE__, __LINE__); - } - const Api* source = + if (GOOGLE_PREDICT_FALSE(&from == this)) MergeFromFail(__LINE__); + const Api* source = ::google::protobuf::internal::DynamicCastToGenerated( &from); if (source == NULL) { @@ -606,15 +632,21 @@ void Api::MergeFrom(const ::google::protobuf::Message& from) { ::google::protobuf::internal::ReflectionOps::Merge(from, this); } else { // @@protoc_insertion_point(generalized_merge_from_cast_success:google.protobuf.Api) - MergeFrom(*source); + UnsafeMergeFrom(*source); } } void Api::MergeFrom(const Api& from) { // @@protoc_insertion_point(class_specific_merge_from_start:google.protobuf.Api) - if (GOOGLE_PREDICT_FALSE(&from == this)) { - ::google::protobuf::internal::MergeFromFail(__FILE__, __LINE__); + if (GOOGLE_PREDICT_TRUE(&from != this)) { + UnsafeMergeFrom(from); + } else { + MergeFromFail(__LINE__); } +} + +void Api::UnsafeMergeFrom(const Api& from) { + GOOGLE_DCHECK(&from != this); methods_.MergeFrom(from.methods_); options_.MergeFrom(from.options_); mixins_.MergeFrom(from.mixins_); @@ -645,7 +677,7 @@ void Api::CopyFrom(const Api& from) { // @@protoc_insertion_point(class_specific_copy_from_start:google.protobuf.Api) if (&from == this) return; Clear(); - MergeFrom(from); + UnsafeMergeFrom(from); } bool Api::IsInitialized() const { @@ -684,37 +716,37 @@ void Api::InternalSwap(Api* other) { void Api::clear_name() { name_.ClearToEmptyNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); } - const ::std::string& Api::name() const { +const ::std::string& Api::name() const { // @@protoc_insertion_point(field_get:google.protobuf.Api.name) return name_.GetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); } - void Api::set_name(const ::std::string& value) { +void Api::set_name(const ::std::string& value) { name_.SetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), value); // @@protoc_insertion_point(field_set:google.protobuf.Api.name) } - void Api::set_name(const char* value) { +void Api::set_name(const char* value) { name_.SetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), ::std::string(value)); // @@protoc_insertion_point(field_set_char:google.protobuf.Api.name) } - void Api::set_name(const char* value, size_t size) { +void Api::set_name(const char* value, size_t size) { name_.SetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), ::std::string(reinterpret_cast(value), size)); // @@protoc_insertion_point(field_set_pointer:google.protobuf.Api.name) } - ::std::string* Api::mutable_name() { +::std::string* Api::mutable_name() { // @@protoc_insertion_point(field_mutable:google.protobuf.Api.name) return name_.MutableNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); } - ::std::string* Api::release_name() { +::std::string* Api::release_name() { // @@protoc_insertion_point(field_release:google.protobuf.Api.name) return name_.ReleaseNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); } - void Api::set_allocated_name(::std::string* name) { +void Api::set_allocated_name(::std::string* name) { if (name != NULL) { } else { @@ -788,37 +820,37 @@ Api::options() const { void Api::clear_version() { version_.ClearToEmptyNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); } - const ::std::string& Api::version() const { +const ::std::string& Api::version() const { // @@protoc_insertion_point(field_get:google.protobuf.Api.version) return version_.GetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); } - void Api::set_version(const ::std::string& value) { +void Api::set_version(const ::std::string& value) { version_.SetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), value); // @@protoc_insertion_point(field_set:google.protobuf.Api.version) } - void Api::set_version(const char* value) { +void Api::set_version(const char* value) { version_.SetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), ::std::string(value)); // @@protoc_insertion_point(field_set_char:google.protobuf.Api.version) } - void Api::set_version(const char* value, size_t size) { +void Api::set_version(const char* value, size_t size) { version_.SetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), ::std::string(reinterpret_cast(value), size)); // @@protoc_insertion_point(field_set_pointer:google.protobuf.Api.version) } - ::std::string* Api::mutable_version() { +::std::string* Api::mutable_version() { // @@protoc_insertion_point(field_mutable:google.protobuf.Api.version) return version_.MutableNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); } - ::std::string* Api::release_version() { +::std::string* Api::release_version() { // @@protoc_insertion_point(field_release:google.protobuf.Api.version) return version_.ReleaseNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); } - void Api::set_allocated_version(::std::string* version) { +void Api::set_allocated_version(::std::string* version) { if (version != NULL) { } else { @@ -830,7 +862,7 @@ void Api::clear_version() { // optional .google.protobuf.SourceContext source_context = 5; bool Api::has_source_context() const { - return !_is_default_instance_ && source_context_ != NULL; + return this != internal_default_instance() && source_context_ != NULL; } void Api::clear_source_context() { if (GetArenaNoVirtual() == NULL && source_context_ != NULL) delete source_context_; @@ -838,7 +870,8 @@ void Api::clear_source_context() { } const ::google::protobuf::SourceContext& Api::source_context() const { // @@protoc_insertion_point(field_get:google.protobuf.Api.source_context) - return source_context_ != NULL ? *source_context_ : *default_instance_->source_context_; + return source_context_ != NULL ? *source_context_ + : *::google::protobuf::SourceContext::internal_default_instance(); } ::google::protobuf::SourceContext* Api::mutable_source_context() { @@ -900,11 +933,11 @@ Api::mixins() const { void Api::clear_syntax() { syntax_ = 0; } - ::google::protobuf::Syntax Api::syntax() const { +::google::protobuf::Syntax Api::syntax() const { // @@protoc_insertion_point(field_get:google.protobuf.Api.syntax) return static_cast< ::google::protobuf::Syntax >(syntax_); } - void Api::set_syntax(::google::protobuf::Syntax value) { +void Api::set_syntax(::google::protobuf::Syntax value) { syntax_ = value; // @@protoc_insertion_point(field_set:google.protobuf.Api.syntax) @@ -926,32 +959,29 @@ const int Method::kSyntaxFieldNumber; Method::Method() : ::google::protobuf::Message(), _internal_metadata_(NULL) { + if (this != internal_default_instance()) protobuf_InitDefaults_google_2fprotobuf_2fapi_2eproto(); SharedCtor(); // @@protoc_insertion_point(constructor:google.protobuf.Method) } void Method::InitAsDefaultInstance() { - _is_default_instance_ = true; } Method::Method(const Method& from) : ::google::protobuf::Message(), _internal_metadata_(NULL) { SharedCtor(); - MergeFrom(from); + UnsafeMergeFrom(from); // @@protoc_insertion_point(copy_constructor:google.protobuf.Method) } void Method::SharedCtor() { - _is_default_instance_ = false; - ::google::protobuf::internal::GetEmptyString(); - _cached_size_ = 0; name_.UnsafeSetDefault(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); request_type_url_.UnsafeSetDefault(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); - request_streaming_ = false; response_type_url_.UnsafeSetDefault(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); - response_streaming_ = false; - syntax_ = 0; + ::memset(&request_streaming_, 0, reinterpret_cast(&syntax_) - + reinterpret_cast(&request_streaming_) + sizeof(syntax_)); + _cached_size_ = 0; } Method::~Method() { @@ -963,8 +993,6 @@ void Method::SharedDtor() { name_.DestroyNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); request_type_url_.DestroyNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); response_type_url_.DestroyNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); - if (this != default_instance_) { - } } void Method::SetCachedSize(int size) const { @@ -978,11 +1006,11 @@ const ::google::protobuf::Descriptor* Method::descriptor() { } const Method& Method::default_instance() { - if (default_instance_ == NULL) protobuf_AddDesc_google_2fprotobuf_2fapi_2eproto(); - return *default_instance_; + protobuf_InitDefaults_google_2fprotobuf_2fapi_2eproto(); + return *internal_default_instance(); } -Method* Method::default_instance_ = NULL; +::google::protobuf::internal::ExplicitlyConstructed Method::default_instance_; Method* Method::New(::google::protobuf::Arena* arena) const { Method* n = new Method; @@ -1068,10 +1096,10 @@ bool Method::MergePartialFromCodedStream( case 3: { if (tag == 24) { parse_request_streaming: + DO_((::google::protobuf::internal::WireFormatLite::ReadPrimitive< bool, ::google::protobuf::internal::WireFormatLite::TYPE_BOOL>( input, &request_streaming_))); - } else { goto handle_unusual; } @@ -1100,10 +1128,10 @@ bool Method::MergePartialFromCodedStream( case 5: { if (tag == 40) { parse_response_streaming: + DO_((::google::protobuf::internal::WireFormatLite::ReadPrimitive< bool, ::google::protobuf::internal::WireFormatLite::TYPE_BOOL>( input, &response_streaming_))); - } else { goto handle_unusual; } @@ -1287,9 +1315,9 @@ void Method::SerializeWithCachedSizes( return target; } -int Method::ByteSize() const { +size_t Method::ByteSizeLong() const { // @@protoc_insertion_point(message_byte_size_start:google.protobuf.Method) - int total_size = 0; + size_t total_size = 0; // optional string name = 1; if (this->name().size() > 0) { @@ -1329,25 +1357,27 @@ int Method::ByteSize() const { } // repeated .google.protobuf.Option options = 6; - total_size += 1 * this->options_size(); - for (int i = 0; i < this->options_size(); i++) { - total_size += - ::google::protobuf::internal::WireFormatLite::MessageSizeNoVirtual( - this->options(i)); + { + unsigned int count = this->options_size(); + total_size += 1UL * count; + for (unsigned int i = 0; i < count; i++) { + total_size += + ::google::protobuf::internal::WireFormatLite::MessageSizeNoVirtual( + this->options(i)); + } } + int cached_size = ::google::protobuf::internal::ToCachedSize(total_size); GOOGLE_SAFE_CONCURRENT_WRITES_BEGIN(); - _cached_size_ = total_size; + _cached_size_ = cached_size; GOOGLE_SAFE_CONCURRENT_WRITES_END(); return total_size; } void Method::MergeFrom(const ::google::protobuf::Message& from) { // @@protoc_insertion_point(generalized_merge_from_start:google.protobuf.Method) - if (GOOGLE_PREDICT_FALSE(&from == this)) { - ::google::protobuf::internal::MergeFromFail(__FILE__, __LINE__); - } - const Method* source = + if (GOOGLE_PREDICT_FALSE(&from == this)) MergeFromFail(__LINE__); + const Method* source = ::google::protobuf::internal::DynamicCastToGenerated( &from); if (source == NULL) { @@ -1355,15 +1385,21 @@ void Method::MergeFrom(const ::google::protobuf::Message& from) { ::google::protobuf::internal::ReflectionOps::Merge(from, this); } else { // @@protoc_insertion_point(generalized_merge_from_cast_success:google.protobuf.Method) - MergeFrom(*source); + UnsafeMergeFrom(*source); } } void Method::MergeFrom(const Method& from) { // @@protoc_insertion_point(class_specific_merge_from_start:google.protobuf.Method) - if (GOOGLE_PREDICT_FALSE(&from == this)) { - ::google::protobuf::internal::MergeFromFail(__FILE__, __LINE__); + if (GOOGLE_PREDICT_TRUE(&from != this)) { + UnsafeMergeFrom(from); + } else { + MergeFromFail(__LINE__); } +} + +void Method::UnsafeMergeFrom(const Method& from) { + GOOGLE_DCHECK(&from != this); options_.MergeFrom(from.options_); if (from.name().size() > 0) { @@ -1399,7 +1435,7 @@ void Method::CopyFrom(const Method& from) { // @@protoc_insertion_point(class_specific_copy_from_start:google.protobuf.Method) if (&from == this) return; Clear(); - MergeFrom(from); + UnsafeMergeFrom(from); } bool Method::IsInitialized() const { @@ -1438,37 +1474,37 @@ void Method::InternalSwap(Method* other) { void Method::clear_name() { name_.ClearToEmptyNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); } - const ::std::string& Method::name() const { +const ::std::string& Method::name() const { // @@protoc_insertion_point(field_get:google.protobuf.Method.name) return name_.GetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); } - void Method::set_name(const ::std::string& value) { +void Method::set_name(const ::std::string& value) { name_.SetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), value); // @@protoc_insertion_point(field_set:google.protobuf.Method.name) } - void Method::set_name(const char* value) { +void Method::set_name(const char* value) { name_.SetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), ::std::string(value)); // @@protoc_insertion_point(field_set_char:google.protobuf.Method.name) } - void Method::set_name(const char* value, size_t size) { +void Method::set_name(const char* value, size_t size) { name_.SetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), ::std::string(reinterpret_cast(value), size)); // @@protoc_insertion_point(field_set_pointer:google.protobuf.Method.name) } - ::std::string* Method::mutable_name() { +::std::string* Method::mutable_name() { // @@protoc_insertion_point(field_mutable:google.protobuf.Method.name) return name_.MutableNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); } - ::std::string* Method::release_name() { +::std::string* Method::release_name() { // @@protoc_insertion_point(field_release:google.protobuf.Method.name) return name_.ReleaseNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); } - void Method::set_allocated_name(::std::string* name) { +void Method::set_allocated_name(::std::string* name) { if (name != NULL) { } else { @@ -1482,37 +1518,37 @@ void Method::clear_name() { void Method::clear_request_type_url() { request_type_url_.ClearToEmptyNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); } - const ::std::string& Method::request_type_url() const { +const ::std::string& Method::request_type_url() const { // @@protoc_insertion_point(field_get:google.protobuf.Method.request_type_url) return request_type_url_.GetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); } - void Method::set_request_type_url(const ::std::string& value) { +void Method::set_request_type_url(const ::std::string& value) { request_type_url_.SetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), value); // @@protoc_insertion_point(field_set:google.protobuf.Method.request_type_url) } - void Method::set_request_type_url(const char* value) { +void Method::set_request_type_url(const char* value) { request_type_url_.SetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), ::std::string(value)); // @@protoc_insertion_point(field_set_char:google.protobuf.Method.request_type_url) } - void Method::set_request_type_url(const char* value, size_t size) { +void Method::set_request_type_url(const char* value, size_t size) { request_type_url_.SetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), ::std::string(reinterpret_cast(value), size)); // @@protoc_insertion_point(field_set_pointer:google.protobuf.Method.request_type_url) } - ::std::string* Method::mutable_request_type_url() { +::std::string* Method::mutable_request_type_url() { // @@protoc_insertion_point(field_mutable:google.protobuf.Method.request_type_url) return request_type_url_.MutableNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); } - ::std::string* Method::release_request_type_url() { +::std::string* Method::release_request_type_url() { // @@protoc_insertion_point(field_release:google.protobuf.Method.request_type_url) return request_type_url_.ReleaseNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); } - void Method::set_allocated_request_type_url(::std::string* request_type_url) { +void Method::set_allocated_request_type_url(::std::string* request_type_url) { if (request_type_url != NULL) { } else { @@ -1526,11 +1562,11 @@ void Method::clear_request_type_url() { void Method::clear_request_streaming() { request_streaming_ = false; } - bool Method::request_streaming() const { +bool Method::request_streaming() const { // @@protoc_insertion_point(field_get:google.protobuf.Method.request_streaming) return request_streaming_; } - void Method::set_request_streaming(bool value) { +void Method::set_request_streaming(bool value) { request_streaming_ = value; // @@protoc_insertion_point(field_set:google.protobuf.Method.request_streaming) @@ -1540,37 +1576,37 @@ void Method::clear_request_streaming() { void Method::clear_response_type_url() { response_type_url_.ClearToEmptyNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); } - const ::std::string& Method::response_type_url() const { +const ::std::string& Method::response_type_url() const { // @@protoc_insertion_point(field_get:google.protobuf.Method.response_type_url) return response_type_url_.GetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); } - void Method::set_response_type_url(const ::std::string& value) { +void Method::set_response_type_url(const ::std::string& value) { response_type_url_.SetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), value); // @@protoc_insertion_point(field_set:google.protobuf.Method.response_type_url) } - void Method::set_response_type_url(const char* value) { +void Method::set_response_type_url(const char* value) { response_type_url_.SetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), ::std::string(value)); // @@protoc_insertion_point(field_set_char:google.protobuf.Method.response_type_url) } - void Method::set_response_type_url(const char* value, size_t size) { +void Method::set_response_type_url(const char* value, size_t size) { response_type_url_.SetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), ::std::string(reinterpret_cast(value), size)); // @@protoc_insertion_point(field_set_pointer:google.protobuf.Method.response_type_url) } - ::std::string* Method::mutable_response_type_url() { +::std::string* Method::mutable_response_type_url() { // @@protoc_insertion_point(field_mutable:google.protobuf.Method.response_type_url) return response_type_url_.MutableNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); } - ::std::string* Method::release_response_type_url() { +::std::string* Method::release_response_type_url() { // @@protoc_insertion_point(field_release:google.protobuf.Method.response_type_url) return response_type_url_.ReleaseNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); } - void Method::set_allocated_response_type_url(::std::string* response_type_url) { +void Method::set_allocated_response_type_url(::std::string* response_type_url) { if (response_type_url != NULL) { } else { @@ -1584,11 +1620,11 @@ void Method::clear_response_type_url() { void Method::clear_response_streaming() { response_streaming_ = false; } - bool Method::response_streaming() const { +bool Method::response_streaming() const { // @@protoc_insertion_point(field_get:google.protobuf.Method.response_streaming) return response_streaming_; } - void Method::set_response_streaming(bool value) { +void Method::set_response_streaming(bool value) { response_streaming_ = value; // @@protoc_insertion_point(field_set:google.protobuf.Method.response_streaming) @@ -1628,11 +1664,11 @@ Method::options() const { void Method::clear_syntax() { syntax_ = 0; } - ::google::protobuf::Syntax Method::syntax() const { +::google::protobuf::Syntax Method::syntax() const { // @@protoc_insertion_point(field_get:google.protobuf.Method.syntax) return static_cast< ::google::protobuf::Syntax >(syntax_); } - void Method::set_syntax(::google::protobuf::Syntax value) { +void Method::set_syntax(::google::protobuf::Syntax value) { syntax_ = value; // @@protoc_insertion_point(field_set:google.protobuf.Method.syntax) @@ -1649,28 +1685,26 @@ const int Mixin::kRootFieldNumber; Mixin::Mixin() : ::google::protobuf::Message(), _internal_metadata_(NULL) { + if (this != internal_default_instance()) protobuf_InitDefaults_google_2fprotobuf_2fapi_2eproto(); SharedCtor(); // @@protoc_insertion_point(constructor:google.protobuf.Mixin) } void Mixin::InitAsDefaultInstance() { - _is_default_instance_ = true; } Mixin::Mixin(const Mixin& from) : ::google::protobuf::Message(), _internal_metadata_(NULL) { SharedCtor(); - MergeFrom(from); + UnsafeMergeFrom(from); // @@protoc_insertion_point(copy_constructor:google.protobuf.Mixin) } void Mixin::SharedCtor() { - _is_default_instance_ = false; - ::google::protobuf::internal::GetEmptyString(); - _cached_size_ = 0; name_.UnsafeSetDefault(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); root_.UnsafeSetDefault(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); + _cached_size_ = 0; } Mixin::~Mixin() { @@ -1681,8 +1715,6 @@ Mixin::~Mixin() { void Mixin::SharedDtor() { name_.DestroyNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); root_.DestroyNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); - if (this != default_instance_) { - } } void Mixin::SetCachedSize(int size) const { @@ -1696,11 +1728,11 @@ const ::google::protobuf::Descriptor* Mixin::descriptor() { } const Mixin& Mixin::default_instance() { - if (default_instance_ == NULL) protobuf_AddDesc_google_2fprotobuf_2fapi_2eproto(); - return *default_instance_; + protobuf_InitDefaults_google_2fprotobuf_2fapi_2eproto(); + return *internal_default_instance(); } -Mixin* Mixin::default_instance_ = NULL; +::google::protobuf::internal::ExplicitlyConstructed Mixin::default_instance_; Mixin* Mixin::New(::google::protobuf::Arena* arena) const { Mixin* n = new Mixin; @@ -1836,9 +1868,9 @@ void Mixin::SerializeWithCachedSizes( return target; } -int Mixin::ByteSize() const { +size_t Mixin::ByteSizeLong() const { // @@protoc_insertion_point(message_byte_size_start:google.protobuf.Mixin) - int total_size = 0; + size_t total_size = 0; // optional string name = 1; if (this->name().size() > 0) { @@ -1854,18 +1886,17 @@ int Mixin::ByteSize() const { this->root()); } + int cached_size = ::google::protobuf::internal::ToCachedSize(total_size); GOOGLE_SAFE_CONCURRENT_WRITES_BEGIN(); - _cached_size_ = total_size; + _cached_size_ = cached_size; GOOGLE_SAFE_CONCURRENT_WRITES_END(); return total_size; } void Mixin::MergeFrom(const ::google::protobuf::Message& from) { // @@protoc_insertion_point(generalized_merge_from_start:google.protobuf.Mixin) - if (GOOGLE_PREDICT_FALSE(&from == this)) { - ::google::protobuf::internal::MergeFromFail(__FILE__, __LINE__); - } - const Mixin* source = + if (GOOGLE_PREDICT_FALSE(&from == this)) MergeFromFail(__LINE__); + const Mixin* source = ::google::protobuf::internal::DynamicCastToGenerated( &from); if (source == NULL) { @@ -1873,15 +1904,21 @@ void Mixin::MergeFrom(const ::google::protobuf::Message& from) { ::google::protobuf::internal::ReflectionOps::Merge(from, this); } else { // @@protoc_insertion_point(generalized_merge_from_cast_success:google.protobuf.Mixin) - MergeFrom(*source); + UnsafeMergeFrom(*source); } } void Mixin::MergeFrom(const Mixin& from) { // @@protoc_insertion_point(class_specific_merge_from_start:google.protobuf.Mixin) - if (GOOGLE_PREDICT_FALSE(&from == this)) { - ::google::protobuf::internal::MergeFromFail(__FILE__, __LINE__); + if (GOOGLE_PREDICT_TRUE(&from != this)) { + UnsafeMergeFrom(from); + } else { + MergeFromFail(__LINE__); } +} + +void Mixin::UnsafeMergeFrom(const Mixin& from) { + GOOGLE_DCHECK(&from != this); if (from.name().size() > 0) { name_.AssignWithDefault(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), from.name_); @@ -1903,7 +1940,7 @@ void Mixin::CopyFrom(const Mixin& from) { // @@protoc_insertion_point(class_specific_copy_from_start:google.protobuf.Mixin) if (&from == this) return; Clear(); - MergeFrom(from); + UnsafeMergeFrom(from); } bool Mixin::IsInitialized() const { @@ -1937,37 +1974,37 @@ void Mixin::InternalSwap(Mixin* other) { void Mixin::clear_name() { name_.ClearToEmptyNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); } - const ::std::string& Mixin::name() const { +const ::std::string& Mixin::name() const { // @@protoc_insertion_point(field_get:google.protobuf.Mixin.name) return name_.GetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); } - void Mixin::set_name(const ::std::string& value) { +void Mixin::set_name(const ::std::string& value) { name_.SetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), value); // @@protoc_insertion_point(field_set:google.protobuf.Mixin.name) } - void Mixin::set_name(const char* value) { +void Mixin::set_name(const char* value) { name_.SetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), ::std::string(value)); // @@protoc_insertion_point(field_set_char:google.protobuf.Mixin.name) } - void Mixin::set_name(const char* value, size_t size) { +void Mixin::set_name(const char* value, size_t size) { name_.SetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), ::std::string(reinterpret_cast(value), size)); // @@protoc_insertion_point(field_set_pointer:google.protobuf.Mixin.name) } - ::std::string* Mixin::mutable_name() { +::std::string* Mixin::mutable_name() { // @@protoc_insertion_point(field_mutable:google.protobuf.Mixin.name) return name_.MutableNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); } - ::std::string* Mixin::release_name() { +::std::string* Mixin::release_name() { // @@protoc_insertion_point(field_release:google.protobuf.Mixin.name) return name_.ReleaseNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); } - void Mixin::set_allocated_name(::std::string* name) { +void Mixin::set_allocated_name(::std::string* name) { if (name != NULL) { } else { @@ -1981,37 +2018,37 @@ void Mixin::clear_name() { void Mixin::clear_root() { root_.ClearToEmptyNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); } - const ::std::string& Mixin::root() const { +const ::std::string& Mixin::root() const { // @@protoc_insertion_point(field_get:google.protobuf.Mixin.root) return root_.GetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); } - void Mixin::set_root(const ::std::string& value) { +void Mixin::set_root(const ::std::string& value) { root_.SetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), value); // @@protoc_insertion_point(field_set:google.protobuf.Mixin.root) } - void Mixin::set_root(const char* value) { +void Mixin::set_root(const char* value) { root_.SetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), ::std::string(value)); // @@protoc_insertion_point(field_set_char:google.protobuf.Mixin.root) } - void Mixin::set_root(const char* value, size_t size) { +void Mixin::set_root(const char* value, size_t size) { root_.SetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), ::std::string(reinterpret_cast(value), size)); // @@protoc_insertion_point(field_set_pointer:google.protobuf.Mixin.root) } - ::std::string* Mixin::mutable_root() { +::std::string* Mixin::mutable_root() { // @@protoc_insertion_point(field_mutable:google.protobuf.Mixin.root) return root_.MutableNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); } - ::std::string* Mixin::release_root() { +::std::string* Mixin::release_root() { // @@protoc_insertion_point(field_release:google.protobuf.Mixin.root) return root_.ReleaseNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); } - void Mixin::set_allocated_root(::std::string* root) { +void Mixin::set_allocated_root(::std::string* root) { if (root != NULL) { } else { diff --git a/src/google/protobuf/api.pb.h b/src/google/protobuf/api.pb.h index 917f888b..ac18055d 100644 --- a/src/google/protobuf/api.pb.h +++ b/src/google/protobuf/api.pb.h @@ -36,6 +36,7 @@ namespace protobuf { // Internal implementation detail -- do not call these. void LIBPROTOBUF_EXPORT protobuf_AddDesc_google_2fprotobuf_2fapi_2eproto(); +void LIBPROTOBUF_EXPORT protobuf_InitDefaults_google_2fprotobuf_2fapi_2eproto(); void protobuf_AssignDesc_google_2fprotobuf_2fapi_2eproto(); void protobuf_ShutdownFile_google_2fprotobuf_2fapi_2eproto(); @@ -60,6 +61,10 @@ class LIBPROTOBUF_EXPORT Api : public ::google::protobuf::Message /* @@protoc_in static const ::google::protobuf::Descriptor* descriptor(); static const Api& default_instance(); + static inline const Api* internal_default_instance() { + return &default_instance_.get(); + } + void Swap(Api* other); // implements Message ---------------------------------------------- @@ -74,7 +79,7 @@ class LIBPROTOBUF_EXPORT Api : public ::google::protobuf::Message /* @@protoc_in void Clear(); bool IsInitialized() const; - int ByteSize() const; + size_t ByteSizeLong() const; bool MergePartialFromCodedStream( ::google::protobuf::io::CodedInputStream* input); void SerializeWithCachedSizes( @@ -90,6 +95,7 @@ class LIBPROTOBUF_EXPORT Api : public ::google::protobuf::Message /* @@protoc_in void SharedDtor(); void SetCachedSize(int size) const; void InternalSwap(Api* other); + void UnsafeMergeFrom(const Api& from); private: inline ::google::protobuf::Arena* GetArenaNoVirtual() const { return _internal_metadata_.arena(); @@ -182,21 +188,21 @@ class LIBPROTOBUF_EXPORT Api : public ::google::protobuf::Message /* @@protoc_in private: ::google::protobuf::internal::InternalMetadataWithArena _internal_metadata_; - bool _is_default_instance_; - ::google::protobuf::internal::ArenaStringPtr name_; ::google::protobuf::RepeatedPtrField< ::google::protobuf::Method > methods_; ::google::protobuf::RepeatedPtrField< ::google::protobuf::Option > options_; + ::google::protobuf::RepeatedPtrField< ::google::protobuf::Mixin > mixins_; + ::google::protobuf::internal::ArenaStringPtr name_; ::google::protobuf::internal::ArenaStringPtr version_; ::google::protobuf::SourceContext* source_context_; - ::google::protobuf::RepeatedPtrField< ::google::protobuf::Mixin > mixins_; int syntax_; mutable int _cached_size_; - friend void LIBPROTOBUF_EXPORT protobuf_AddDesc_google_2fprotobuf_2fapi_2eproto(); + friend void LIBPROTOBUF_EXPORT protobuf_InitDefaults_google_2fprotobuf_2fapi_2eproto_impl(); + friend void LIBPROTOBUF_EXPORT protobuf_AddDesc_google_2fprotobuf_2fapi_2eproto_impl(); friend void protobuf_AssignDesc_google_2fprotobuf_2fapi_2eproto(); friend void protobuf_ShutdownFile_google_2fprotobuf_2fapi_2eproto(); void InitAsDefaultInstance(); - static Api* default_instance_; + static ::google::protobuf::internal::ExplicitlyConstructed default_instance_; }; // ------------------------------------------------------------------- @@ -215,6 +221,10 @@ class LIBPROTOBUF_EXPORT Method : public ::google::protobuf::Message /* @@protoc static const ::google::protobuf::Descriptor* descriptor(); static const Method& default_instance(); + static inline const Method* internal_default_instance() { + return &default_instance_.get(); + } + void Swap(Method* other); // implements Message ---------------------------------------------- @@ -229,7 +239,7 @@ class LIBPROTOBUF_EXPORT Method : public ::google::protobuf::Message /* @@protoc void Clear(); bool IsInitialized() const; - int ByteSize() const; + size_t ByteSizeLong() const; bool MergePartialFromCodedStream( ::google::protobuf::io::CodedInputStream* input); void SerializeWithCachedSizes( @@ -245,6 +255,7 @@ class LIBPROTOBUF_EXPORT Method : public ::google::protobuf::Message /* @@protoc void SharedDtor(); void SetCachedSize(int size) const; void InternalSwap(Method* other); + void UnsafeMergeFrom(const Method& from); private: inline ::google::protobuf::Arena* GetArenaNoVirtual() const { return _internal_metadata_.arena(); @@ -327,21 +338,21 @@ class LIBPROTOBUF_EXPORT Method : public ::google::protobuf::Message /* @@protoc private: ::google::protobuf::internal::InternalMetadataWithArena _internal_metadata_; - bool _is_default_instance_; + ::google::protobuf::RepeatedPtrField< ::google::protobuf::Option > options_; ::google::protobuf::internal::ArenaStringPtr name_; ::google::protobuf::internal::ArenaStringPtr request_type_url_; ::google::protobuf::internal::ArenaStringPtr response_type_url_; bool request_streaming_; bool response_streaming_; int syntax_; - ::google::protobuf::RepeatedPtrField< ::google::protobuf::Option > options_; mutable int _cached_size_; - friend void LIBPROTOBUF_EXPORT protobuf_AddDesc_google_2fprotobuf_2fapi_2eproto(); + friend void LIBPROTOBUF_EXPORT protobuf_InitDefaults_google_2fprotobuf_2fapi_2eproto_impl(); + friend void LIBPROTOBUF_EXPORT protobuf_AddDesc_google_2fprotobuf_2fapi_2eproto_impl(); friend void protobuf_AssignDesc_google_2fprotobuf_2fapi_2eproto(); friend void protobuf_ShutdownFile_google_2fprotobuf_2fapi_2eproto(); void InitAsDefaultInstance(); - static Method* default_instance_; + static ::google::protobuf::internal::ExplicitlyConstructed default_instance_; }; // ------------------------------------------------------------------- @@ -360,6 +371,10 @@ class LIBPROTOBUF_EXPORT Mixin : public ::google::protobuf::Message /* @@protoc_ static const ::google::protobuf::Descriptor* descriptor(); static const Mixin& default_instance(); + static inline const Mixin* internal_default_instance() { + return &default_instance_.get(); + } + void Swap(Mixin* other); // implements Message ---------------------------------------------- @@ -374,7 +389,7 @@ class LIBPROTOBUF_EXPORT Mixin : public ::google::protobuf::Message /* @@protoc_ void Clear(); bool IsInitialized() const; - int ByteSize() const; + size_t ByteSizeLong() const; bool MergePartialFromCodedStream( ::google::protobuf::io::CodedInputStream* input); void SerializeWithCachedSizes( @@ -390,6 +405,7 @@ class LIBPROTOBUF_EXPORT Mixin : public ::google::protobuf::Message /* @@protoc_ void SharedDtor(); void SetCachedSize(int size) const; void InternalSwap(Mixin* other); + void UnsafeMergeFrom(const Mixin& from); private: inline ::google::protobuf::Arena* GetArenaNoVirtual() const { return _internal_metadata_.arena(); @@ -431,16 +447,16 @@ class LIBPROTOBUF_EXPORT Mixin : public ::google::protobuf::Message /* @@protoc_ private: ::google::protobuf::internal::InternalMetadataWithArena _internal_metadata_; - bool _is_default_instance_; ::google::protobuf::internal::ArenaStringPtr name_; ::google::protobuf::internal::ArenaStringPtr root_; mutable int _cached_size_; - friend void LIBPROTOBUF_EXPORT protobuf_AddDesc_google_2fprotobuf_2fapi_2eproto(); + friend void LIBPROTOBUF_EXPORT protobuf_InitDefaults_google_2fprotobuf_2fapi_2eproto_impl(); + friend void LIBPROTOBUF_EXPORT protobuf_AddDesc_google_2fprotobuf_2fapi_2eproto_impl(); friend void protobuf_AssignDesc_google_2fprotobuf_2fapi_2eproto(); friend void protobuf_ShutdownFile_google_2fprotobuf_2fapi_2eproto(); void InitAsDefaultInstance(); - static Mixin* default_instance_; + static ::google::protobuf::internal::ExplicitlyConstructed default_instance_; }; // =================================================================== @@ -600,7 +616,7 @@ inline void Api::set_allocated_version(::std::string* version) { // optional .google.protobuf.SourceContext source_context = 5; inline bool Api::has_source_context() const { - return !_is_default_instance_ && source_context_ != NULL; + return this != internal_default_instance() && source_context_ != NULL; } inline void Api::clear_source_context() { if (GetArenaNoVirtual() == NULL && source_context_ != NULL) delete source_context_; @@ -608,7 +624,8 @@ inline void Api::clear_source_context() { } inline const ::google::protobuf::SourceContext& Api::source_context() const { // @@protoc_insertion_point(field_get:google.protobuf.Api.source_context) - return source_context_ != NULL ? *source_context_ : *default_instance_->source_context_; + return source_context_ != NULL ? *source_context_ + : *::google::protobuf::SourceContext::internal_default_instance(); } inline ::google::protobuf::SourceContext* Api::mutable_source_context() { diff --git a/src/google/protobuf/api.proto b/src/google/protobuf/api.proto index dbe87b8f..bbbe9833 100644 --- a/src/google/protobuf/api.proto +++ b/src/google/protobuf/api.proto @@ -39,7 +39,6 @@ option csharp_namespace = "Google.Protobuf.WellKnownTypes"; option java_package = "com.google.protobuf"; option java_outer_classname = "ApiProto"; option java_multiple_files = true; -option java_generate_equals_and_hash = true; option objc_class_prefix = "GPB"; // Api is a light-weight descriptor for a protocol buffer service. diff --git a/src/google/protobuf/arena.cc b/src/google/protobuf/arena.cc index 78e20946..aa4e587c 100755 --- a/src/google/protobuf/arena.cc +++ b/src/google/protobuf/arena.cc @@ -30,6 +30,9 @@ #include +#include +#include + #ifdef ADDRESS_SANITIZER #include @@ -125,10 +128,9 @@ Arena::Block* Arena::NewBlock(void* me, Block* my_last_block, size_t n, } else { size = start_block_size; } - if (n > size - kHeaderSize) { - // TODO(sanjay): Check if n + kHeaderSize would overflow - size = kHeaderSize + n; - } + // Verify that n + kHeaderSize won't overflow. + GOOGLE_CHECK_LE(n, std::numeric_limits::max() - kHeaderSize); + size = std::max(size, kHeaderSize + n); Block* b = reinterpret_cast(options_.block_alloc(size)); b->pos = kHeaderSize + n; diff --git a/src/google/protobuf/arena.h b/src/google/protobuf/arena.h index 0a5eacee..f05277ed 100644 --- a/src/google/protobuf/arena.h +++ b/src/google/protobuf/arena.h @@ -79,8 +79,12 @@ template void arena_destruct_object(void* object) { template void arena_delete_object(void* object) { delete reinterpret_cast(object); } -inline void arena_free(void* object, size_t /* size */) { - free(object); +inline void arena_free(void* object, size_t size) { +#if defined(__GXX_DELETE_WITH_SIZE__) || defined(__cpp_sized_deallocation) + ::operator delete(object, size); +#else + ::operator delete(object); +#endif } } // namespace internal @@ -144,7 +148,7 @@ struct ArenaOptions { max_block_size(kDefaultMaxBlockSize), initial_block(NULL), initial_block_size(0), - block_alloc(&malloc), + block_alloc(&::operator new), block_dealloc(&internal::arena_free), on_arena_init(NULL), on_arena_reset(NULL), @@ -454,7 +458,7 @@ class LIBPROTOBUF_EXPORT Arena { // Combines SpaceAllocated and SpaceUsed. Returns a pair of // . - GOOGLE_ATTRIBUTE_NOINLINE pair SpaceAllocatedAndUsed() const; + GOOGLE_ATTRIBUTE_NOINLINE std::pair SpaceAllocatedAndUsed() const; // Frees all storage allocated by this arena after calling destructors // registered with OwnDestructor() and freeing objects registered with Own(). @@ -608,6 +612,7 @@ class LIBPROTOBUF_EXPORT Arena { const T>(static_cast(0))) == sizeof(char) || google::protobuf::internal::has_trivial_destructor::value> {}; + private: // CreateMessage requires that T supports arenas, but this private method // works whether or not T supports arenas. These are not exposed to user code // as it can cause confusing API usages, and end up having double free in diff --git a/src/google/protobuf/arena_unittest.cc b/src/google/protobuf/arena_unittest.cc index 5f33e939..35d00463 100644 --- a/src/google/protobuf/arena_unittest.cc +++ b/src/google/protobuf/arena_unittest.cc @@ -151,8 +151,6 @@ class MustBeConstructedWithOneThroughEight { GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(MustBeConstructedWithOneThroughEight); }; -} // namespace - TEST(ArenaTest, ArenaConstructable) { EXPECT_TRUE(Arena::is_arena_constructable::type::value); EXPECT_TRUE(Arena::is_arena_constructable::type::value); @@ -893,6 +891,24 @@ TEST(ArenaTest, UnsafeArenaRelease) { delete s; } +TEST(ArenaTest, OneofMerge) { + Arena arena; + TestAllTypes* message0 = Arena::CreateMessage(&arena); + TestAllTypes* message1 = Arena::CreateMessage(&arena); + + message0->unsafe_arena_set_allocated_oneof_string(new string("x")); + ASSERT_TRUE(message0->has_oneof_string()); + message1->unsafe_arena_set_allocated_oneof_string(new string("y")); + ASSERT_TRUE(message1->has_oneof_string()); + EXPECT_EQ("x", message0->oneof_string()); + EXPECT_EQ("y", message1->oneof_string()); + message0->MergeFrom(*message1); + EXPECT_EQ("y", message0->oneof_string()); + EXPECT_EQ("y", message1->oneof_string()); + delete message0->unsafe_arena_release_oneof_string(); + delete message1->unsafe_arena_release_oneof_string(); +} + TEST(ArenaTest, ArenaOneofReflection) { Arena arena; TestAllTypes* message = Arena::CreateMessage(&arena); @@ -923,7 +939,6 @@ TEST(ArenaTest, ArenaOneofReflection) { delete submsg; } -namespace { void TestSwapRepeatedField(Arena* arena1, Arena* arena2) { // Test "safe" (copying) semantics for direct Swap() on RepeatedPtrField // between arenas. @@ -962,7 +977,6 @@ void TestSwapRepeatedField(Arena* arena1, Arena* arena2) { EXPECT_EQ(i, field2.Get(i).optional_int32()); } } -} // namespace TEST(ArenaTest, SwapRepeatedField) { Arena arena; @@ -1104,8 +1118,6 @@ TEST(ArenaTest, MutableMessageReflection) { #endif // !GOOGLE_PROTOBUF_NO_RTTI -namespace { - void FillArenaAwareFields(TestAllTypes* message) { string test_string = "hello world"; message->set_optional_int32(42); @@ -1124,8 +1136,6 @@ void FillArenaAwareFields(TestAllTypes* message) { message->mutable_optional_lazy_message()->set_bb(42); } -} - // Test: no allocations occur on heap while touching all supported field types. TEST(ArenaTest, NoHeapAllocationsTest) { // Allocate a large initial block to avoid mallocs during hooked test. @@ -1196,9 +1206,7 @@ TEST(ArenaTest, RepeatedFieldWithNonPODType) { } // Align n to next multiple of 8 -namespace { uint64 Align8(uint64 n) { return (n + 7) & -8; } -} // namespace TEST(ArenaTest, SpaceAllocated_and_Used) { ArenaOptions options; @@ -1249,6 +1257,22 @@ TEST(ArenaTest, Alignment) { } } +TEST(ArenaTest, BlockSizeSmallerThanAllocation) { + for (size_t i = 0; i <= 8; ++i) { + ::google::protobuf::ArenaOptions opt; + opt.start_block_size = opt.max_block_size = i; + ::google::protobuf::Arena arena(opt); + + *::google::protobuf::Arena::Create(&arena) = 42; + EXPECT_GE(arena.SpaceAllocated(), 8); + EXPECT_EQ(8, arena.SpaceUsed()); + + *::google::protobuf::Arena::Create(&arena) = 42; + EXPECT_GE(arena.SpaceAllocated(), 16); + EXPECT_EQ(16, arena.SpaceUsed()); + } +} + TEST(ArenaTest, GetArenaShouldReturnTheArenaForArenaAllocatedMessages) { ::google::protobuf::Arena arena; ArenaMessage* message = Arena::CreateMessage(&arena); @@ -1349,5 +1373,7 @@ TEST(ArenaTest, ArenaHooksSanity) { EXPECT_EQ(1, ArenaHooksTestUtil::num_destruct); } + +} // namespace } // namespace protobuf } // namespace google diff --git a/src/google/protobuf/compiler/code_generator.cc b/src/google/protobuf/compiler/code_generator.cc index 473eb4e6..f6ff1e5d 100644 --- a/src/google/protobuf/compiler/code_generator.cc +++ b/src/google/protobuf/compiler/code_generator.cc @@ -36,6 +36,7 @@ #include #include +#include #include namespace google { @@ -43,6 +44,33 @@ namespace protobuf { namespace compiler { CodeGenerator::~CodeGenerator() {} + +bool CodeGenerator::GenerateAll( + const vector& files, + const string& parameter, + GeneratorContext* generator_context, + string* error) const { + // Default implemenation is just to call the per file method, and prefix any + // error string with the file to provide context. + bool succeeded = true; + for (int i = 0; i < files.size(); i++) { + const FileDescriptor* file = files[i]; + succeeded = Generate(file, parameter, generator_context, error); + if (!succeeded && error && error->empty()) { + *error = "Code generator returned false but provided no error " + "description."; + } + if (error && !error->empty()) { + *error = file->name() + ": " + *error; + break; + } + if (!succeeded) { + break; + } + } + return succeeded; +} + GeneratorContext::~GeneratorContext() {} io::ZeroCopyOutputStream* diff --git a/src/google/protobuf/compiler/code_generator.h b/src/google/protobuf/compiler/code_generator.h index b989f151..642bbfad 100644 --- a/src/google/protobuf/compiler/code_generator.h +++ b/src/google/protobuf/compiler/code_generator.h @@ -66,11 +66,11 @@ class LIBPROTOC_EXPORT CodeGenerator { // Generates code for the given proto file, generating one or more files in // the given output directory. // - // A parameter to be passed to the generator can be specified on the - // command line. This is intended to be used by Java and similar languages - // to specify which specific class from the proto file is to be generated, - // though it could have other uses as well. It is empty if no parameter was - // given. + // A parameter to be passed to the generator can be specified on the command + // line. This is intended to be used to pass generator specific parameters. + // It is empty if no parameter was given. ParseGeneratorParameter (below), + // can be used to accept multiple parameters within the single parameter + // command line flag. // // Returns true if successful. Otherwise, sets *error to a description of // the problem (e.g. "invalid parameter") and returns false. @@ -79,18 +79,11 @@ class LIBPROTOC_EXPORT CodeGenerator { GeneratorContext* generator_context, string* error) const = 0; - // Generates code for all given proto files, generating one or more files in - // the given output directory. - // - // This method should be called instead of |Generate()| when - // |HasGenerateAll()| returns |true|. It is used to emulate legacy semantics - // when more than one `.proto` file is specified on one compiler invocation. + // Generates code for all given proto files. // - // WARNING: Please do not use unless legacy semantics force the code generator - // to produce a single output file for all input files, or otherwise require - // an examination of all input files first. The canonical code generator - // design produces one output file per input .proto file, and we do not wish - // to encourage alternate designs. + // WARNING: The canonical code generator design produces one or two output + // files per input .proto file, and we do not wish to encourage alternate + // designs. // // A parameter is given as passed on the command line, as in |Generate()| // above. @@ -100,15 +93,13 @@ class LIBPROTOC_EXPORT CodeGenerator { virtual bool GenerateAll(const vector& files, const string& parameter, GeneratorContext* generator_context, - string* error) const { - *error = "Unimplemented GenerateAll() method."; - return false; - } - - // Returns true if the code generator expects to receive all FileDescriptors - // at once (via |GenerateAll()|), rather than one at a time (via - // |Generate()|). This is required to implement legacy semantics. - virtual bool HasGenerateAll() const { return false; } + string* error) const; + + // This is no longer used, but this class is part of the opensource protobuf + // library, so it has to remain to keep vtables the same for the current + // version of the library. When protobufs does a api breaking change, the + // method can be removed. + virtual bool HasGenerateAll() const { return true; } private: GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(CodeGenerator); diff --git a/src/google/protobuf/compiler/command_line_interface.cc b/src/google/protobuf/compiler/command_line_interface.cc index bb781b0a..0d1c30ce 100644 --- a/src/google/protobuf/compiler/command_line_interface.cc +++ b/src/google/protobuf/compiler/command_line_interface.cc @@ -704,6 +704,7 @@ CommandLineInterface::CommandLineInterface() : mode_(MODE_COMPILE), print_mode_(PRINT_NONE), error_format_(ERROR_FORMAT_GCC), + direct_dependencies_explicitly_set_(false), imports_in_descriptor_set_(false), source_info_in_descriptor_set_(false), disallow_services_(false), @@ -784,6 +785,24 @@ int CommandLineInterface::Run(int argc, const char* const argv[]) { "--disallow_services was used." << endl; return 1; } + + // Enforce --direct_dependencies + if (direct_dependencies_explicitly_set_) { + bool indirect_imports = false; + for (int i = 0; i < parsed_file->dependency_count(); i++) { + if (direct_dependencies_.find(parsed_file->dependency(i)->name()) == + direct_dependencies_.end()) { + indirect_imports = true; + cerr << parsed_file->name() + << ": File is imported but not declared in " + << "--direct_dependencies: " + << parsed_file->dependency(i)->name() << std::endl; + } + } + if (indirect_imports) { + return 1; + } + } } // We construct a separate GeneratorContext for each output location. Note @@ -897,6 +916,7 @@ void CommandLineInterface::Clear() { executable_name_.clear(); proto_path_.clear(); input_files_.clear(); + direct_dependencies_.clear(); output_directives_.clear(); codec_type_.clear(); descriptor_set_name_.clear(); @@ -907,6 +927,7 @@ void CommandLineInterface::Clear() { imports_in_descriptor_set_ = false; source_info_in_descriptor_set_ = false; disallow_services_ = false; + direct_dependencies_explicitly_set_ = false; } bool CommandLineInterface::MakeInputsBeProtoPathRelative( @@ -1154,6 +1175,21 @@ CommandLineInterface::InterpretArgument(const string& name, proto_path_.push_back(pair(virtual_path, disk_path)); } + } else if (name == "--direct_dependencies") { + if (direct_dependencies_explicitly_set_) { + std::cerr << name << " may only be passed once. To specify multiple " + "direct dependencies, pass them all as a single " + "parameter separated by '" + << kPathSeparator << "'." << std::endl; + return PARSE_ARGUMENT_FAIL; + } + + direct_dependencies_explicitly_set_ = true; + vector direct = Split( + value, kPathSeparator, true); + GOOGLE_DCHECK(direct_dependencies_.empty()); + direct_dependencies_.insert(direct.begin(), direct.end()); + } else if (name == "-o" || name == "--descriptor_set_out") { if (!descriptor_set_name_.empty()) { std::cerr << name << " may only be passed once." << std::endl; @@ -1447,24 +1483,11 @@ bool CommandLineInterface::GenerateOutput( } parameters.append(generator_parameters_[output_directive.name]); } - if (output_directive.generator->HasGenerateAll()) { - if (!output_directive.generator->GenerateAll( - parsed_files, parameters, generator_context, &error)) { - // Generator returned an error. - std::cerr << output_directive.name << ": " - << ": " << error << std::endl; - return false; - } - } else { - for (int i = 0; i < parsed_files.size(); i++) { - if (!output_directive.generator->Generate(parsed_files[i], parameters, - generator_context, &error)) { - // Generator returned an error. - std::cerr << output_directive.name << ": " << parsed_files[i]->name() - << ": " << error << std::endl; - return false; - } - } + if (!output_directive.generator->GenerateAll( + parsed_files, parameters, generator_context, &error)) { + // Generator returned an error. + std::cerr << output_directive.name << ": " << error << std::endl; + return false; } } diff --git a/src/google/protobuf/compiler/command_line_interface.h b/src/google/protobuf/compiler/command_line_interface.h index 32084567..c38e65a3 100644 --- a/src/google/protobuf/compiler/command_line_interface.h +++ b/src/google/protobuf/compiler/command_line_interface.h @@ -352,6 +352,11 @@ class LIBPROTOC_EXPORT CommandLineInterface { vector > proto_path_; // Search path for proto files. vector input_files_; // Names of the input proto files. + // Names of proto files which are allowed to be imported. Used by build + // systems to enforce depend-on-what-you-import. + set direct_dependencies_; + bool direct_dependencies_explicitly_set_; + // output_directives_ lists all the files we are supposed to output and what // generator to use for each. struct OutputDirective { diff --git a/src/google/protobuf/compiler/command_line_interface_unittest.cc b/src/google/protobuf/compiler/command_line_interface_unittest.cc index dee438c6..56a07dbf 100644 --- a/src/google/protobuf/compiler/command_line_interface_unittest.cc +++ b/src/google/protobuf/compiler/command_line_interface_unittest.cc @@ -871,6 +871,92 @@ TEST_F(CommandLineInterfaceTest, AllowServicesHasService) { ExpectGenerated("test_generator", "", "foo.proto", "Foo"); } +TEST_F(CommandLineInterfaceTest, DirectDependencies_Missing_EmptyList) { + CreateTempFile("foo.proto", + "syntax = \"proto2\";\n" + "import \"bar.proto\";\n" + "message Foo { optional Bar bar = 1; }"); + CreateTempFile("bar.proto", + "syntax = \"proto2\";\n" + "message Bar { optional string text = 1; }"); + + Run("protocol_compiler --test_out=$tmpdir --proto_path=$tmpdir " + "--direct_dependencies= foo.proto"); + + ExpectErrorText( + "foo.proto: File is imported but not declared in --direct_dependencies: " + "bar.proto\n"); +} + +TEST_F(CommandLineInterfaceTest, DirectDependencies_Missing) { + CreateTempFile("foo.proto", + "syntax = \"proto2\";\n" + "import \"bar.proto\";\n" + "import \"bla.proto\";\n" + "message Foo { optional Bar bar = 1; optional Bla bla = 2; }"); + CreateTempFile("bar.proto", + "syntax = \"proto2\";\n" + "message Bar { optional string text = 1; }"); + CreateTempFile("bla.proto", + "syntax = \"proto2\";\n" + "message Bla { optional int64 number = 1; }"); + + Run("protocol_compiler --test_out=$tmpdir --proto_path=$tmpdir " + "--direct_dependencies=bla.proto foo.proto"); + + ExpectErrorText( + "foo.proto: File is imported but not declared in --direct_dependencies: " + "bar.proto\n"); +} + +TEST_F(CommandLineInterfaceTest, DirectDependencies_NoViolation) { + CreateTempFile("foo.proto", + "syntax = \"proto2\";\n" + "import \"bar.proto\";\n" + "message Foo { optional Bar bar = 1; }"); + CreateTempFile("bar.proto", + "syntax = \"proto2\";\n" + "message Bar { optional string text = 1; }"); + + Run("protocol_compiler --test_out=$tmpdir --proto_path=$tmpdir " + "--direct_dependencies=bar.proto foo.proto"); + + ExpectNoErrors(); +} + +TEST_F(CommandLineInterfaceTest, DirectDependencies_NoViolation_MultiImports) { + CreateTempFile("foo.proto", + "syntax = \"proto2\";\n" + "import \"bar.proto\";\n" + "import \"bla.proto\";\n" + "message Foo { optional Bar bar = 1; optional Bla bla = 2; }"); + CreateTempFile("bar.proto", + "syntax = \"proto2\";\n" + "message Bar { optional string text = 1; }"); + CreateTempFile("bla.proto", + "syntax = \"proto2\";\n" + "message Bla { optional int64 number = 1; }"); + + Run("protocol_compiler --test_out=$tmpdir --proto_path=$tmpdir " + "--direct_dependencies=bar.proto:bla.proto foo.proto"); + + ExpectNoErrors(); +} + +TEST_F(CommandLineInterfaceTest, DirectDependencies_ProvidedMultipleTimes) { + CreateTempFile("foo.proto", + "syntax = \"proto2\";\n"); + + Run("protocol_compiler --test_out=$tmpdir --proto_path=$tmpdir " + "--direct_dependencies=bar.proto --direct_dependencies=bla.proto " + "foo.proto"); + + ExpectErrorText( + "--direct_dependencies may only be passed once. To specify multiple " + "direct dependencies, pass them all as a single parameter separated by " + "':'.\n"); +} + TEST_F(CommandLineInterfaceTest, CwdRelativeInputs) { // Test that we can accept working-directory-relative input files. diff --git a/src/google/protobuf/compiler/cpp/cpp_bootstrap_unittest.cc b/src/google/protobuf/compiler/cpp/cpp_bootstrap_unittest.cc index 77451ab1..deef290b 100644 --- a/src/google/protobuf/compiler/cpp/cpp_bootstrap_unittest.cc +++ b/src/google/protobuf/compiler/cpp/cpp_bootstrap_unittest.cc @@ -99,7 +99,6 @@ class MockGeneratorContext : public GeneratorContext { &actual_contents, true)); EXPECT_TRUE(actual_contents == *expected_contents) << physical_filename << " needs to be regenerated. Please run " - "google/protobuf/compiler/release_compiler.sh and " "generate_descriptor_proto.sh. Then add this file " "to your CL."; } diff --git a/src/google/protobuf/compiler/cpp/cpp_enum.cc b/src/google/protobuf/compiler/cpp/cpp_enum.cc index 62b7ed4e..6ced26bc 100644 --- a/src/google/protobuf/compiler/cpp/cpp_enum.cc +++ b/src/google/protobuf/compiler/cpp/cpp_enum.cc @@ -260,7 +260,7 @@ void EnumGenerator::GenerateMethods(io::Printer* printer) { printer->Print(vars, "bool $classname$_IsValid(int value) {\n" - " switch(value) {\n"); + " switch (value) {\n"); // Multiple values may have the same number. Make sure we only cover // each number once by first constructing a set containing all valid diff --git a/src/google/protobuf/compiler/cpp/cpp_enum_field.cc b/src/google/protobuf/compiler/cpp/cpp_enum_field.cc index ffd81529..c3dfa817 100644 --- a/src/google/protobuf/compiler/cpp/cpp_enum_field.cc +++ b/src/google/protobuf/compiler/cpp/cpp_enum_field.cc @@ -83,13 +83,13 @@ void EnumFieldGenerator:: GenerateInlineAccessorDefinitions(io::Printer* printer, bool is_inline) const { map variables(variables_); - variables["inline"] = is_inline ? "inline" : ""; + variables["inline"] = is_inline ? "inline " : ""; printer->Print(variables, - "$inline$ $type$ $classname$::$name$() const {\n" + "$inline$$type$ $classname$::$name$() const {\n" " // @@protoc_insertion_point(field_get:$full_name$)\n" " return static_cast< $type$ >($name$_);\n" "}\n" - "$inline$ void $classname$::set_$name$($type$ value) {\n"); + "$inline$void $classname$::set_$name$($type$ value) {\n"); if (!HasPreservingUnknownEnumSemantics(descriptor_->file())) { printer->Print(variables, " assert($type$_IsValid(value));\n"); @@ -187,16 +187,16 @@ void EnumOneofFieldGenerator:: GenerateInlineAccessorDefinitions(io::Printer* printer, bool is_inline) const { map variables(variables_); - variables["inline"] = is_inline ? "inline" : ""; + variables["inline"] = is_inline ? "inline " : ""; printer->Print(variables, - "$inline$ $type$ $classname$::$name$() const {\n" + "$inline$$type$ $classname$::$name$() const {\n" " // @@protoc_insertion_point(field_get:$full_name$)\n" " if (has_$name$()) {\n" " return static_cast< $type$ >($oneof_prefix$$name$_);\n" " }\n" " return static_cast< $type$ >($default$);\n" "}\n" - "$inline$ void $classname$::set_$name$($type$ value) {\n"); + "$inline$void $classname$::set_$name$($type$ value) {\n"); if (!HasPreservingUnknownEnumSemantics(descriptor_->file())) { printer->Print(variables, " assert($type$_IsValid(value));\n"); @@ -263,13 +263,13 @@ void RepeatedEnumFieldGenerator:: GenerateInlineAccessorDefinitions(io::Printer* printer, bool is_inline) const { map variables(variables_); - variables["inline"] = is_inline ? "inline" : ""; + variables["inline"] = is_inline ? "inline " : ""; printer->Print(variables, - "$inline$ $type$ $classname$::$name$(int index) const {\n" + "$inline$$type$ $classname$::$name$(int index) const {\n" " // @@protoc_insertion_point(field_get:$full_name$)\n" " return static_cast< $type$ >($name$_.Get(index));\n" "}\n" - "$inline$ void $classname$::set_$name$(int index, $type$ value) {\n"); + "$inline$void $classname$::set_$name$(int index, $type$ value) {\n"); if (!HasPreservingUnknownEnumSemantics(descriptor_->file())) { printer->Print(variables, " assert($type$_IsValid(value));\n"); @@ -278,7 +278,7 @@ GenerateInlineAccessorDefinitions(io::Printer* printer, " $name$_.Set(index, value);\n" " // @@protoc_insertion_point(field_set:$full_name$)\n" "}\n" - "$inline$ void $classname$::add_$name$($type$ value) {\n"); + "$inline$void $classname$::add_$name$($type$ value) {\n"); if (!HasPreservingUnknownEnumSemantics(descriptor_->file())) { printer->Print(variables, " assert($type$_IsValid(value));\n"); @@ -288,12 +288,12 @@ GenerateInlineAccessorDefinitions(io::Printer* printer, " // @@protoc_insertion_point(field_add:$full_name$)\n" "}\n"); printer->Print(variables, - "$inline$ const ::google::protobuf::RepeatedField&\n" + "$inline$const ::google::protobuf::RepeatedField&\n" "$classname$::$name$() const {\n" " // @@protoc_insertion_point(field_list:$full_name$)\n" " return $name$_;\n" "}\n" - "$inline$ ::google::protobuf::RepeatedField*\n" + "$inline$::google::protobuf::RepeatedField*\n" "$classname$::mutable_$name$() {\n" " // @@protoc_insertion_point(field_mutable_list:$full_name$)\n" " return &$name$_;\n" @@ -310,6 +310,11 @@ GenerateMergingCode(io::Printer* printer) const { printer->Print(variables_, "$name$_.MergeFrom(from.$name$_);\n"); } +void RepeatedEnumFieldGenerator:: +GenerateUnsafeMergingCode(io::Printer* printer) const { + printer->Print(variables_, "$name$_.UnsafeMergeFrom(from.$name$_);\n"); +} + void RepeatedEnumFieldGenerator:: GenerateSwappingCode(io::Printer* printer) const { printer->Print(variables_, "$name$_.UnsafeArenaSwap(&other->$name$_);\n"); @@ -475,10 +480,11 @@ void RepeatedEnumFieldGenerator:: GenerateByteSize(io::Printer* printer) const { printer->Print(variables_, "{\n" - " int data_size = 0;\n"); + " size_t data_size = 0;\n" + " unsigned int count = this->$name$_size();"); printer->Indent(); printer->Print(variables_, - "for (int i = 0; i < this->$name$_size(); i++) {\n" + "for (unsigned int i = 0; i < count; i++) {\n" " data_size += ::google::protobuf::internal::WireFormatLite::EnumSize(\n" " this->$name$(i));\n" "}\n"); @@ -489,13 +495,14 @@ GenerateByteSize(io::Printer* printer) const { " total_size += $tag_size$ +\n" " ::google::protobuf::internal::WireFormatLite::Int32Size(data_size);\n" "}\n" + "int cached_size = ::google::protobuf::internal::ToCachedSize(data_size);\n" "GOOGLE_SAFE_CONCURRENT_WRITES_BEGIN();\n" - "_$name$_cached_byte_size_ = data_size;\n" + "_$name$_cached_byte_size_ = cached_size;\n" "GOOGLE_SAFE_CONCURRENT_WRITES_END();\n" "total_size += data_size;\n"); } else { printer->Print(variables_, - "total_size += $tag_size$ * this->$name$_size() + data_size;\n"); + "total_size += ($tag_size$UL * count) + data_size;\n"); } printer->Outdent(); printer->Print("}\n"); diff --git a/src/google/protobuf/compiler/cpp/cpp_enum_field.h b/src/google/protobuf/compiler/cpp/cpp_enum_field.h index fe21c575..57ffeec5 100644 --- a/src/google/protobuf/compiler/cpp/cpp_enum_field.h +++ b/src/google/protobuf/compiler/cpp/cpp_enum_field.h @@ -101,6 +101,7 @@ class RepeatedEnumFieldGenerator : public FieldGenerator { bool is_inline) const; void GenerateClearingCode(io::Printer* printer) const; void GenerateMergingCode(io::Printer* printer) const; + void GenerateUnsafeMergingCode(io::Printer* printer) const; void GenerateSwappingCode(io::Printer* printer) const; void GenerateConstructorCode(io::Printer* printer) const; void GenerateMergeFromCodedStream(io::Printer* printer) const; diff --git a/src/google/protobuf/compiler/cpp/cpp_extension.cc b/src/google/protobuf/compiler/cpp/cpp_extension.cc index c42f1627..4554c72c 100644 --- a/src/google/protobuf/compiler/cpp/cpp_extension.cc +++ b/src/google/protobuf/compiler/cpp/cpp_extension.cc @@ -178,28 +178,30 @@ void ExtensionGenerator::GenerateRegistration(io::Printer* printer) { switch (descriptor_->cpp_type()) { case FieldDescriptor::CPPTYPE_ENUM: - printer->Print(vars, - "::google::protobuf::internal::ExtensionSet::RegisterEnumExtension(\n" - " &$extendee$::default_instance(),\n" - " $number$, $field_type$, $is_repeated$, $is_packed$,\n"); + printer->Print( + vars, + "::google::protobuf::internal::ExtensionSet::RegisterEnumExtension(\n" + " $extendee$::internal_default_instance(),\n" + " $number$, $field_type$, $is_repeated$, $is_packed$,\n"); printer->Print( " &$type$_IsValid);\n", "type", ClassName(descriptor_->enum_type(), true)); break; case FieldDescriptor::CPPTYPE_MESSAGE: - printer->Print(vars, - "::google::protobuf::internal::ExtensionSet::RegisterMessageExtension(\n" - " &$extendee$::default_instance(),\n" - " $number$, $field_type$, $is_repeated$, $is_packed$,\n"); printer->Print( - " &$type$::default_instance());\n", - "type", ClassName(descriptor_->message_type(), true)); + vars, + "::google::protobuf::internal::ExtensionSet::RegisterMessageExtension(\n" + " $extendee$::internal_default_instance(),\n" + " $number$, $field_type$, $is_repeated$, $is_packed$,\n"); + printer->Print(" $type$::internal_default_instance());\n", "type", + ClassName(descriptor_->message_type(), true)); break; default: - printer->Print(vars, - "::google::protobuf::internal::ExtensionSet::RegisterExtension(\n" - " &$extendee$::default_instance(),\n" - " $number$, $field_type$, $is_repeated$, $is_packed$);\n"); + printer->Print( + vars, + "::google::protobuf::internal::ExtensionSet::RegisterExtension(\n" + " $extendee$::internal_default_instance(),\n" + " $number$, $field_type$, $is_repeated$, $is_packed$);\n"); break; } } diff --git a/src/google/protobuf/compiler/cpp/cpp_field.h b/src/google/protobuf/compiler/cpp/cpp_field.h index 3b012527..fdd338a6 100644 --- a/src/google/protobuf/compiler/cpp/cpp_field.h +++ b/src/google/protobuf/compiler/cpp/cpp_field.h @@ -136,6 +136,13 @@ class FieldGenerator { // GenerateMergeFrom method. virtual void GenerateMergingCode(io::Printer* printer) const = 0; + // The same, but the generated code may or may not check the possibility that + // the two objects being merged have the same address. To be safe, callers + // should avoid calling this unless they know the objects are different. + virtual void GenerateUnsafeMergingCode(io::Printer* printer) const { + GenerateMergingCode(printer); + } + // Generate lines of code (statements, not declarations) which swaps // this field and the corresponding field of another message, which // is stored in the generated code variable "other". This is used to diff --git a/src/google/protobuf/compiler/cpp/cpp_file.cc b/src/google/protobuf/compiler/cpp/cpp_file.cc index b3eca660..369497ce 100644 --- a/src/google/protobuf/compiler/cpp/cpp_file.cc +++ b/src/google/protobuf/compiler/cpp/cpp_file.cc @@ -89,7 +89,7 @@ FileGenerator::FileGenerator(const FileDescriptor* file, const Options& options) new ExtensionGenerator(file->extension(i), options)); } - SplitStringUsing(file_->package(), ".", &package_parts_); + package_parts_ = Split(file_->package(), ".", true); } FileGenerator::~FileGenerator() {} @@ -336,6 +336,20 @@ void FileGenerator::GenerateSource(io::Printer* printer) { // Generate classes. for (int i = 0; i < file_->message_type_count(); i++) { + if (i == 0 && HasGeneratedMethods(file_, options_)) { + printer->Print( + "\n" + "namespace {\n" + "\n" + "static void MergeFromFail(int line) GOOGLE_ATTRIBUTE_COLD" + " GOOGLE_ATTRIBUTE_NORETURN;\n" + "static void MergeFromFail(int line) {\n" + " ::google::protobuf::internal::MergeFromFail(__FILE__, line);\n" + "}\n" + "\n" + "} // namespace\n" + "\n"); + } printer->Print("\n"); printer->Print(kThickSeparator); printer->Print("\n"); @@ -449,6 +463,7 @@ void FileGenerator::GenerateBuildDescriptors(io::Printer* printer) { // In optimize_for = LITE_RUNTIME mode, we don't generate AssignDescriptors() // and we only use AddDescriptors() to allocate default instances. + if (HasDescriptorMethods(file_, options_)) { printer->Print( "\n" @@ -500,15 +515,15 @@ void FileGenerator::GenerateBuildDescriptors(io::Printer* printer) { // AssignDescriptors(). All later times, waits for the first call to // complete and then returns. printer->Print( - "namespace {\n" - "\n" - "GOOGLE_PROTOBUF_DECLARE_ONCE(protobuf_AssignDescriptors_once_);\n" - "inline void protobuf_AssignDescriptorsOnce() {\n" - " ::google::protobuf::GoogleOnceInit(&protobuf_AssignDescriptors_once_,\n" - " &$assigndescriptorsname$);\n" - "}\n" - "\n", - "assigndescriptorsname", GlobalAssignDescriptorsName(file_->name())); + "namespace {\n" + "\n" + "GOOGLE_PROTOBUF_DECLARE_ONCE(protobuf_AssignDescriptors_once_);\n" + "void protobuf_AssignDescriptorsOnce() {\n" + " ::google::protobuf::GoogleOnceInit(&protobuf_AssignDescriptors_once_,\n" + " &$assigndescriptorsname$);\n" + "}\n" + "\n", + "assigndescriptorsname", GlobalAssignDescriptorsName(file_->name())); // protobuf_RegisterTypes(): Calls // MessageFactory::InternalRegisterGeneratedType() for each message type. @@ -548,44 +563,68 @@ void FileGenerator::GenerateBuildDescriptors(io::Printer* printer) { // ----------------------------------------------------------------- - // Now generate the AddDescriptors() function. - PrintHandlingOptionalStaticInitializers( - file_, options_, printer, - // With static initializers. - // Note that we don't need any special synchronization in the following - // code - // because it is called at static init time before any threads exist. - "void $adddescriptorsname$() GOOGLE_ATTRIBUTE_COLD;\n" - "void $adddescriptorsname$() {\n" - " static bool already_here = false;\n" - " if (already_here) return;\n" - " already_here = true;\n" - " GOOGLE_PROTOBUF_VERIFY_VERSION;\n" - "\n", - // Without. - "void $adddescriptorsname$_impl() {\n" + // Now generate the InitDefaults() function. + printer->Print( + "void $initdefaultsname$_impl() {\n" " GOOGLE_PROTOBUF_VERIFY_VERSION;\n" "\n", // Vars. - "adddescriptorsname", GlobalAddDescriptorsName(file_->name())); + "initdefaultsname", GlobalInitDefaultsName(file_->name())); printer->Indent(); - // Call the AddDescriptors() methods for all of our dependencies, to make + // Call the InitDefaults() methods for all of our dependencies, to make // sure they get added first. for (int i = 0; i < file_->dependency_count(); i++) { const FileDescriptor* dependency = file_->dependency(i); // Print the namespace prefix for the dependency. string add_desc_name = QualifiedFileLevelSymbol( - dependency->package(), GlobalAddDescriptorsName(dependency->name())); + dependency->package(), GlobalInitDefaultsName(dependency->name())); // Call its AddDescriptors function. printer->Print( "$name$();\n", "name", add_desc_name); } + // Allocate and initialize default instances. This can't be done lazily + // since default instances are returned by simple accessors and are used with + // extensions. Speaking of which, we also register extensions at this time. + for (int i = 0; i < file_->message_type_count(); i++) { + message_generators_[i]->GenerateDefaultInstanceAllocator(printer); + } + for (int i = 0; i < file_->extension_count(); i++) { + extension_generators_[i]->GenerateRegistration(printer); + } + for (int i = 0; i < file_->message_type_count(); i++) { + message_generators_[i]->GenerateDefaultInstanceInitializer(printer); + } + printer->Outdent(); + printer->Print( + "}\n" + "\n" + "GOOGLE_PROTOBUF_DECLARE_ONCE($initdefaultsname$_once_);\n" + "void $initdefaultsname$() {\n" + " ::google::protobuf::GoogleOnceInit(&$initdefaultsname$_once_,\n" + " &$initdefaultsname$_impl);\n" + "}\n", + "initdefaultsname", GlobalInitDefaultsName(file_->name())); + + // ----------------------------------------------------------------- + + // Now generate the AddDescriptors() function. + printer->Print( + "void $adddescriptorsname$_impl() {\n" + " GOOGLE_PROTOBUF_VERIFY_VERSION;\n" + "\n" + " $initdefaultsname$();\n", + // Vars. + "adddescriptorsname", GlobalAddDescriptorsName(file_->name()), + "initdefaultsname", GlobalInitDefaultsName(file_->name())); + + printer->Indent(); if (HasDescriptorMethods(file_, options_)) { - // Embed the descriptor. We simply serialize the entire FileDescriptorProto + // Embed the descriptor. We simply serialize the entire + // FileDescriptorProto // and embed it as a string literal, which is parsed and built into real // descriptors at initialization time. FileDescriptorProto file_proto; @@ -655,30 +694,37 @@ void FileGenerator::GenerateBuildDescriptors(io::Printer* printer) { "filename", file_->name()); } - // Allocate and initialize default instances. This can't be done lazily - // since default instances are returned by simple accessors and are used with - // extensions. Speaking of which, we also register extensions at this time. - for (int i = 0; i < file_->message_type_count(); i++) { - message_generators_[i]->GenerateDefaultInstanceAllocator(printer); - } - for (int i = 0; i < file_->extension_count(); i++) { - extension_generators_[i]->GenerateRegistration(printer); - } - for (int i = 0; i < file_->message_type_count(); i++) { - message_generators_[i]->GenerateDefaultInstanceInitializer(printer); + // Call the AddDescriptors() methods for all of our dependencies, to make + // sure they get added first. + for (int i = 0; i < file_->dependency_count(); i++) { + const FileDescriptor* dependency = file_->dependency(i); + // Print the namespace prefix for the dependency. + string add_desc_name = QualifiedFileLevelSymbol( + dependency->package(), GlobalAddDescriptorsName(dependency->name())); + // Call its AddDescriptors function. + printer->Print("$adddescriptorsname$();\n", "adddescriptorsname", + add_desc_name); } printer->Print( - "::google::protobuf::internal::OnShutdown(&$shutdownfilename$);\n", - "shutdownfilename", GlobalShutdownFileName(file_->name())); + "::google::protobuf::internal::OnShutdown(&$shutdownfilename$);\n", + "shutdownfilename", GlobalShutdownFileName(file_->name())); printer->Outdent(); printer->Print( - "}\n" - "\n"); + "}\n" + "\n" + "GOOGLE_PROTOBUF_DECLARE_ONCE($adddescriptorsname$_once_);\n" + "void $adddescriptorsname$() {\n" + " ::google::protobuf::GoogleOnceInit(&$adddescriptorsname$_once_,\n" + " &$adddescriptorsname$_impl);\n" + "}\n", + "adddescriptorsname", GlobalAddDescriptorsName(file_->name())); - PrintHandlingOptionalStaticInitializers( - file_, options_, printer, + if (!StaticInitializersForced(file_, options_)) { + printer->Print("#ifdef GOOGLE_PROTOBUF_NO_STATIC_INITIALIZER\n"); + } + printer->Print( // With static initializers. "// Force AddDescriptors() to be called at static initialization time.\n" "struct StaticDescriptorInitializer_$filename$ {\n" @@ -686,15 +732,12 @@ void FileGenerator::GenerateBuildDescriptors(io::Printer* printer) { " $adddescriptorsname$();\n" " }\n" "} static_descriptor_initializer_$filename$_;\n", - // Without. - "GOOGLE_PROTOBUF_DECLARE_ONCE($adddescriptorsname$_once_);\n" - "void $adddescriptorsname$() {\n" - " ::google::protobuf::GoogleOnceInit(&$adddescriptorsname$_once_,\n" - " &$adddescriptorsname$_impl);\n" - "}\n", // Vars. "adddescriptorsname", GlobalAddDescriptorsName(file_->name()), "filename", FilenameIdentifier(file_->name())); + if (!StaticInitializersForced(file_, options_)) { + printer->Print("#endif // GOOGLE_PROTOBUF_NO_STATIC_INITIALIZER\n"); + } } void FileGenerator::GenerateNamespaceOpeners(io::Printer* printer) { @@ -892,12 +935,14 @@ void FileGenerator::GenerateGlobalStateFunctionDeclarations( // Forward-declare the AddDescriptors, AssignDescriptors, and ShutdownFile // functions, so that we can declare them to be friends of each class. printer->Print( - "\n" - "// Internal implementation detail -- do not call these.\n" - "void $dllexport_decl$$adddescriptorsname$();\n", - "adddescriptorsname", GlobalAddDescriptorsName(file_->name()), - "dllexport_decl", - options_.dllexport_decl.empty() ? "" : options_.dllexport_decl + " "); + "\n" + "// Internal implementation detail -- do not call these.\n" + "void $dllexport_decl$$adddescriptorsname$();\n" + "void $dllexport_decl$$initdefaultsname$();\n", + "initdefaultsname", GlobalInitDefaultsName(file_->name()), + "adddescriptorsname", GlobalAddDescriptorsName(file_->name()), + "dllexport_decl", + options_.dllexport_decl.empty() ? "" : options_.dllexport_decl + " "); printer->Print( // Note that we don't put dllexport_decl on these because they are only diff --git a/src/google/protobuf/compiler/cpp/cpp_helpers.cc b/src/google/protobuf/compiler/cpp/cpp_helpers.cc index 2ad4d36a..6d844cc2 100644 --- a/src/google/protobuf/compiler/cpp/cpp_helpers.cc +++ b/src/google/protobuf/compiler/cpp/cpp_helpers.cc @@ -415,7 +415,8 @@ string DefaultValue(const FieldDescriptor* field) { CEscape(field->default_value_string())) + "\""; case FieldDescriptor::CPPTYPE_MESSAGE: - return FieldMessageTypeName(field) + "::default_instance()"; + return "*" + FieldMessageTypeName(field) + + "::internal_default_instance()"; } // Can't actually get here; make compiler happy. (We could add a default // case above but then we wouldn't get the nice compiler warning when a @@ -444,6 +445,10 @@ string GlobalAddDescriptorsName(const string& filename) { return "protobuf_AddDesc_" + FilenameIdentifier(filename); } +string GlobalInitDefaultsName(const string& filename) { + return "protobuf_InitDefaults_" + FilenameIdentifier(filename); +} + // Return the name of the AssignDescriptors() function for a given file. string GlobalAssignDescriptorsName(const string& filename) { return "protobuf_AssignDesc_" + FilenameIdentifier(filename); @@ -500,40 +505,6 @@ bool StaticInitializersForced(const FileDescriptor* file, return false; } -void PrintHandlingOptionalStaticInitializers( - const FileDescriptor* file, const Options& options, io::Printer* printer, - const char* with_static_init, const char* without_static_init, - const char* var1, const string& val1, const char* var2, - const string& val2) { - map vars; - if (var1) { - vars[var1] = val1; - } - if (var2) { - vars[var2] = val2; - } - PrintHandlingOptionalStaticInitializers( - vars, file, options, printer, with_static_init, without_static_init); -} - -void PrintHandlingOptionalStaticInitializers(const map& vars, - const FileDescriptor* file, - const Options& options, - io::Printer* printer, - const char* with_static_init, - const char* without_static_init) { - if (StaticInitializersForced(file, options)) { - printer->Print(vars, with_static_init); - } else { - printer->Print(vars, (string( - "#ifdef GOOGLE_PROTOBUF_NO_STATIC_INITIALIZER\n") + - without_static_init + - "#else\n" + - with_static_init + - "#endif\n").c_str()); - } -} - static bool HasMapFields(const Descriptor* descriptor) { for (int i = 0; i < descriptor->field_count(); ++i) { diff --git a/src/google/protobuf/compiler/cpp/cpp_helpers.h b/src/google/protobuf/compiler/cpp/cpp_helpers.h index 018acfca..3a0c0388 100644 --- a/src/google/protobuf/compiler/cpp/cpp_helpers.h +++ b/src/google/protobuf/compiler/cpp/cpp_helpers.h @@ -147,6 +147,9 @@ string FilenameIdentifier(const string& filename); // Return the name of the AddDescriptors() function for a given file. string GlobalAddDescriptorsName(const string& filename); +// Return the name of the InitDefaults() function for a given file. +string GlobalInitDefaultsName(const string& filename); + // Return the name of the AssignDescriptors() function for a given file. string GlobalAssignDescriptorsName(const string& filename); @@ -223,22 +226,6 @@ inline bool HasFastArraySerialization(const FileDescriptor* file, bool StaticInitializersForced(const FileDescriptor* file, const Options& options); -// Prints 'with_static_init' if static initializers have to be used for the -// provided file. Otherwise emits both 'with_static_init' and -// 'without_static_init' using #ifdef. -void PrintHandlingOptionalStaticInitializers( - const FileDescriptor* file, const Options& options, io::Printer* printer, - const char* with_static_init, const char* without_static_init, - const char* var1 = NULL, const string& val1 = "", const char* var2 = NULL, - const string& val2 = ""); - -void PrintHandlingOptionalStaticInitializers(const map& vars, - const FileDescriptor* file, - const Options& options, - io::Printer* printer, - const char* with_static_init, - const char* without_static_init); - inline bool IsMapEntryMessage(const Descriptor* descriptor) { return descriptor->options().map_entry(); diff --git a/src/google/protobuf/compiler/cpp/cpp_map_field.cc b/src/google/protobuf/compiler/cpp/cpp_map_field.cc index 0588e34e..31ac9ca7 100644 --- a/src/google/protobuf/compiler/cpp/cpp_map_field.cc +++ b/src/google/protobuf/compiler/cpp/cpp_map_field.cc @@ -399,7 +399,8 @@ void MapFieldGenerator::GenerateSerializeWithCachedSizes( void MapFieldGenerator:: GenerateByteSize(io::Printer* printer) const { printer->Print(variables_, - "total_size += $tag_size$ * this->$name$_size();\n" + "total_size += $tag_size$ *\n" + " ::google::protobuf::internal::FromIntSize(this->$name$_size());\n" "{\n" " ::google::protobuf::scoped_ptr<$map_classname$> entry;\n" " for (::google::protobuf::Map< $key_cpp$, $val_cpp$ >::const_iterator\n" diff --git a/src/google/protobuf/compiler/cpp/cpp_message.cc b/src/google/protobuf/compiler/cpp/cpp_message.cc index 1f1a0f1c..f5648663 100644 --- a/src/google/protobuf/compiler/cpp/cpp_message.cc +++ b/src/google/protobuf/compiler/cpp/cpp_message.cc @@ -85,14 +85,13 @@ struct FieldOrderingByNumber { // Sort the fields of the given Descriptor by number into a new[]'d array // and return it. -const FieldDescriptor** SortFieldsByNumber(const Descriptor* descriptor) { - const FieldDescriptor** fields = - new const FieldDescriptor*[descriptor->field_count()]; +std::vector SortFieldsByNumber( + const Descriptor* descriptor) { + std::vector fields(descriptor->field_count()); for (int i = 0; i < descriptor->field_count(); i++) { fields[i] = descriptor->field(i); } - std::sort(fields, fields + descriptor->field_count(), - FieldOrderingByNumber()); + std::sort(fields.begin(), fields.end(), FieldOrderingByNumber()); return fields; } @@ -227,59 +226,150 @@ class FieldGroup { // used in a vector. }; +// Helper for the code that emits the Clear() method. +bool CanInitializeByZeroing(const FieldDescriptor* field) { + if (field->is_repeated() || field->is_extension()) return false; + switch (field->cpp_type()) { + case internal::WireFormatLite::CPPTYPE_ENUM: + return field->default_value_enum()->number() == 0; + case internal::WireFormatLite::CPPTYPE_INT32: + return field->default_value_int32() == 0; + case internal::WireFormatLite::CPPTYPE_INT64: + return field->default_value_int64() == 0; + case internal::WireFormatLite::CPPTYPE_UINT32: + return field->default_value_uint32() == 0; + case internal::WireFormatLite::CPPTYPE_UINT64: + return field->default_value_uint64() == 0; + case internal::WireFormatLite::CPPTYPE_FLOAT: + return field->default_value_float() == 0; + case internal::WireFormatLite::CPPTYPE_DOUBLE: + return field->default_value_double() == 0; + case internal::WireFormatLite::CPPTYPE_BOOL: + return field->default_value_bool() == false; + default: + return false; + } +} + // Reorder 'fields' so that if the fields are output into a c++ class in the new -// order, the alignment padding is minimized. We try to do this while keeping -// each field as close as possible to its original position so that we don't -// reduce cache locality much for function that access each field in order. +// order, fields of similiar family (see below) are together and within each +// family, alignment padding is minimized. +// +// We try to do this while keeping each field as close as possible to its +// declaration order (from the .proto file) so that we don't reduce cache +// locality much for function that access each field in order. This is also the +// only (weak) signal we have for author intent concerning field layout. +// +// TODO(ckennelly): Update these functions to use the optimized layout order +// for their access patterns. +// +// TODO(ckennelly): If/when we have profiles available for the compiler, use +// those rather than respect declaration order. +// +// We classify each field into a particular "family" of fields, that we perform +// the same operation on in our generated functions. +// +// REPEATED is placed first, as the C++ compiler automatically initializes +// these fields in layout order. +// +// STRING is grouped next, as our Clear/SharedCtor/SharedDtor walks it and +// calls ArenaStringPtr::Destroy on each. +// +// MESSAGE is grouped next, as our Clear/SharedDtor code walks it and calls +// delete on each. We initialize these fields with a NULL pointer (see +// MessageFieldGenerator::GenerateConstructorCode). +// TODO(ckennelly): memset these in SharedCtor. +// +// ZERO_INITIALIZABLE is memset in Clear/SharedCtor +// +// OTHER these fields are initialized one-by-one. void OptimizePadding(vector* fields) { + // The sorted numeric order of Family determines the declaration order in the + // memory layout. + enum Family { + REPEATED = 0, + STRING = 1, + MESSAGE = 2, + ZERO_INITIALIZABLE = 3, + OTHER = 4, + kMaxFamily + }; + // First divide fields into those that align to 1 byte, 4 bytes or 8 bytes. - vector aligned_to_1, aligned_to_4, aligned_to_8; + vector aligned_to_1[kMaxFamily]; + vector aligned_to_4[kMaxFamily]; + vector aligned_to_8[kMaxFamily]; for (int i = 0; i < fields->size(); ++i) { - switch (EstimateAlignmentSize((*fields)[i])) { - case 1: aligned_to_1.push_back(FieldGroup(i, (*fields)[i])); break; - case 4: aligned_to_4.push_back(FieldGroup(i, (*fields)[i])); break; - case 8: aligned_to_8.push_back(FieldGroup(i, (*fields)[i])); break; - default: - GOOGLE_LOG(FATAL) << "Unknown alignment size."; + const FieldDescriptor* field = (*fields)[i]; + + Family f = OTHER; + if (field->is_repeated()) { + f = REPEATED; + } else if (field->cpp_type() == FieldDescriptor::CPPTYPE_STRING) { + f = STRING; + } else if (field->cpp_type() == FieldDescriptor::CPPTYPE_MESSAGE) { + f = MESSAGE; + } else if (CanInitializeByZeroing(field)) { + f = ZERO_INITIALIZABLE; } - } - // Now group fields aligned to 1 byte into sets of 4, and treat those like a - // single field aligned to 4 bytes. - for (int i = 0; i < aligned_to_1.size(); i += 4) { - FieldGroup field_group; - for (int j = i; j < aligned_to_1.size() && j < i + 4; ++j) { - field_group.Append(aligned_to_1[j]); + switch (EstimateAlignmentSize(field)) { + case 1: aligned_to_1[f].push_back(FieldGroup(i, field)); break; + case 4: aligned_to_4[f].push_back(FieldGroup(i, field)); break; + case 8: aligned_to_8[f].push_back(FieldGroup(i, field)); break; + default: + GOOGLE_LOG(FATAL) << "Unknown alignment size."; } - aligned_to_4.push_back(field_group); } - // Sort by preferred location to keep fields as close to their original - // location as possible. Using stable_sort ensures that the output is - // consistent across runs. - std::stable_sort(aligned_to_4.begin(), aligned_to_4.end()); - // Now group fields aligned to 4 bytes (or the 4-field groups created above) - // into pairs, and treat those like a single field aligned to 8 bytes. - for (int i = 0; i < aligned_to_4.size(); i += 2) { - FieldGroup field_group; - for (int j = i; j < aligned_to_4.size() && j < i + 2; ++j) { - field_group.Append(aligned_to_4[j]); - } - if (i == aligned_to_4.size() - 1) { - // Move incomplete 4-byte block to the end. - field_group.SetPreferredLocation(fields->size() + 1); + // For each family, group fields to optimize padding. + for (int f = 0; f < kMaxFamily; f++) { + // Now group fields aligned to 1 byte into sets of 4, and treat those like a + // single field aligned to 4 bytes. + for (int i = 0; i < aligned_to_1[f].size(); i += 4) { + FieldGroup field_group; + for (int j = i; j < aligned_to_1[f].size() && j < i + 4; ++j) { + field_group.Append(aligned_to_1[f][j]); + } + aligned_to_4[f].push_back(field_group); + } + // Sort by preferred location to keep fields as close to their declaration + // order as possible. Using stable_sort ensures that the output is + // consistent across runs. + std::stable_sort(aligned_to_4[f].begin(), aligned_to_4[f].end()); + + // Now group fields aligned to 4 bytes (or the 4-field groups created above) + // into pairs, and treat those like a single field aligned to 8 bytes. + for (int i = 0; i < aligned_to_4[f].size(); i += 2) { + FieldGroup field_group; + for (int j = i; j < aligned_to_4[f].size() && j < i + 2; ++j) { + field_group.Append(aligned_to_4[f][j]); + } + if (i == aligned_to_4[f].size() - 1) { + if (f == OTHER) { + // Move incomplete 4-byte block to the beginning. This is done to + // pair with the (possible) leftover blocks from the + // ZERO_INITIALIZABLE family. + field_group.SetPreferredLocation(-1); + } else { + // Move incomplete 4-byte block to the end. + field_group.SetPreferredLocation(fields->size() + 1); + } + } + aligned_to_8[f].push_back(field_group); } - aligned_to_8.push_back(field_group); + // Sort by preferred location. + std::stable_sort(aligned_to_8[f].begin(), aligned_to_8[f].end()); } - // Sort by preferred location. - std::stable_sort(aligned_to_8.begin(), aligned_to_8.end()); // Now pull out all the FieldDescriptors in order. fields->clear(); - for (int i = 0; i < aligned_to_8.size(); ++i) { - fields->insert(fields->end(), - aligned_to_8[i].fields().begin(), - aligned_to_8[i].fields().end()); + for (int f = 0; f < kMaxFamily; ++f) { + for (int i = 0; i < aligned_to_8[f].size(); ++i) { + fields->insert(fields->end(), + aligned_to_8[f][i].fields().begin(), + aligned_to_8[f][i].fields().end()); + } } } @@ -337,6 +427,20 @@ bool HasHasMethod(const FieldDescriptor* field) { return field->cpp_type() == FieldDescriptor::CPPTYPE_MESSAGE; } +size_t HasBitsSize(const Descriptor* descriptor) { + // TODO(jieluo) - Optimize _has_bits_ for repeated and oneof fields. + size_t sizeof_has_bits = (descriptor->field_count() + 31) / 32 * 4; + if (descriptor->field_count() == 0) { + // Zero-size arrays aren't technically allowed, and MSVC in particular + // doesn't like them. We still need to declare these arrays to make + // other code compile. Since this is an uncommon case, we'll just declare + // them with size 1 and waste some space. Oh well. + sizeof_has_bits = 4; + } + + return sizeof_has_bits; +} + // Collects map entry message type information. void CollectMapInfo(const Descriptor* descriptor, map* variables) { @@ -389,6 +493,15 @@ MessageGenerator::MessageGenerator(const Descriptor* descriptor, ExtensionGenerator>[descriptor->extension_count()]), use_dependent_base_(false) { + // Compute optimized field order to be used for layout and initialization + // purposes. + for (int i = 0; i < descriptor_->field_count(); i++) { + if (!descriptor_->field(i)->containing_oneof()) { + optimized_order_.push_back(descriptor_->field(i)); + } + } + OptimizePadding(&optimized_order_); + for (int i = 0; i < descriptor->nested_type_count(); i++) { nested_generators_[i].reset( new MessageGenerator(descriptor->nested_type(i), options)); @@ -644,11 +757,12 @@ GenerateSingularFieldHasBits(const FieldDescriptor* field, " return !$name$_.IsCleared();\n" "}\n"); } else { - printer->Print(vars, - "$inline$" - "bool $classname$::has_$name$() const {\n" - " return !_is_default_instance_ && $name$_ != NULL;\n" - "}\n"); + printer->Print( + vars, + "$inline$" + "bool $classname$::has_$name$() const {\n" + " return this != internal_default_instance() && $name$_ != NULL;\n" + "}\n"); } } } @@ -805,31 +919,6 @@ GenerateFieldAccessorDefinitions(io::Printer* printer, bool is_inline) { } } -// Helper for the code that emits the Clear() method. -static bool CanClearByZeroing(const FieldDescriptor* field) { - if (field->is_repeated() || field->is_extension()) return false; - switch (field->cpp_type()) { - case internal::WireFormatLite::CPPTYPE_ENUM: - return field->default_value_enum()->number() == 0; - case internal::WireFormatLite::CPPTYPE_INT32: - return field->default_value_int32() == 0; - case internal::WireFormatLite::CPPTYPE_INT64: - return field->default_value_int64() == 0; - case internal::WireFormatLite::CPPTYPE_UINT32: - return field->default_value_uint32() == 0; - case internal::WireFormatLite::CPPTYPE_UINT64: - return field->default_value_uint64() == 0; - case internal::WireFormatLite::CPPTYPE_FLOAT: - return field->default_value_float() == 0; - case internal::WireFormatLite::CPPTYPE_DOUBLE: - return field->default_value_double() == 0; - case internal::WireFormatLite::CPPTYPE_BOOL: - return field->default_value_bool() == false; - default: - return false; - } -} - void MessageGenerator:: GenerateDependentBaseClassDefinition(io::Printer* printer) { if (!use_dependent_base_) { @@ -1009,19 +1098,13 @@ GenerateClassDefinition(io::Printer* printer) { "\n"); } - if (!StaticInitializersForced(descriptor_->file(), options_)) { - printer->Print(vars, - "#ifdef GOOGLE_PROTOBUF_NO_STATIC_INITIALIZER\n" - "// Returns the internal default instance pointer. This function can\n" - "// return NULL thus should not be used by the user. This is intended\n" - "// for Protobuf internal code. Please use default_instance() declared\n" - "// above instead.\n" + // TODO(gerbens) make this private, while still granting other protos access. + printer->Print( + vars, "static inline const $classname$* internal_default_instance() {\n" - " return default_instance_;\n" + " return &default_instance_.get();\n" "}\n" - "#endif\n" "\n"); - } if (SupportsArenas(descriptor_)) { @@ -1068,7 +1151,7 @@ GenerateClassDefinition(io::Printer* printer) { "void Clear();\n" "bool IsInitialized() const;\n" "\n" - "int ByteSize() const;\n" + "size_t ByteSizeLong() const;\n" "bool MergePartialFromCodedStream(\n" " ::google::protobuf::io::CodedInputStream* input);\n" "void SerializeWithCachedSizes(\n" @@ -1131,7 +1214,8 @@ GenerateClassDefinition(io::Printer* printer) { "void SharedCtor();\n" "void SharedDtor();\n" "void SetCachedSize(int size) const;\n" - "void InternalSwap($classname$* other);\n", + "void InternalSwap($classname$* other);\n" + "void UnsafeMergeFrom(const $classname$& from);\n", "classname", classname_); if (SupportsArenas(descriptor_)) { printer->Print( @@ -1260,8 +1344,8 @@ GenerateClassDefinition(io::Printer* printer) { !descriptor_->options().message_set_wire_format() && num_required_fields_ > 1) { printer->Print( - "// helper for ByteSize()\n" - "int RequiredFieldsByteSizeFallback() const;\n\n"); + "// helper for ByteSizeLong()\n" + "size_t RequiredFieldsByteSizeFallback() const;\n\n"); } // Prepare decls for _cached_size_ and _has_bits_. Their position in the @@ -1271,18 +1355,10 @@ GenerateClassDefinition(io::Printer* printer) { // TODO(kenton): Make _cached_size_ an atomic when C++ supports it. const string cached_size_decl = "mutable int _cached_size_;\n"; - // TODO(jieluo) - Optimize _has_bits_ for repeated and oneof fields. - size_t sizeof_has_bits = (descriptor_->field_count() + 31) / 32 * 4; - if (descriptor_->field_count() == 0) { - // Zero-size arrays aren't technically allowed, and MSVC in particular - // doesn't like them. We still need to declare these arrays to make - // other code compile. Since this is an uncommon case, we'll just declare - // them with size 1 and waste some space. Oh well. - sizeof_has_bits = 4; - } + const size_t sizeof_has_bits = HasBitsSize(descriptor_); const string has_bits_decl = sizeof_has_bits == 0 ? "" : - "::google::protobuf::uint32 _has_bits_[" + SimpleItoa(sizeof_has_bits / 4) + "];\n"; - + "::google::protobuf::internal::HasBits<" + SimpleItoa(sizeof_has_bits / 4) + + "> _has_bits_;\n"; // To minimize padding, data members are divided into three sections: // (1) members assumed to align to 8 bytes @@ -1326,45 +1402,27 @@ GenerateClassDefinition(io::Printer* printer) { printer->Print(cached_size_decl.c_str()); need_to_emit_cached_size = false; } - } else { - // Without field presence, we need another way to disambiguate the default - // instance, because the default instance's submessage fields (if any) store - // pointers to the default instances of the submessages even when they - // aren't present. Alternatives to this approach might be to (i) use a - // tagged pointer on all message fields, setting a tag bit for "not really - // present, just default instance"; or (ii) comparing |this| against the - // return value from GeneratedMessageFactory::GetPrototype() in all - // has_$field$() calls. However, both of these options are much more - // expensive (in code size and CPU overhead) than just checking a field in - // the message. Long-term, the best solution would be to rearchitect the - // default instance design not to store pointers to submessage default - // instances, and have reflection get those some other way; but that change - // would have too much impact on proto2. - printer->Print( - "bool _is_default_instance_;\n"); } // Field members: // List fields which doesn't belong to any oneof - vector fields; hash_map fieldname_to_chunk; for (int i = 0; i < descriptor_->field_count(); i++) { if (!descriptor_->field(i)->containing_oneof()) { const FieldDescriptor* field = descriptor_->field(i); - fields.push_back(field); fieldname_to_chunk[FieldName(field)] = i / 8; } } - OptimizePadding(&fields); + // Emit some private and static members runs_of_fields_ = vector< vector >(1); - for (int i = 0; i < fields.size(); ++i) { - const FieldDescriptor* field = fields[i]; + for (int i = 0; i < optimized_order_.size(); ++i) { + const FieldDescriptor* field = optimized_order_[i]; const FieldGenerator& generator = field_generators_.get(field); generator.GenerateStaticMembers(printer); generator.GeneratePrivateMembers(printer); - if (CanClearByZeroing(field)) { + if (CanInitializeByZeroing(field)) { const string& fieldname = FieldName(field); if (!runs_of_fields_.back().empty() && (fieldname_to_chunk[runs_of_fields_.back().back()] != @@ -1424,15 +1482,15 @@ GenerateClassDefinition(io::Printer* printer) { // Declare AddDescriptors(), BuildDescriptors(), and ShutdownFile() as // friends so that they can access private static variables like // default_instance_ and reflection_. - PrintHandlingOptionalStaticInitializers( - descriptor_->file(), options_, printer, - // With static initializers. - "friend void $dllexport_decl$ $adddescriptorsname$();\n", - // Without. - "friend void $dllexport_decl$ $adddescriptorsname$_impl();\n", - // Vars. - "dllexport_decl", options_.dllexport_decl, "adddescriptorsname", - GlobalAddDescriptorsName(descriptor_->file()->name())); + printer->Print("friend void $dllexport_decl$ $initdefaultsname$_impl();\n", + // Vars. + "dllexport_decl", options_.dllexport_decl, "initdefaultsname", + GlobalInitDefaultsName(descriptor_->file()->name())); + printer->Print("friend void $dllexport_decl$ $adddescriptorsname$_impl();\n", + // Vars. + "dllexport_decl", options_.dllexport_decl, + "adddescriptorsname", + GlobalAddDescriptorsName(descriptor_->file()->name())); printer->Print( "friend void $assigndescriptorsname$();\n" @@ -1443,12 +1501,12 @@ GenerateClassDefinition(io::Printer* printer) { "shutdownfilename", GlobalShutdownFileName(descriptor_->file()->name())); printer->Print( - "void InitAsDefaultInstance();\n" - "static $classname$* default_instance_;\n", - "classname", classname_); + "void InitAsDefaultInstance();\n" + "static ::google::protobuf::internal::ExplicitlyConstructed<$classname$> default_instance_;\n", + "classname", classname_); printer->Outdent(); - printer->Print(vars, "};"); + printer->Print("};"); GOOGLE_DCHECK(!need_to_emit_cached_size); } @@ -1578,18 +1636,18 @@ GenerateDescriptorInitializer(io::Printer* printer, int index) { "::NewGeneratedMessageReflection"; // Construct the reflection object. printer->Print(vars, - "$classname$_reflection_ =\n" - " $fn$(\n" - " $classname$_descriptor_,\n" - " $classname$::default_instance_,\n" - " $classname$_offsets_,\n"); + "$classname$_reflection_ =\n" + " $fn$(\n" + " $classname$_descriptor_,\n" + " $classname$::internal_default_instance(),\n" + " $classname$_offsets_,\n"); if (!HasFieldPresence(descriptor_->file())) { // If we don't have field presence, then _has_bits_ does not exist. printer->Print(vars, " -1,\n"); } else { printer->Print(vars, - " GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET($classname$, _has_bits_[0]),\n"); + " GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET($classname$, _has_bits_),\n"); } // Unknown field offset: either points to the unknown field set if embedded @@ -1637,22 +1695,12 @@ GenerateDescriptorInitializer(io::Printer* printer, int index) { // not (because e.g. we don't have an unknown field set). if (UseUnknownFieldSet(descriptor_->file(), options_)) { printer->Print(vars, - " GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(" - "$classname$, _internal_metadata_),\n"); + " GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(" + "$classname$, _internal_metadata_));\n"); } else { printer->Print(vars, - " GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(" - "$classname$, _arena_),\n"); - } - - // is_default_instance_ offset. - if (HasFieldPresence(descriptor_->file())) { - printer->Print(vars, - " -1);\n"); - } else { - printer->Print(vars, - " GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(" - "$classname$, _is_default_instance_));\n"); + " GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(" + "$classname$, _arena_));\n"); } // Handle nested types. @@ -1670,11 +1718,11 @@ GenerateTypeRegistrations(io::Printer* printer) { // Register this message type with the message factory. if (!IsMapEntryMessage(descriptor_)) { printer->Print( - "::google::protobuf::MessageFactory::InternalRegisterGeneratedMessage(\n" - " $classname$_descriptor_, &$classname$::default_instance());\n", - "classname", classname_); - } - else { + "::google::protobuf::MessageFactory::InternalRegisterGeneratedMessage(\n" + " $classname$_descriptor_, " + "$classname$::internal_default_instance());\n", + "classname", classname_); + } else { map vars; CollectMapInfo(descriptor_, &vars); vars["classname"] = classname_; @@ -1708,6 +1756,12 @@ GenerateTypeRegistrations(io::Printer* printer) { void MessageGenerator:: GenerateDefaultInstanceAllocator(io::Printer* printer) { + // Force initialization of primitive values we depend on. + printer->Print( + StrCat( + uses_string_ ? "::google::protobuf::internal::GetEmptyString();\n" : "") + .c_str()); + // Construct the default instances of all fields, as they will be used // when creating the default instance of the entire message. for (int i = 0; i < descriptor_->field_count(); i++) { @@ -1720,9 +1774,8 @@ GenerateDefaultInstanceAllocator(io::Printer* printer) { // Construct the default instance. We can't call InitAsDefaultInstance() yet // because we need to make sure all default instances that this one might // depend on are constructed first. - printer->Print( - "$classname$::default_instance_ = new $classname$();\n", - "classname", classname_); + printer->Print("$classname$::default_instance_.DefaultConstruct();\n", + "classname", classname_); if ((descriptor_->oneof_decl_count() > 0) && HasDescriptorMethods(descriptor_->file(), options_)) { @@ -1741,8 +1794,9 @@ GenerateDefaultInstanceAllocator(io::Printer* printer) { void MessageGenerator:: GenerateDefaultInstanceInitializer(io::Printer* printer) { printer->Print( - "$classname$::default_instance_->InitAsDefaultInstance();\n", - "classname", classname_); + "$classname$::default_instance_.get_mutable()->InitAsDefaultInstance();" + "\n", + "classname", classname_); // Register extensions. for (int i = 0; i < descriptor_->extension_count(); i++) { @@ -1761,10 +1815,6 @@ GenerateDefaultInstanceInitializer(io::Printer* printer) { void MessageGenerator:: GenerateShutdownCode(io::Printer* printer) { - printer->Print( - "delete $classname$::default_instance_;\n", - "classname", classname_); - if (HasDescriptorMethods(descriptor_->file(), options_)) { if (descriptor_->oneof_decl_count() > 0) { printer->Print( @@ -1894,6 +1944,12 @@ GenerateClassMethods(io::Printer* printer) { GenerateIsInitialized(printer); printer->Print("\n"); + } else { + printer->Print( + "void $classname$::UnsafeMergeFrom(const $classname$& from) {\n" + " MergeFrom(from);\n" + "}\n", + "classname", classname_); } GenerateSwap(printer); @@ -1966,15 +2022,15 @@ GenerateSharedConstructorCode(io::Printer* printer) { "classname", classname_); printer->Indent(); - if (!HasFieldPresence(descriptor_->file())) { - printer->Print( - " _is_default_instance_ = false;\n"); + bool need_to_clear_cached_size = true; + // We reproduce the logic used for laying out _cached_sized_ in the class + // definition, as to initialize it in-order. + if (HasFieldPresence(descriptor_->file()) && + (HasBitsSize(descriptor_) % 8) != 0) { + printer->Print("_cached_size_ = 0;\n"); + need_to_clear_cached_size = false; } - printer->Print(StrCat( - uses_string_ ? "::google::protobuf::internal::GetEmptyString();\n" : "", - "_cached_size_ = 0;\n").c_str()); - if (PreserveUnknownFields(descriptor_) && !UseUnknownFieldSet(descriptor_->file(), options_)) { printer->Print( @@ -1982,16 +2038,52 @@ GenerateSharedConstructorCode(io::Printer* printer) { " &::google::protobuf::internal::GetEmptyStringAlreadyInited());\n"); } - for (int i = 0; i < descriptor_->field_count(); i++) { - if (!descriptor_->field(i)->containing_oneof()) { - field_generators_.get(descriptor_->field(i)) - .GenerateConstructorCode(printer); + const FieldDescriptor* last_start = NULL; + // RunMap maps from fields that start each run to the number of fields in that + // run. This is optimized for the common case that there are very few runs in + // a message and that most of the eligible fields appear together. + typedef hash_map RunMap; + RunMap runs; + + for (int i = 0; i < optimized_order_.size(); ++i) { + const FieldDescriptor* field = optimized_order_[i]; + // TODO(ckennelly): Scalar messages (raw pointers) can be initialized by + // zero as well. + if (CanInitializeByZeroing(field)) { + if (last_start == NULL) { + last_start = field; + } + + runs[last_start]++; + } else { + last_start = NULL; } } - if (HasFieldPresence(descriptor_->file())) { - printer->Print( - "::memset(_has_bits_, 0, sizeof(_has_bits_));\n"); + for (int i = 0; i < optimized_order_.size(); ++i) { + const FieldDescriptor* field = optimized_order_[i]; + RunMap::const_iterator it = runs.find(field); + + // We only apply the memset technique to runs of more than one field, as + // assignment is better than memset for generated code clarity. + if (it != runs.end() && it->second > 1) { + // Use a memset, then skip run_length fields. + const size_t run_length = it->second; + const string first_field_name = FieldName(field); + const string last_field_name = + FieldName(optimized_order_[i + run_length - 1]); + + printer->Print( + "::memset(&$first$_, 0, reinterpret_cast(&$last$_) -\n" + " reinterpret_cast(&$first$_) + sizeof($last$_));\n", + "first", first_field_name, + "last", last_field_name); + + i += run_length - 1; + // ++i at the top of the loop. + } else { + field_generators_.get(field).GenerateConstructorCode(printer); + } } for (int i = 0; i < descriptor_->oneof_decl_count(); i++) { @@ -2000,6 +2092,10 @@ GenerateSharedConstructorCode(io::Printer* printer) { "oneof_name", descriptor_->oneof_decl(i)->name()); } + if (need_to_clear_cached_size) { + printer->Print("_cached_size_ = 0;\n"); + } + printer->Outdent(); printer->Print("}\n\n"); } @@ -2013,7 +2109,8 @@ GenerateSharedDestructorCode(io::Printer* printer) { if (SupportsArenas(descriptor_)) { // Do nothing when the message is allocated in an arena. printer->Print( - "if (GetArenaNoVirtual() != NULL) {\n" + "::google::protobuf::Arena* arena = GetArenaNoVirtual();\n" + "if (arena != NULL) {\n" " return;\n" "}\n" "\n"); @@ -2026,7 +2123,7 @@ GenerateSharedDestructorCode(io::Printer* printer) { printer->Print( "_unknown_fields_.Destroy(\n" " &::google::protobuf::internal::GetEmptyStringAlreadyInited(),\n" - " GetArenaNoVirtual());\n"); + " arena);\n"); } else { printer->Print( "_unknown_fields_.DestroyNoArena(\n" @@ -2035,11 +2132,10 @@ GenerateSharedDestructorCode(io::Printer* printer) { } // Write the destructors for each field except oneof members. - for (int i = 0; i < descriptor_->field_count(); i++) { - if (!descriptor_->field(i)->containing_oneof()) { - field_generators_.get(descriptor_->field(i)) - .GenerateDestructorCode(printer); - } + // optimized_order_ does not contain oneof fields. + for (int i = 0; i < optimized_order_.size(); i++) { + const FieldDescriptor* field = optimized_order_[i]; + field_generators_.get(field).GenerateDestructorCode(printer); } // Generate code to destruct oneofs. Clearing should do the work. @@ -2051,13 +2147,6 @@ GenerateSharedDestructorCode(io::Printer* printer) { "oneof_name", descriptor_->oneof_decl(i)->name()); } - PrintHandlingOptionalStaticInitializers( - descriptor_->file(), options_, printer, - // With static initializers. - "if (this != default_instance_) {\n", - // Without. - "if (this != &default_instance()) {\n"); - // We need to delete all embedded messages. // TODO(kenton): If we make unset messages point at default instances // instead of NULL, then it would make sense to move this code into @@ -2069,16 +2158,13 @@ GenerateSharedDestructorCode(io::Printer* printer) { field->cpp_type() == FieldDescriptor::CPPTYPE_MESSAGE) { // Skip oneof members if (!field->containing_oneof()) { - printer->Print( - " delete $name$_;\n", - "name", FieldName(field)); + printer->Print("delete $name$_;\n", "name", FieldName(field)); } } } printer->Outdent(); printer->Print( - " }\n" "}\n" "\n"); } @@ -2151,16 +2237,18 @@ GenerateStructors(io::Printer* printer) { } // Initialize member variables with arena constructor. - for (int i = 0; i < descriptor_->field_count(); i++) { - bool has_arena_constructor = descriptor_->field(i)->is_repeated(); + for (int i = 0; i < optimized_order_.size(); i++) { + const FieldDescriptor* field = optimized_order_[i]; + + bool has_arena_constructor = field->is_repeated(); if (has_arena_constructor) { initializer_with_arena += string(",\n ") + - FieldName(descriptor_->field(i)) + string("_(arena)"); + FieldName(field) + string("_(arena)"); } } if (IsAnyMessage(descriptor_)) { - initializer_with_arena += ",\n _any_metadata_(&type_url, &value_)"; + initializer_with_arena += ",\n _any_metadata_(&type_url_, &value_)"; } string initializer_null; @@ -2173,27 +2261,31 @@ GenerateStructors(io::Printer* printer) { printer->Print( "$classname$::$classname$()\n" " : $superclass$()$initializer$ {\n" + " if (this != internal_default_instance()) $initdefaultsname$();\n" " SharedCtor();\n" " // @@protoc_insertion_point(constructor:$full_name$)\n" "}\n", - "classname", classname_, - "superclass", superclass, - "full_name", descriptor_->full_name(), - "initializer", initializer_null); + "classname", classname_, "superclass", superclass, "full_name", + descriptor_->full_name(), "initializer", initializer_null, + "initdefaultsname", GlobalInitDefaultsName(descriptor_->file()->name())); if (SupportsArenas(descriptor_)) { printer->Print( - "\n" "$classname$::$classname$(::google::protobuf::Arena* arena)\n" " : $initializer$ {\n" + // When arenas are used it's safe to assume we have finished + // static init time (protos with arenas are unsafe during static init) + "#ifdef GOOGLE_PROTOBUF_NO_STATIC_INITIALIZER\n" + " $initdefaultsname$();\n" + "#endif // GOOGLE_PROTOBUF_NO_STATIC_INITIALIZER\n" " SharedCtor();\n" " RegisterArenaDtor(arena);\n" " // @@protoc_insertion_point(arena_constructor:$full_name$)\n" "}\n", - "initializer", initializer_with_arena, - "classname", classname_, - "superclass", superclass, - "full_name", descriptor_->full_name()); + "initializer", initializer_with_arena, "classname", classname_, + "superclass", superclass, "full_name", descriptor_->full_name(), + "initdefaultsname", + GlobalInitDefaultsName(descriptor_->file()->name())); } printer->Print( @@ -2201,11 +2293,6 @@ GenerateStructors(io::Printer* printer) { "void $classname$::InitAsDefaultInstance() {\n", "classname", classname_); - if (!HasFieldPresence(descriptor_->file())) { - printer->Print( - " _is_default_instance_ = true;\n"); - } - // The default instance needs all of its embedded message pointers // cross-linked to other default instances. We can't do this initialization // in the constructor because some other default instances may not have been @@ -2224,11 +2311,7 @@ GenerateStructors(io::Printer* printer) { name = classname_ + "_default_oneof_instance_->"; } name += FieldName(field); - PrintHandlingOptionalStaticInitializers( - descriptor_->file(), options_, printer, - // With static initializers. - " $name$_ = const_cast< $type$*>(&$type$::default_instance());\n", - // Without. + printer->Print( " $name$_ = const_cast< $type$*>(\n" " $type$::internal_default_instance());\n", // Vars. @@ -2262,7 +2345,7 @@ GenerateStructors(io::Printer* printer) { printer->Print(" {\n"); printer->Print( " SharedCtor();\n" - " MergeFrom(from);\n" + " UnsafeMergeFrom(from);\n" " // @@protoc_insertion_point(copy_constructor:$full_name$)\n" "}\n" "\n", @@ -2304,37 +2387,29 @@ GenerateStructors(io::Printer* printer) { if (HasDescriptorMethods(descriptor_->file(), options_) && !descriptor_->options().no_standard_descriptor_accessor()) { printer->Print( - "const ::google::protobuf::Descriptor* $classname$::descriptor() {\n" - " protobuf_AssignDescriptorsOnce();\n" - " return $classname$_descriptor_;\n" - "}\n" - "\n", - "classname", classname_, - "adddescriptorsname", - GlobalAddDescriptorsName(descriptor_->file()->name())); + "const ::google::protobuf::Descriptor* $classname$::descriptor() {\n" + " protobuf_AssignDescriptorsOnce();\n" + " return $classname$_descriptor_;\n" + "}\n" + "\n", + "classname", classname_, "initdefaultsname", + GlobalInitDefaultsName(descriptor_->file()->name())); } printer->Print( - "const $classname$& $classname$::default_instance() {\n", - "classname", classname_); - - PrintHandlingOptionalStaticInitializers( - descriptor_->file(), options_, printer, - // With static initializers. - " if (default_instance_ == NULL) $adddescriptorsname$();\n", - // Without. - " $adddescriptorsname$();\n", - // Vars. - "adddescriptorsname", - GlobalAddDescriptorsName(descriptor_->file()->name())); + "const $classname$& $classname$::default_instance() {\n" + " $initdefaultsname$();\n" + " return *internal_default_instance();\n" + "}\n", + "classname", classname_, "initdefaultsname", + GlobalInitDefaultsName(descriptor_->file()->name())); printer->Print( - " return *default_instance_;\n" - "}\n" - "\n" - "$classname$* $classname$::default_instance_ = NULL;\n" - "\n", - "classname", classname_); + "\n" + "::google::protobuf::internal::ExplicitlyConstructed<$classname$> " + "$classname$::default_instance_;\n" + "\n", + "classname", classname_); if (SupportsArenas(descriptor_)) { printer->Print( @@ -2463,7 +2538,7 @@ GenerateClear(io::Printer* printer) { int count = popcnt(mask); GOOGLE_DCHECK_GE(count, 1); if (count == 1 || - (count <= 4 && count == memset_field_count_for_chunk[i / 8])) { + count == memset_field_count_for_chunk[i / 8]) { // No "if" here because the chunk is trivial. } else { if (HasFieldPresence(descriptor_->file())) { @@ -2540,8 +2615,7 @@ GenerateClear(io::Printer* printer) { if (HasFieldPresence(descriptor_->file())) { // Step 5: Everything else. - printer->Print( - "::memset(_has_bits_, 0, sizeof(_has_bits_));\n"); + printer->Print("_has_bits_.Clear();\n"); } if (PreserveUnknownFields(descriptor_)) { @@ -2584,7 +2658,7 @@ GenerateOneofClear(io::Printer* printer) { "$full_name$)\n"); printer->Indent(); printer->Print(oneof_vars, - "switch($oneofname$_case()) {\n"); + "switch ($oneofname$_case()) {\n"); printer->Indent(); for (int j = 0; j < descriptor_->oneof_decl(i)->field_count(); j++) { const FieldDescriptor* field = descriptor_->oneof_decl(i)->field(j); @@ -2639,7 +2713,7 @@ GenerateSwap(io::Printer* printer) { " InternalSwap(other);\n" " } else {\n" " $classname$ temp;\n" - " temp.MergeFrom(*this);\n" + " temp.UnsafeMergeFrom(*this);\n" " CopyFrom(*other);\n" " other->CopyFrom(temp);\n" " }\n" @@ -2715,9 +2789,7 @@ GenerateMergeFrom(io::Printer* printer) { "void $classname$::MergeFrom(const ::google::protobuf::Message& from) {\n" "// @@protoc_insertion_point(generalized_merge_from_start:" "$full_name$)\n" - " if (GOOGLE_PREDICT_FALSE(&from == this)) {\n" - " ::google::protobuf::internal::MergeFromFail(__FILE__, __LINE__);\n" - " }\n", + " if (GOOGLE_PREDICT_FALSE(&from == this)) MergeFromFail(__LINE__);\n", "classname", classname_, "full_name", descriptor_->full_name()); printer->Indent(); @@ -2726,7 +2798,7 @@ GenerateMergeFrom(io::Printer* printer) { // system, as the GOOGLE_CHECK above ensured that we have the same descriptor // for each message. printer->Print( - "const $classname$* source = \n" + "const $classname$* source =\n" " ::google::protobuf::internal::DynamicCastToGenerated(\n" " &from);\n" "if (source == NULL) {\n" @@ -2736,7 +2808,7 @@ GenerateMergeFrom(io::Printer* printer) { "} else {\n" "// @@protoc_insertion_point(generalized_merge_from_cast_success:" "$full_name$)\n" - " MergeFrom(*source);\n" + " UnsafeMergeFrom(*source);\n" "}\n", "classname", classname_, "full_name", descriptor_->full_name()); @@ -2758,9 +2830,15 @@ GenerateMergeFrom(io::Printer* printer) { "void $classname$::MergeFrom(const $classname$& from) {\n" "// @@protoc_insertion_point(class_specific_merge_from_start:" "$full_name$)\n" - " if (GOOGLE_PREDICT_FALSE(&from == this)) {\n" - " ::google::protobuf::internal::MergeFromFail(__FILE__, __LINE__);\n" - " }\n", + " if (GOOGLE_PREDICT_TRUE(&from != this)) {\n" + " UnsafeMergeFrom(from);\n" + " } else {\n" + " MergeFromFail(__LINE__);\n" + " }\n" + "}\n" + "\n" + "void $classname$::UnsafeMergeFrom(const $classname$& from) {\n" + " GOOGLE_DCHECK(&from != this);\n", "classname", classname_, "full_name", descriptor_->full_name()); printer->Indent(); @@ -2770,7 +2848,7 @@ GenerateMergeFrom(io::Printer* printer) { const FieldDescriptor* field = descriptor_->field(i); if (field->is_repeated()) { - field_generators_.get(field).GenerateMergingCode(printer); + field_generators_.get(field).GenerateUnsafeMergingCode(printer); } } @@ -2865,7 +2943,8 @@ GenerateMergeFrom(io::Printer* printer) { if (UseUnknownFieldSet(descriptor_->file(), options_)) { printer->Print( "if (from._internal_metadata_.have_unknown_fields()) {\n" - " mutable_unknown_fields()->MergeFrom(from.unknown_fields());\n" + " ::google::protobuf::UnknownFieldSet::MergeToInternalMetdata(\n" + " from.unknown_fields(), &_internal_metadata_);\n" "}\n"); } else { printer->Print( @@ -2911,7 +2990,7 @@ GenerateCopyFrom(io::Printer* printer) { printer->Print( "if (&from == this) return;\n" "Clear();\n" - "MergeFrom(from);\n"); + "UnsafeMergeFrom(from);\n"); printer->Outdent(); printer->Print("}\n"); @@ -2926,13 +3005,9 @@ GenerateMergeFromCodedStream(io::Printer* printer) { " ::google::protobuf::io::CodedInputStream* input) {\n", "classname", classname_); - PrintHandlingOptionalStaticInitializers( - descriptor_->file(), options_, printer, - // With static initializers. - " return _extensions_.ParseMessageSet(input, default_instance_,\n" - " mutable_unknown_fields());\n", - // Without. - " return _extensions_.ParseMessageSet(input, &default_instance(),\n" + printer->Print( + " return _extensions_.ParseMessageSet(input, " + "internal_default_instance(),\n" " mutable_unknown_fields());\n", // Vars. "classname", classname_); @@ -2971,8 +3046,8 @@ GenerateMergeFromCodedStream(io::Printer* printer) { printer->Print("for (;;) {\n"); printer->Indent(); - google::protobuf::scoped_array ordered_fields( - SortFieldsByNumber(descriptor_)); + std::vector ordered_fields = + SortFieldsByNumber(descriptor_); uint32 maxtag = descriptor_->field_count() == 0 ? 0 : WireFormat::MakeTag(ordered_fields[descriptor_->field_count() - 1]); const int kCutoff0 = 127; // fits in 1-byte varint @@ -3000,7 +3075,7 @@ GenerateMergeFromCodedStream(io::Printer* printer) { // Find repeated messages and groups now, to simplify what follows. hash_set fields_with_parse_loop; - for (int i = 0; i < descriptor_->field_count(); i++) { + for (int i = 0; i < ordered_fields.size(); i++) { const FieldDescriptor* field = ordered_fields[i]; if (field->is_repeated() && (field->type() == FieldDescriptor::TYPE_MESSAGE || @@ -3012,7 +3087,13 @@ GenerateMergeFromCodedStream(io::Printer* printer) { // need_label is true if we generated "goto parse_$name$" while handling the // previous field. bool need_label = false; - for (int i = 0; i < descriptor_->field_count(); i++) { + // Pay attention to whether we are in a run of fields from the same oneof. + // Motivation: it would be unusual to parse multiple values for a single + // oneof, since only the last would be used. + const FieldDescriptor* last_of_current_oneof = NULL; + // The following is valid iff last_of_current_oneof is non-NULL. + int index_of_last_of_current_oneof = -1; + for (int i = 0; i < ordered_fields.size(); i++) { const FieldDescriptor* field = ordered_fields[i]; const bool loops = fields_with_parse_loop.count(i) > 0; const bool next_field_loops = fields_with_parse_loop.count(i + 1) > 0; @@ -3111,21 +3192,53 @@ GenerateMergeFromCodedStream(io::Printer* printer) { "input->UnsafeDecrementRecursionDepth();\n"); } - // If there are more fields, expect the next one. + // If there are more fields, expect the next one, unless we just parsed + // a oneof and the next field would be from the same oneof. (There's no + // reason to expect something that makes what we just read irrelevant, + // so guess something after the current string of fields from this oneof.) need_label = false; if (!emitted_goto_next_tag) { - if (i + 1 == descriptor_->field_count()) { + // delta is the distance in ordered_fields[] from the current field to + // the field we'll guess is next. + int delta = last_of_current_oneof == NULL + ? 1 + : std::max(index_of_last_of_current_oneof - i, 1); + if (i == index_of_last_of_current_oneof) { + printer->Outdent(); + printer->Print( + " after_$last$:\n", + "last", FieldName(last_of_current_oneof)); + printer->Indent(); + last_of_current_oneof = NULL; + } else if (last_of_current_oneof == NULL) { + delta = 1; + // Check for the unlikely case that delta > 1 is better. + if (field->containing_oneof() != NULL) { + while (i + delta < ordered_fields.size() && + ordered_fields[i + delta]->containing_oneof() == + field->containing_oneof()) { + index_of_last_of_current_oneof = i + delta; + last_of_current_oneof = ordered_fields[i + delta]; + ++delta; + } + } + } + if (delta > 1) { + printer->Print( + "goto after_$last$;\n", + "last", FieldName(last_of_current_oneof)); + } else if (i + delta == descriptor_->field_count()) { // Expect EOF. // TODO(kenton): Expect group end-tag? printer->Print( "if (input->ExpectAtEnd()) goto success;\n"); } else { - const FieldDescriptor* next_field = ordered_fields[i + 1]; + const FieldDescriptor* next_field = ordered_fields[i + delta]; printer->Print( "if (input->ExpectTag($next_tag$)) goto parse_$next_name$;\n", "next_tag", SimpleItoa(WireFormat::MakeTag(next_field)), "next_name", next_field->name()); - need_label = true; + need_label = delta == 1; } } @@ -3179,31 +3292,21 @@ GenerateMergeFromCodedStream(io::Printer* printer) { printer->Print(") {\n"); if (PreserveUnknownFields(descriptor_)) { if (UseUnknownFieldSet(descriptor_->file(), options_)) { - PrintHandlingOptionalStaticInitializers( - descriptor_->file(), options_, printer, - // With static initializers. - " DO_(_extensions_.ParseField(tag, input, default_instance_,\n" - " mutable_unknown_fields()));\n", - // Without. - " DO_(_extensions_.ParseField(tag, input, &default_instance(),\n" + printer->Print( + " DO_(_extensions_.ParseField(tag, input, " + "internal_default_instance(),\n" " mutable_unknown_fields()));\n"); } else { - PrintHandlingOptionalStaticInitializers( - descriptor_->file(), options_, printer, - // With static initializers. - " DO_(_extensions_.ParseField(tag, input, default_instance_,\n" - " &unknown_fields_stream));\n", - // Without. - " DO_(_extensions_.ParseField(tag, input, &default_instance(),\n" + printer->Print( + " DO_(_extensions_.ParseField(tag, input, " + "internal_default_instance(),\n" " &unknown_fields_stream));\n"); } } else { - PrintHandlingOptionalStaticInitializers( - descriptor_->file(), options_, printer, + printer->Print( // With static initializers. - " DO_(_extensions_.ParseField(tag, input, default_instance_);\n", - // Without. - " DO_(_extensions_.ParseField(tag, input, &default_instance());\n"); + " DO_(_extensions_.ParseField(tag, input, " + "internal_default_instance());\n"); } printer->Print( " continue;\n" @@ -3248,6 +3351,43 @@ GenerateMergeFromCodedStream(io::Printer* printer) { "}\n", "full_name", descriptor_->full_name()); } +void MessageGenerator::GenerateSerializeOneofFields( + io::Printer* printer, const vector& fields, + bool to_array) { + GOOGLE_CHECK(!fields.empty()); + if (fields.size() == 1) { + GenerateSerializeOneField(printer, fields[0], to_array); + return; + } + // We have multiple mutually exclusive choices. Emit a switch statement. + const OneofDescriptor* oneof = fields[0]->containing_oneof(); + printer->Print( + "switch ($oneofname$_case()) {\n", + "oneofname", oneof->name()); + printer->Indent(); + for (int i = 0; i < fields.size(); i++) { + const FieldDescriptor* field = fields[i]; + printer->Print( + "case k$field_name$:\n", + "field_name", UnderscoresToCamelCase(field->name(), true)); + printer->Indent(); + if (to_array) { + field_generators_.get(field).GenerateSerializeWithCachedSizesToArray( + printer); + } else { + field_generators_.get(field).GenerateSerializeWithCachedSizes(printer); + } + printer->Print( + "break;\n"); + printer->Outdent(); + } + printer->Outdent(); + // Doing nothing is an option. + printer->Print( + " default: ;\n" + "}\n"); +} + void MessageGenerator::GenerateSerializeOneField( io::Printer* printer, const FieldDescriptor* field, bool to_array) { PrintFieldComment(printer, field); @@ -3382,10 +3522,61 @@ GenerateSerializeWithCachedSizesToArray(io::Printer* printer) { void MessageGenerator:: GenerateSerializeWithCachedSizesBody(io::Printer* printer, bool to_array) { - google::protobuf::scoped_array ordered_fields( - SortFieldsByNumber(descriptor_)); + // If there are multiple fields in a row from the same oneof then we + // coalesce them and emit a switch statement. This is more efficient + // because it lets the C++ compiler know this is a "at most one can happen" + // situation. If we emitted "if (has_x()) ...; if (has_y()) ..." the C++ + // compiler's emitted code might check has_y() even when has_x() is true. + class LazySerializerEmitter { + public: + LazySerializerEmitter(MessageGenerator* mg, io::Printer* printer, + bool to_array) + : mg_(mg), + printer_(printer), + to_array_(to_array), + eager_(!HasFieldPresence(mg->descriptor_->file())) {} + + ~LazySerializerEmitter() { Flush(); } + + // If conditions allow, try to accumulate a run of fields from the same + // oneof, and handle them at the next Flush(). + void Emit(const FieldDescriptor* field) { + if (eager_ || MustFlush(field)) { + Flush(); + } + if (field->containing_oneof() == NULL) { + mg_->GenerateSerializeOneField(printer_, field, to_array_); + } else { + v_.push_back(field); + } + } - vector sorted_extensions; + void Flush() { + if (!v_.empty()) { + mg_->GenerateSerializeOneofFields(printer_, v_, to_array_); + v_.clear(); + } + } + + private: + // If we have multiple fields in v_ then they all must be from the same + // oneof. Would adding field to v_ break that invariant? + bool MustFlush(const FieldDescriptor* field) { + return !v_.empty() && + v_[0]->containing_oneof() != field->containing_oneof(); + } + + MessageGenerator* mg_; + io::Printer* printer_; + const bool to_array_; + const bool eager_; + vector v_; + }; + + std::vector ordered_fields = + SortFieldsByNumber(descriptor_); + + std::vector sorted_extensions; for (int i = 0; i < descriptor_->extension_range_count(); ++i) { sorted_extensions.push_back(descriptor_->extension_range(i)); } @@ -3393,22 +3584,26 @@ GenerateSerializeWithCachedSizesBody(io::Printer* printer, bool to_array) { ExtensionRangeSorter()); // Merge the fields and the extension ranges, both sorted by field number. - int i, j; - for (i = 0, j = 0; - i < descriptor_->field_count() || j < sorted_extensions.size(); - ) { - if (i == descriptor_->field_count()) { - GenerateSerializeOneExtensionRange(printer, - sorted_extensions[j++], - to_array); - } else if (j == sorted_extensions.size()) { - GenerateSerializeOneField(printer, ordered_fields[i++], to_array); - } else if (ordered_fields[i]->number() < sorted_extensions[j]->start) { - GenerateSerializeOneField(printer, ordered_fields[i++], to_array); - } else { - GenerateSerializeOneExtensionRange(printer, - sorted_extensions[j++], - to_array); + { + LazySerializerEmitter e(this, printer, to_array); + int i, j; + for (i = 0, j = 0; + i < ordered_fields.size() || j < sorted_extensions.size();) { + if (i == descriptor_->field_count()) { + e.Flush(); + GenerateSerializeOneExtensionRange(printer, + sorted_extensions[j++], + to_array); + } else if (j == sorted_extensions.size()) { + e.Emit(ordered_fields[i++]); + } else if (ordered_fields[i]->number() < sorted_extensions[j]->start) { + e.Emit(ordered_fields[i++]); + } else { + e.Flush(); + GenerateSerializeOneExtensionRange(printer, + sorted_extensions[j++], + to_array); + } } } @@ -3480,9 +3675,9 @@ GenerateByteSize(io::Printer* printer) { if (descriptor_->options().message_set_wire_format()) { // Special-case MessageSet. printer->Print( - "int $classname$::ByteSize() const {\n" + "size_t $classname$::ByteSizeLong() const {\n" "// @@protoc_insertion_point(message_set_byte_size_start:$full_name$)\n" - " int total_size = _extensions_.MessageSetByteSize();\n", + " size_t total_size = _extensions_.MessageSetByteSize();\n", "classname", classname_, "full_name", descriptor_->full_name()); GOOGLE_CHECK(UseUnknownFieldSet(descriptor_->file(), options_)); printer->Print( @@ -3491,8 +3686,9 @@ GenerateByteSize(io::Printer* printer) { " ComputeUnknownMessageSetItemsSize(unknown_fields());\n" "}\n"); printer->Print( + " int cached_size = ::google::protobuf::internal::ToCachedSize(total_size);\n" " GOOGLE_SAFE_CONCURRENT_WRITES_BEGIN();\n" - " _cached_size_ = total_size;\n" + " _cached_size_ = cached_size;\n" " GOOGLE_SAFE_CONCURRENT_WRITES_END();\n" " return total_size;\n" "}\n"); @@ -3503,12 +3699,12 @@ GenerateByteSize(io::Printer* printer) { // Emit a function (rarely used, we hope) that handles the required fields // by checking for each one individually. printer->Print( - "int $classname$::RequiredFieldsByteSizeFallback() const {\n" + "size_t $classname$::RequiredFieldsByteSizeFallback() const {\n" "// @@protoc_insertion_point(required_fields_byte_size_fallback_start:" "$full_name$)\n", "classname", classname_, "full_name", descriptor_->full_name()); printer->Indent(); - printer->Print("int total_size = 0;\n"); + printer->Print("size_t total_size = 0;\n"); for (int i = 0; i < descriptor_->field_count(); i++) { const FieldDescriptor* field = descriptor_->field(i); if (field->is_required()) { @@ -3529,12 +3725,12 @@ GenerateByteSize(io::Printer* printer) { } printer->Print( - "int $classname$::ByteSize() const {\n" + "size_t $classname$::ByteSizeLong() const {\n" "// @@protoc_insertion_point(message_byte_size_start:$full_name$)\n", "classname", classname_, "full_name", descriptor_->full_name()); printer->Indent(); printer->Print( - "int total_size = 0;\n" + "size_t total_size = 0;\n" "\n"); // Handle required fields (if any). We expect all of them to be @@ -3727,8 +3923,9 @@ GenerateByteSize(io::Printer* printer) { // exact same value, it works on all common processors. In a future version // of C++, _cached_size_ should be made into an atomic. printer->Print( + "int cached_size = ::google::protobuf::internal::ToCachedSize(total_size);\n" "GOOGLE_SAFE_CONCURRENT_WRITES_BEGIN();\n" - "_cached_size_ = total_size;\n" + "_cached_size_ = cached_size;\n" "GOOGLE_SAFE_CONCURRENT_WRITES_END();\n" "return total_size;\n"); @@ -3804,7 +4001,9 @@ GenerateIsInitialized(io::Printer* printer) { if (descriptor_->extension_range_count() > 0) { printer->Print( "\n" - "if (!_extensions_.IsInitialized()) return false;\n"); + "if (!_extensions_.IsInitialized()) {\n" + " return false;\n" + "}\n"); } printer->Outdent(); diff --git a/src/google/protobuf/compiler/cpp/cpp_message.h b/src/google/protobuf/compiler/cpp/cpp_message.h index b1e3fe21..3bdc0ed3 100644 --- a/src/google/protobuf/compiler/cpp/cpp_message.h +++ b/src/google/protobuf/compiler/cpp/cpp_message.h @@ -165,6 +165,11 @@ class MessageGenerator { void GenerateSerializeOneField(io::Printer* printer, const FieldDescriptor* field, bool unbounded); + // Generate a switch statement to serialize 2+ fields from the same oneof. + // Or, if fields.size() == 1, just call GenerateSerializeOneField(). + void GenerateSerializeOneofFields( + io::Printer* printer, const vector& fields, + bool to_array); void GenerateSerializeOneExtensionRange( io::Printer* printer, const Descriptor::ExtensionRange* range, bool unbounded); @@ -189,6 +194,11 @@ class MessageGenerator { string classname_; Options options_; FieldGeneratorMap field_generators_; + // optimized_order_ is the order we layout the message's fields in the class. + // This is reused to initialize the fields in-order for cache efficiency. + // + // optimized_order_ excludes oneof fields. + vector optimized_order_; vector< vector > runs_of_fields_; // that might be trivially cleared google::protobuf::scoped_array > nested_generators_; google::protobuf::scoped_array > enum_generators_; diff --git a/src/google/protobuf/compiler/cpp/cpp_message_field.cc b/src/google/protobuf/compiler/cpp/cpp_message_field.cc index d021035d..ca7bae02 100644 --- a/src/google/protobuf/compiler/cpp/cpp_message_field.cc +++ b/src/google/protobuf/compiler/cpp/cpp_message_field.cc @@ -161,8 +161,7 @@ void MessageFieldGenerator::GenerateNonInlineAccessorDefinitions( " if ($name$_ == NULL) {\n" " return NULL;\n" " } else {\n" - " $type$* temp = new $type$;\n" - " temp->MergeFrom(*$name$_);\n" + " $type$* temp = new $type$(*$name$_);\n" " $name$_ = NULL;\n" " return temp;\n" " }\n" @@ -346,23 +345,29 @@ GenerateDependentInlineAccessorDefinitions(io::Printer* printer) const { void MessageFieldGenerator:: GenerateInlineAccessorDefinitions(io::Printer* printer, bool is_inline) const { + if (dependent_field_) { + // for dependent fields we cannot access its internal_default_instance, + // because the type is incomplete. + // TODO(gerbens) deprecate dependent base class. + map variables(variables_); + variables["inline"] = is_inline ? "inline " : ""; + printer->Print(variables, + "$inline$const $type$& $classname$::$name$() const {\n" + " // @@protoc_insertion_point(field_get:$full_name$)\n" + " return $name$_ != NULL ? *$name$_\n" + " : *internal_default_instance()->$name$_;\n" + "}\n"); + return; + } + map variables(variables_); variables["inline"] = is_inline ? "inline " : ""; printer->Print(variables, "$inline$const $type$& $classname$::$name$() const {\n" - " // @@protoc_insertion_point(field_get:$full_name$)\n"); - - PrintHandlingOptionalStaticInitializers( - variables, descriptor_->file(), options_, printer, - // With static initializers. - " return $name$_ != NULL ? *$name$_ : *default_instance_->$name$_;\n", - // Without. - " return $name$_ != NULL ? *$name$_ : *default_instance().$name$_;\n"); - printer->Print(variables, "}\n"); - - if (dependent_field_) { - return; - } + " // @@protoc_insertion_point(field_get:$full_name$)\n" + " return $name$_ != NULL ? *$name$_\n" + " : *$type$::internal_default_instance();\n" + "}\n"); if (SupportsArenas(descriptor_)) { printer->Print(variables, @@ -663,8 +668,8 @@ InternalGenerateInlineAccessorDefinitions(const map& variables, " if ($this_message$GetArenaNoVirtual() != NULL) {\n" // N.B.: safe to use the underlying field pointer here because we are sure // that it is non-NULL (because has_$name$() returned true). - " $dependent_typename$* temp = new $dependent_typename$;\n" - " temp->MergeFrom(*$field_member$);\n" + " $dependent_typename$* temp = " + "new $dependent_typename$(*$field_member$);\n" " $field_member$ = NULL;\n" " return temp;\n" " } else {\n" @@ -1041,12 +1046,18 @@ GenerateSerializeWithCachedSizesToArray(io::Printer* printer) const { void RepeatedMessageFieldGenerator:: GenerateByteSize(io::Printer* printer) const { printer->Print(variables_, - "total_size += $tag_size$ * this->$name$_size();\n" - "for (int i = 0; i < this->$name$_size(); i++) {\n" + "{\n" + " unsigned int count = this->$name$_size();\n"); + printer->Indent(); + printer->Print(variables_, + "total_size += $tag_size$UL * count;\n" + "for (unsigned int i = 0; i < count; i++) {\n" " total_size +=\n" " ::google::protobuf::internal::WireFormatLite::$declared_type$SizeNoVirtual(\n" " this->$name$(i));\n" "}\n"); + printer->Outdent(); + printer->Print("}\n"); } } // namespace cpp diff --git a/src/google/protobuf/compiler/cpp/cpp_primitive_field.cc b/src/google/protobuf/compiler/cpp/cpp_primitive_field.cc index 650f0381..54b3d24a 100644 --- a/src/google/protobuf/compiler/cpp/cpp_primitive_field.cc +++ b/src/google/protobuf/compiler/cpp/cpp_primitive_field.cc @@ -123,13 +123,13 @@ GenerateAccessorDeclarations(io::Printer* printer) const { void PrimitiveFieldGenerator:: GenerateInlineAccessorDefinitions(io::Printer* printer, bool is_inline) const { map variables(variables_); - variables["inline"] = is_inline ? "inline" : ""; + variables["inline"] = is_inline ? "inline " : ""; printer->Print(variables, - "$inline$ $type$ $classname$::$name$() const {\n" + "$inline$$type$ $classname$::$name$() const {\n" " // @@protoc_insertion_point(field_get:$full_name$)\n" " return $name$_;\n" "}\n" - "$inline$ void $classname$::set_$name$($type$ value) {\n" + "$inline$void $classname$::set_$name$($type$ value) {\n" " $set_hasbit$\n" " $name$_ = value;\n" " // @@protoc_insertion_point(field_set:$full_name$)\n" @@ -159,10 +159,10 @@ GenerateConstructorCode(io::Printer* printer) const { void PrimitiveFieldGenerator:: GenerateMergeFromCodedStream(io::Printer* printer) const { printer->Print(variables_, + "$set_hasbit$\n" "DO_((::google::protobuf::internal::WireFormatLite::ReadPrimitive<\n" " $type$, $wire_format_field_type$>(\n" - " input, &$name$_)));\n" - "$set_hasbit$\n"); + " input, &$name$_)));\n"); } void PrimitiveFieldGenerator:: @@ -207,16 +207,16 @@ PrimitiveOneofFieldGenerator::~PrimitiveOneofFieldGenerator() {} void PrimitiveOneofFieldGenerator:: GenerateInlineAccessorDefinitions(io::Printer* printer, bool is_inline) const { map variables(variables_); - variables["inline"] = is_inline ? "inline" : ""; + variables["inline"] = is_inline ? "inline " : ""; printer->Print(variables, - "$inline$ $type$ $classname$::$name$() const {\n" + "$inline$$type$ $classname$::$name$() const {\n" " // @@protoc_insertion_point(field_get:$full_name$)\n" " if (has_$name$()) {\n" " return $oneof_prefix$$name$_;\n" " }\n" " return $default$;\n" "}\n" - "$inline$ void $classname$::set_$name$($type$ value) {\n" + "$inline$void $classname$::set_$name$($type$ value) {\n" " if (!has_$name$()) {\n" " clear_$oneof_name$();\n" " set_has_$name$();\n" @@ -298,27 +298,27 @@ GenerateAccessorDeclarations(io::Printer* printer) const { void RepeatedPrimitiveFieldGenerator:: GenerateInlineAccessorDefinitions(io::Printer* printer, bool is_inline) const { map variables(variables_); - variables["inline"] = is_inline ? "inline" : ""; + variables["inline"] = is_inline ? "inline " : ""; printer->Print(variables, - "$inline$ $type$ $classname$::$name$(int index) const {\n" + "$inline$$type$ $classname$::$name$(int index) const {\n" " // @@protoc_insertion_point(field_get:$full_name$)\n" " return $name$_.Get(index);\n" "}\n" - "$inline$ void $classname$::set_$name$(int index, $type$ value) {\n" + "$inline$void $classname$::set_$name$(int index, $type$ value) {\n" " $name$_.Set(index, value);\n" " // @@protoc_insertion_point(field_set:$full_name$)\n" "}\n" - "$inline$ void $classname$::add_$name$($type$ value) {\n" + "$inline$void $classname$::add_$name$($type$ value) {\n" " $name$_.Add(value);\n" " // @@protoc_insertion_point(field_add:$full_name$)\n" "}\n"); printer->Print(variables, - "$inline$ const ::google::protobuf::RepeatedField< $type$ >&\n" + "$inline$const ::google::protobuf::RepeatedField< $type$ >&\n" "$classname$::$name$() const {\n" " // @@protoc_insertion_point(field_list:$full_name$)\n" " return $name$_;\n" "}\n" - "$inline$ ::google::protobuf::RepeatedField< $type$ >*\n" + "$inline$::google::protobuf::RepeatedField< $type$ >*\n" "$classname$::mutable_$name$() {\n" " // @@protoc_insertion_point(field_mutable_list:$full_name$)\n" " return &$name$_;\n" @@ -335,6 +335,11 @@ GenerateMergingCode(io::Printer* printer) const { printer->Print(variables_, "$name$_.MergeFrom(from.$name$_);\n"); } +void RepeatedPrimitiveFieldGenerator:: +GenerateUnsafeMergingCode(io::Printer* printer) const { + printer->Print(variables_, "$name$_.UnsafeMergeFrom(from.$name$_);\n"); +} + void RepeatedPrimitiveFieldGenerator:: GenerateSwappingCode(io::Printer* printer) const { printer->Print(variables_, "$name$_.UnsafeArenaSwap(&other->$name$_);\n"); @@ -420,18 +425,19 @@ void RepeatedPrimitiveFieldGenerator:: GenerateByteSize(io::Printer* printer) const { printer->Print(variables_, "{\n" - " int data_size = 0;\n"); + " size_t data_size = 0;\n" + " unsigned int count = this->$name$_size();\n"); printer->Indent(); int fixed_size = FixedSize(descriptor_->type()); if (fixed_size == -1) { printer->Print(variables_, - "for (int i = 0; i < this->$name$_size(); i++) {\n" + "for (unsigned int i = 0; i < count; i++) {\n" " data_size += ::google::protobuf::internal::WireFormatLite::\n" " $declared_type$Size(this->$name$(i));\n" "}\n"); } else { printer->Print(variables_, - "data_size = $fixed_size$ * this->$name$_size();\n"); + "data_size = $fixed_size$UL * count;\n"); } if (descriptor_->is_packed()) { @@ -440,13 +446,16 @@ GenerateByteSize(io::Printer* printer) const { " total_size += $tag_size$ +\n" " ::google::protobuf::internal::WireFormatLite::Int32Size(data_size);\n" "}\n" + "int cached_size = ::google::protobuf::internal::ToCachedSize(data_size);\n" "GOOGLE_SAFE_CONCURRENT_WRITES_BEGIN();\n" - "_$name$_cached_byte_size_ = data_size;\n" + "_$name$_cached_byte_size_ = cached_size;\n" "GOOGLE_SAFE_CONCURRENT_WRITES_END();\n" "total_size += data_size;\n"); } else { printer->Print(variables_, - "total_size += $tag_size$ * this->$name$_size() + data_size;\n"); + "total_size += $tag_size$ *\n" + " ::google::protobuf::internal::FromIntSize(this->$name$_size());\n" + "total_size += data_size;\n"); } printer->Outdent(); printer->Print("}\n"); diff --git a/src/google/protobuf/compiler/cpp/cpp_primitive_field.h b/src/google/protobuf/compiler/cpp/cpp_primitive_field.h index 655ebde4..23cc697e 100644 --- a/src/google/protobuf/compiler/cpp/cpp_primitive_field.h +++ b/src/google/protobuf/compiler/cpp/cpp_primitive_field.h @@ -103,6 +103,7 @@ class RepeatedPrimitiveFieldGenerator : public FieldGenerator { bool is_inline) const; void GenerateClearingCode(io::Printer* printer) const; void GenerateMergingCode(io::Printer* printer) const; + virtual void GenerateUnsafeMergingCode(io::Printer* printer) const; void GenerateSwappingCode(io::Printer* printer) const; void GenerateConstructorCode(io::Printer* printer) const; void GenerateMergeFromCodedStream(io::Printer* printer) const; diff --git a/src/google/protobuf/compiler/cpp/cpp_string_field.cc b/src/google/protobuf/compiler/cpp/cpp_string_field.cc index 1d743457..aee3d1ea 100644 --- a/src/google/protobuf/compiler/cpp/cpp_string_field.cc +++ b/src/google/protobuf/compiler/cpp/cpp_string_field.cc @@ -166,25 +166,25 @@ void StringFieldGenerator:: GenerateInlineAccessorDefinitions(io::Printer* printer, bool is_inline) const { map variables(variables_); - variables["inline"] = is_inline ? "inline" : ""; + variables["inline"] = is_inline ? "inline " : ""; if (SupportsArenas(descriptor_)) { printer->Print(variables, - "$inline$ const ::std::string& $classname$::$name$() const {\n" + "$inline$const ::std::string& $classname$::$name$() const {\n" " // @@protoc_insertion_point(field_get:$full_name$)\n" " return $name$_.Get($default_variable$);\n" "}\n" - "$inline$ void $classname$::set_$name$(const ::std::string& value) {\n" + "$inline$void $classname$::set_$name$(const ::std::string& value) {\n" " $set_hasbit$\n" " $name$_.Set($default_variable$, value, GetArenaNoVirtual());\n" " // @@protoc_insertion_point(field_set:$full_name$)\n" "}\n" - "$inline$ void $classname$::set_$name$(const char* value) {\n" + "$inline$void $classname$::set_$name$(const char* value) {\n" " $set_hasbit$\n" " $name$_.Set($default_variable$, $string_piece$(value),\n" " GetArenaNoVirtual());\n" " // @@protoc_insertion_point(field_set_char:$full_name$)\n" "}\n" - "$inline$ " + "$inline$" "void $classname$::set_$name$(const $pointer_type$* value,\n" " size_t size) {\n" " $set_hasbit$\n" @@ -192,24 +192,24 @@ GenerateInlineAccessorDefinitions(io::Printer* printer, " reinterpret_cast(value), size), GetArenaNoVirtual());\n" " // @@protoc_insertion_point(field_set_pointer:$full_name$)\n" "}\n" - "$inline$ ::std::string* $classname$::mutable_$name$() {\n" + "$inline$::std::string* $classname$::mutable_$name$() {\n" " $set_hasbit$\n" " // @@protoc_insertion_point(field_mutable:$full_name$)\n" " return $name$_.Mutable($default_variable$, GetArenaNoVirtual());\n" "}\n" - "$inline$ ::std::string* $classname$::$release_name$() {\n" + "$inline$::std::string* $classname$::$release_name$() {\n" " // @@protoc_insertion_point(field_release:$full_name$)\n" " $clear_hasbit$\n" " return $name$_.Release($default_variable$, GetArenaNoVirtual());\n" "}\n" - "$inline$ ::std::string* $classname$::unsafe_arena_release_$name$() {\n" + "$inline$::std::string* $classname$::unsafe_arena_release_$name$() {\n" " // @@protoc_insertion_point(field_unsafe_arena_release:$full_name$)\n" " GOOGLE_DCHECK(GetArenaNoVirtual() != NULL);\n" " $clear_hasbit$\n" " return $name$_.UnsafeArenaRelease($default_variable$,\n" " GetArenaNoVirtual());\n" "}\n" - "$inline$ void $classname$::set_allocated_$name$(::std::string* $name$) {\n" + "$inline$void $classname$::set_allocated_$name$(::std::string* $name$) {\n" " if ($name$ != NULL) {\n" " $set_hasbit$\n" " } else {\n" @@ -219,7 +219,7 @@ GenerateInlineAccessorDefinitions(io::Printer* printer, " GetArenaNoVirtual());\n" " // @@protoc_insertion_point(field_set_allocated:$full_name$)\n" "}\n" - "$inline$ void $classname$::unsafe_arena_set_allocated_$name$(\n" + "$inline$void $classname$::unsafe_arena_set_allocated_$name$(\n" " ::std::string* $name$) {\n" " GOOGLE_DCHECK(GetArenaNoVirtual() != NULL);\n" " if ($name$ != NULL) {\n" @@ -235,21 +235,21 @@ GenerateInlineAccessorDefinitions(io::Printer* printer, } else { // No-arena case. printer->Print(variables, - "$inline$ const ::std::string& $classname$::$name$() const {\n" + "$inline$const ::std::string& $classname$::$name$() const {\n" " // @@protoc_insertion_point(field_get:$full_name$)\n" " return $name$_.GetNoArena($default_variable$);\n" "}\n" - "$inline$ void $classname$::set_$name$(const ::std::string& value) {\n" + "$inline$void $classname$::set_$name$(const ::std::string& value) {\n" " $set_hasbit$\n" " $name$_.SetNoArena($default_variable$, value);\n" " // @@protoc_insertion_point(field_set:$full_name$)\n" "}\n" - "$inline$ void $classname$::set_$name$(const char* value) {\n" + "$inline$void $classname$::set_$name$(const char* value) {\n" " $set_hasbit$\n" " $name$_.SetNoArena($default_variable$, $string_piece$(value));\n" " // @@protoc_insertion_point(field_set_char:$full_name$)\n" "}\n" - "$inline$ " + "$inline$" "void $classname$::set_$name$(const $pointer_type$* value, " "size_t size) {\n" " $set_hasbit$\n" @@ -257,17 +257,17 @@ GenerateInlineAccessorDefinitions(io::Printer* printer, " $string_piece$(reinterpret_cast(value), size));\n" " // @@protoc_insertion_point(field_set_pointer:$full_name$)\n" "}\n" - "$inline$ ::std::string* $classname$::mutable_$name$() {\n" + "$inline$::std::string* $classname$::mutable_$name$() {\n" " $set_hasbit$\n" " // @@protoc_insertion_point(field_mutable:$full_name$)\n" " return $name$_.MutableNoArena($default_variable$);\n" "}\n" - "$inline$ ::std::string* $classname$::$release_name$() {\n" + "$inline$::std::string* $classname$::$release_name$() {\n" " // @@protoc_insertion_point(field_release:$full_name$)\n" " $clear_hasbit$\n" " return $name$_.ReleaseNoArena($default_variable$);\n" "}\n" - "$inline$ void $classname$::set_allocated_$name$(::std::string* $name$) {\n" + "$inline$void $classname$::set_allocated_$name$(::std::string* $name$) {\n" " if ($name$ != NULL) {\n" " $set_hasbit$\n" " } else {\n" @@ -339,8 +339,10 @@ GenerateConstructorCode(io::Printer* printer) const { void StringFieldGenerator:: GenerateDestructorCode(io::Printer* printer) const { if (SupportsArenas(descriptor_)) { + // The variable |arena| is defined by the enclosing code. + // See MessageGenerator::GenerateSharedDestructorCode. printer->Print(variables_, - "$name$_.Destroy($default_variable$, GetArenaNoVirtual());\n"); + "$name$_.Destroy($default_variable$, arena);\n"); } else { printer->Print(variables_, "$name$_.DestroyNoArena($default_variable$);\n"); @@ -426,17 +428,17 @@ void StringOneofFieldGenerator:: GenerateInlineAccessorDefinitions(io::Printer* printer, bool is_inline) const { map variables(variables_); - variables["inline"] = is_inline ? "inline" : ""; + variables["inline"] = is_inline ? "inline " : ""; if (SupportsArenas(descriptor_)) { printer->Print(variables, - "$inline$ const ::std::string& $classname$::$name$() const {\n" + "$inline$const ::std::string& $classname$::$name$() const {\n" " // @@protoc_insertion_point(field_get:$full_name$)\n" " if (has_$name$()) {\n" " return $oneof_prefix$$name$_.Get($default_variable$);\n" " }\n" " return *$default_variable$;\n" "}\n" - "$inline$ void $classname$::set_$name$(const ::std::string& value) {\n" + "$inline$void $classname$::set_$name$(const ::std::string& value) {\n" " if (!has_$name$()) {\n" " clear_$oneof_name$();\n" " set_has_$name$();\n" @@ -446,7 +448,7 @@ GenerateInlineAccessorDefinitions(io::Printer* printer, " GetArenaNoVirtual());\n" " // @@protoc_insertion_point(field_set:$full_name$)\n" "}\n" - "$inline$ void $classname$::set_$name$(const char* value) {\n" + "$inline$void $classname$::set_$name$(const char* value) {\n" " if (!has_$name$()) {\n" " clear_$oneof_name$();\n" " set_has_$name$();\n" @@ -456,7 +458,7 @@ GenerateInlineAccessorDefinitions(io::Printer* printer, " $string_piece$(value), GetArenaNoVirtual());\n" " // @@protoc_insertion_point(field_set_char:$full_name$)\n" "}\n" - "$inline$ " + "$inline$" "void $classname$::set_$name$(const $pointer_type$* value,\n" " size_t size) {\n" " if (!has_$name$()) {\n" @@ -469,7 +471,7 @@ GenerateInlineAccessorDefinitions(io::Printer* printer, " GetArenaNoVirtual());\n" " // @@protoc_insertion_point(field_set_pointer:$full_name$)\n" "}\n" - "$inline$ ::std::string* $classname$::mutable_$name$() {\n" + "$inline$::std::string* $classname$::mutable_$name$() {\n" " if (!has_$name$()) {\n" " clear_$oneof_name$();\n" " set_has_$name$();\n" @@ -479,7 +481,7 @@ GenerateInlineAccessorDefinitions(io::Printer* printer, " GetArenaNoVirtual());\n" " // @@protoc_insertion_point(field_mutable:$full_name$)\n" "}\n" - "$inline$ ::std::string* $classname$::$release_name$() {\n" + "$inline$::std::string* $classname$::$release_name$() {\n" " // @@protoc_insertion_point(field_release:$full_name$)\n" " if (has_$name$()) {\n" " clear_has_$oneof_name$();\n" @@ -489,7 +491,7 @@ GenerateInlineAccessorDefinitions(io::Printer* printer, " return NULL;\n" " }\n" "}\n" - "$inline$ ::std::string* $classname$::unsafe_arena_release_$name$() {\n" + "$inline$::std::string* $classname$::unsafe_arena_release_$name$() {\n" " // @@protoc_insertion_point(field_unsafe_arena_release:$full_name$)\n" " GOOGLE_DCHECK(GetArenaNoVirtual() != NULL);\n" " if (has_$name$()) {\n" @@ -500,7 +502,7 @@ GenerateInlineAccessorDefinitions(io::Printer* printer, " return NULL;\n" " }\n" "}\n" - "$inline$ void $classname$::set_allocated_$name$(::std::string* $name$) {\n" + "$inline$void $classname$::set_allocated_$name$(::std::string* $name$) {\n" " if (!has_$name$()) {\n" " $oneof_prefix$$name$_.UnsafeSetDefault($default_variable$);\n" " }\n" @@ -512,7 +514,7 @@ GenerateInlineAccessorDefinitions(io::Printer* printer, " }\n" " // @@protoc_insertion_point(field_set_allocated:$full_name$)\n" "}\n" - "$inline$ void $classname$::unsafe_arena_set_allocated_$name$(" + "$inline$void $classname$::unsafe_arena_set_allocated_$name$(" "::std::string* $name$) {\n" " GOOGLE_DCHECK(GetArenaNoVirtual() != NULL);\n" " if (!has_$name$()) {\n" @@ -530,14 +532,14 @@ GenerateInlineAccessorDefinitions(io::Printer* printer, } else { // No-arena case. printer->Print(variables, - "$inline$ const ::std::string& $classname$::$name$() const {\n" + "$inline$const ::std::string& $classname$::$name$() const {\n" " // @@protoc_insertion_point(field_get:$full_name$)\n" " if (has_$name$()) {\n" " return $oneof_prefix$$name$_.GetNoArena($default_variable$);\n" " }\n" " return *$default_variable$;\n" "}\n" - "$inline$ void $classname$::set_$name$(const ::std::string& value) {\n" + "$inline$void $classname$::set_$name$(const ::std::string& value) {\n" " // @@protoc_insertion_point(field_set:$full_name$)\n" " if (!has_$name$()) {\n" " clear_$oneof_name$();\n" @@ -547,7 +549,7 @@ GenerateInlineAccessorDefinitions(io::Printer* printer, " $oneof_prefix$$name$_.SetNoArena($default_variable$, value);\n" " // @@protoc_insertion_point(field_set:$full_name$)\n" "}\n" - "$inline$ void $classname$::set_$name$(const char* value) {\n" + "$inline$void $classname$::set_$name$(const char* value) {\n" " if (!has_$name$()) {\n" " clear_$oneof_name$();\n" " set_has_$name$();\n" @@ -557,7 +559,7 @@ GenerateInlineAccessorDefinitions(io::Printer* printer, " $string_piece$(value));\n" " // @@protoc_insertion_point(field_set_char:$full_name$)\n" "}\n" - "$inline$ " + "$inline$" "void $classname$::set_$name$(const $pointer_type$* value, size_t size) {\n" " if (!has_$name$()) {\n" " clear_$oneof_name$();\n" @@ -568,7 +570,7 @@ GenerateInlineAccessorDefinitions(io::Printer* printer, " reinterpret_cast(value), size));\n" " // @@protoc_insertion_point(field_set_pointer:$full_name$)\n" "}\n" - "$inline$ ::std::string* $classname$::mutable_$name$() {\n" + "$inline$::std::string* $classname$::mutable_$name$() {\n" " if (!has_$name$()) {\n" " clear_$oneof_name$();\n" " set_has_$name$();\n" @@ -577,7 +579,7 @@ GenerateInlineAccessorDefinitions(io::Printer* printer, " // @@protoc_insertion_point(field_mutable:$full_name$)\n" " return $oneof_prefix$$name$_.MutableNoArena($default_variable$);\n" "}\n" - "$inline$ ::std::string* $classname$::$release_name$() {\n" + "$inline$::std::string* $classname$::$release_name$() {\n" " // @@protoc_insertion_point(field_release:$full_name$)\n" " if (has_$name$()) {\n" " clear_has_$oneof_name$();\n" @@ -586,7 +588,7 @@ GenerateInlineAccessorDefinitions(io::Printer* printer, " return NULL;\n" " }\n" "}\n" - "$inline$ void $classname$::set_allocated_$name$(::std::string* $name$) {\n" + "$inline$void $classname$::set_allocated_$name$(::std::string* $name$) {\n" " if (!has_$name$()) {\n" " $oneof_prefix$$name$_.UnsafeSetDefault($default_variable$);\n" " }\n" @@ -732,55 +734,55 @@ void RepeatedStringFieldGenerator:: GenerateInlineAccessorDefinitions(io::Printer* printer, bool is_inline) const { map variables(variables_); - variables["inline"] = is_inline ? "inline" : ""; + variables["inline"] = is_inline ? "inline " : ""; printer->Print(variables, - "$inline$ const ::std::string& $classname$::$name$(int index) const {\n" + "$inline$const ::std::string& $classname$::$name$(int index) const {\n" " // @@protoc_insertion_point(field_get:$full_name$)\n" " return $name$_.$cppget$(index);\n" "}\n" - "$inline$ ::std::string* $classname$::mutable_$name$(int index) {\n" + "$inline$::std::string* $classname$::mutable_$name$(int index) {\n" " // @@protoc_insertion_point(field_mutable:$full_name$)\n" " return $name$_.Mutable(index);\n" "}\n" - "$inline$ void $classname$::set_$name$(int index, const ::std::string& value) {\n" + "$inline$void $classname$::set_$name$(int index, const ::std::string& value) {\n" " // @@protoc_insertion_point(field_set:$full_name$)\n" " $name$_.Mutable(index)->assign(value);\n" "}\n" - "$inline$ void $classname$::set_$name$(int index, const char* value) {\n" + "$inline$void $classname$::set_$name$(int index, const char* value) {\n" " $name$_.Mutable(index)->assign(value);\n" " // @@protoc_insertion_point(field_set_char:$full_name$)\n" "}\n" - "$inline$ void " + "$inline$void " "$classname$::set_$name$" "(int index, const $pointer_type$* value, size_t size) {\n" " $name$_.Mutable(index)->assign(\n" " reinterpret_cast(value), size);\n" " // @@protoc_insertion_point(field_set_pointer:$full_name$)\n" "}\n" - "$inline$ ::std::string* $classname$::add_$name$() {\n" + "$inline$::std::string* $classname$::add_$name$() {\n" " // @@protoc_insertion_point(field_add_mutable:$full_name$)\n" " return $name$_.Add();\n" "}\n" - "$inline$ void $classname$::add_$name$(const ::std::string& value) {\n" + "$inline$void $classname$::add_$name$(const ::std::string& value) {\n" " $name$_.Add()->assign(value);\n" " // @@protoc_insertion_point(field_add:$full_name$)\n" "}\n" - "$inline$ void $classname$::add_$name$(const char* value) {\n" + "$inline$void $classname$::add_$name$(const char* value) {\n" " $name$_.Add()->assign(value);\n" " // @@protoc_insertion_point(field_add_char:$full_name$)\n" "}\n" - "$inline$ void " + "$inline$void " "$classname$::add_$name$(const $pointer_type$* value, size_t size) {\n" " $name$_.Add()->assign(reinterpret_cast(value), size);\n" " // @@protoc_insertion_point(field_add_pointer:$full_name$)\n" "}\n"); printer->Print(variables, - "$inline$ const ::google::protobuf::RepeatedPtrField< ::std::string>&\n" + "$inline$const ::google::protobuf::RepeatedPtrField< ::std::string>&\n" "$classname$::$name$() const {\n" " // @@protoc_insertion_point(field_list:$full_name$)\n" " return $name$_;\n" "}\n" - "$inline$ ::google::protobuf::RepeatedPtrField< ::std::string>*\n" + "$inline$::google::protobuf::RepeatedPtrField< ::std::string>*\n" "$classname$::mutable_$name$() {\n" " // @@protoc_insertion_point(field_mutable_list:$full_name$)\n" " return &$name$_;\n" @@ -797,6 +799,11 @@ GenerateMergingCode(io::Printer* printer) const { printer->Print(variables_, "$name$_.MergeFrom(from.$name$_);\n"); } +void RepeatedStringFieldGenerator:: +GenerateUnsafeMergingCode(io::Printer* printer) const { + printer->Print(variables_, "$name$_.UnsafeMergeFrom(from.$name$_);\n"); +} + void RepeatedStringFieldGenerator:: GenerateSwappingCode(io::Printer* printer) const { printer->Print(variables_, "$name$_.UnsafeArenaSwap(&other->$name$_);\n"); @@ -858,7 +865,8 @@ GenerateSerializeWithCachedSizesToArray(io::Printer* printer) const { void RepeatedStringFieldGenerator:: GenerateByteSize(io::Printer* printer) const { printer->Print(variables_, - "total_size += $tag_size$ * this->$name$_size();\n" + "total_size += $tag_size$ *\n" + " ::google::protobuf::internal::FromIntSize(this->$name$_size());\n" "for (int i = 0; i < this->$name$_size(); i++) {\n" " total_size += ::google::protobuf::internal::WireFormatLite::$declared_type$Size(\n" " this->$name$(i));\n" diff --git a/src/google/protobuf/compiler/cpp/cpp_string_field.h b/src/google/protobuf/compiler/cpp/cpp_string_field.h index cb4e8772..1dea7663 100644 --- a/src/google/protobuf/compiler/cpp/cpp_string_field.h +++ b/src/google/protobuf/compiler/cpp/cpp_string_field.h @@ -110,6 +110,7 @@ class RepeatedStringFieldGenerator : public FieldGenerator { bool is_inline) const; void GenerateClearingCode(io::Printer* printer) const; void GenerateMergingCode(io::Printer* printer) const; + void GenerateUnsafeMergingCode(io::Printer* printer) const; void GenerateSwappingCode(io::Printer* printer) const; void GenerateConstructorCode(io::Printer* printer) const; void GenerateMergeFromCodedStream(io::Printer* printer) const; diff --git a/src/google/protobuf/compiler/cpp/cpp_unittest.cc b/src/google/protobuf/compiler/cpp/cpp_unittest.cc index b7b6039a..d214ef0a 100644 --- a/src/google/protobuf/compiler/cpp/cpp_unittest.cc +++ b/src/google/protobuf/compiler/cpp/cpp_unittest.cc @@ -129,12 +129,12 @@ TEST(GeneratedDescriptorTest, IdenticalDescriptors) { // Test that descriptors are generated correctly by converting them to // FileDescriptorProtos and comparing. - FileDescriptorProto generated_decsriptor_proto, parsed_descriptor_proto; - generated_descriptor->CopyTo(&generated_decsriptor_proto); + FileDescriptorProto generated_descriptor_proto, parsed_descriptor_proto; + generated_descriptor->CopyTo(&generated_descriptor_proto); parsed_descriptor->CopyTo(&parsed_descriptor_proto); EXPECT_EQ(parsed_descriptor_proto.DebugString(), - generated_decsriptor_proto.DebugString()); + generated_descriptor_proto.DebugString()); } #if !defined(GOOGLE_PROTOBUF_CMAKE_BUILD) && !defined(_MSC_VER) diff --git a/src/google/protobuf/compiler/java/java_file.cc b/src/google/protobuf/compiler/java/java_file.cc index 5e387285..3cbc530e 100644 --- a/src/google/protobuf/compiler/java/java_file.cc +++ b/src/google/protobuf/compiler/java/java_file.cc @@ -189,8 +189,6 @@ void MaybeRestartJavaMethod(io::Printer* printer, *bytecode_estimate = 0; } } - - } // namespace FileGenerator::FileGenerator(const FileDescriptor* file, const Options& options, diff --git a/src/google/protobuf/compiler/java/java_map_field.cc b/src/google/protobuf/compiler/java/java_map_field.cc index 16c5bec5..07aa3565 100644 --- a/src/google/protobuf/compiler/java/java_map_field.cc +++ b/src/google/protobuf/compiler/java/java_map_field.cc @@ -92,7 +92,11 @@ void SetMessageVariables(const FieldDescriptor* descriptor, const JavaType valueJavaType = GetJavaType(value); (*variables)["key_type"] = TypeName(key, name_resolver, false); - (*variables)["boxed_key_type"] = TypeName(key, name_resolver, true); + string boxed_key_type = TypeName(key, name_resolver, true); + (*variables)["boxed_key_type"] = boxed_key_type; + // Used for calling the serialization function. + (*variables)["short_key_type"] = + boxed_key_type.substr(boxed_key_type.rfind('.') + 1); (*variables)["key_wire_type"] = WireType(key); (*variables)["key_default_value"] = DefaultValue(key, true, name_resolver); (*variables)["key_null_check"] = IsReferenceType(keyJavaType) ? @@ -147,6 +151,7 @@ void SetMessageVariables(const FieldDescriptor* descriptor, name_resolver->GetImmutableClassName(descriptor->file()) + ".internal_" + UniqueFileScopeIdentifier(descriptor->message_type()) + "_descriptor, "; + (*variables)["ver"] = GeneratedCodeVersionSuffix(); } } // namespace @@ -661,21 +666,23 @@ GenerateParsingCode(io::Printer* printer) const { variables_, "com.google.protobuf.ByteString bytes = input.readBytes();\n" "com.google.protobuf.MapEntry<$type_parameters$>\n" - "$name$ = $default_entry$.getParserForType().parseFrom(bytes);\n"); + "$name$__ = $default_entry$.getParserForType().parseFrom(bytes);\n"); printer->Print( variables_, - "if ($value_enum_type$.forNumber($name$.getValue()) == null) {\n" + "if ($value_enum_type$.forNumber($name$__.getValue()) == null) {\n" " unknownFields.mergeLengthDelimitedField($number$, bytes);\n" "} else {\n" - " $name$_.getMutableMap().put($name$.getKey(), $name$.getValue());\n" + " $name$_.getMutableMap().put(\n" + " $name$__.getKey(), $name$__.getValue());\n" "}\n"); } else { printer->Print( variables_, "com.google.protobuf.MapEntry<$type_parameters$>\n" - "$name$ = input.readMessage(\n" + "$name$__ = input.readMessage(\n" " $default_entry$.getParserForType(), extensionRegistry);\n" - "$name$_.getMutableMap().put($name$.getKey(), $name$.getValue());\n"); + "$name$_.getMutableMap().put(\n" + " $name$__.getKey(), $name$__.getValue());\n"); } } @@ -688,15 +695,12 @@ void ImmutableMapFieldGenerator:: GenerateSerializationCode(io::Printer* printer) const { printer->Print( variables_, - "for (java.util.Map.Entry<$type_parameters$> entry\n" - " : internalGet$capitalized_name$().getMap().entrySet()) {\n" - " com.google.protobuf.MapEntry<$type_parameters$>\n" - " $name$ = $default_entry$.newBuilderForType()\n" - " .setKey(entry.getKey())\n" - " .setValue(entry.getValue())\n" - " .build();\n" - " output.writeMessage($number$, $name$);\n" - "}\n"); + "com.google.protobuf.GeneratedMessage$ver$\n" + " .serialize$short_key_type$MapTo(\n" + " output,\n" + " internalGet$capitalized_name$(),\n" + " $default_entry$,\n" + " $number$);\n"); } void ImmutableMapFieldGenerator:: @@ -706,12 +710,12 @@ GenerateSerializedSizeCode(io::Printer* printer) const { "for (java.util.Map.Entry<$type_parameters$> entry\n" " : internalGet$capitalized_name$().getMap().entrySet()) {\n" " com.google.protobuf.MapEntry<$type_parameters$>\n" - " $name$ = $default_entry$.newBuilderForType()\n" + " $name$__ = $default_entry$.newBuilderForType()\n" " .setKey(entry.getKey())\n" " .setValue(entry.getValue())\n" " .build();\n" " size += com.google.protobuf.CodedOutputStream\n" - " .computeMessageSize($number$, $name$);\n" + " .computeMessageSize($number$, $name$__);\n" "}\n"); } diff --git a/src/google/protobuf/compiler/java/java_map_field_lite.cc b/src/google/protobuf/compiler/java/java_map_field_lite.cc index 0d3bea17..5f102e07 100644 --- a/src/google/protobuf/compiler/java/java_map_field_lite.cc +++ b/src/google/protobuf/compiler/java/java_map_field_lite.cc @@ -765,14 +765,14 @@ GenerateParsingCode(io::Printer* printer) const { printer->Print( variables_, "com.google.protobuf.ByteString bytes = input.readBytes();\n" - "java.util.Map.Entry<$type_parameters$> $name$ =\n" + "java.util.Map.Entry<$type_parameters$> $name$__ =\n" " $default_entry$.parseEntry(bytes, extensionRegistry);\n"); printer->Print( variables_, - "if ($value_enum_type$.forNumber($name$.getValue()) == null) {\n" + "if ($value_enum_type$.forNumber($name$__.getValue()) == null) {\n" " super.mergeLengthDelimitedField($number$, bytes);\n" "} else {\n" - " $name$_.put($name$);\n" + " $name$_.put($name$__);\n" "}\n"); } else { printer->Print( diff --git a/src/google/protobuf/compiler/java/java_message.cc b/src/google/protobuf/compiler/java/java_message.cc index 6c80d070..68d28b05 100644 --- a/src/google/protobuf/compiler/java/java_message.cc +++ b/src/google/protobuf/compiler/java/java_message.cc @@ -928,7 +928,7 @@ void ImmutableMessageGenerator::GenerateIsInitialized( case FieldDescriptor::LABEL_REPEATED: if (IsMapEntry(field->message_type())) { printer->Print( - "for ($type$ item : get$name$().values()) {\n" + "for ($type$ item : get$name$Map().values()) {\n" " if (!item.isInitialized()) {\n" " memoizedIsInitialized = 0;\n" " return false;\n" diff --git a/src/google/protobuf/compiler/java/java_message_builder.cc b/src/google/protobuf/compiler/java/java_message_builder.cc index 42154694..cd82c51a 100644 --- a/src/google/protobuf/compiler/java/java_message_builder.cc +++ b/src/google/protobuf/compiler/java/java_message_builder.cc @@ -184,6 +184,11 @@ Generate(io::Printer* printer) { "}\n" "\n"); } else { + // Override methods declared in GeneratedMessage to return the concrete + // generated type so callsites won't depend on GeneratedMessage. This + // is needed to keep binary compatibility when we change generated code + // to subclass a different GeneratedMessage class (e.g., in v3.0.0 release + // we changed all generated code to subclass GeneratedMessageV3). printer->Print( "public final Builder setUnknownFields(\n" " final com.google.protobuf.UnknownFieldSet unknownFields) {\n" @@ -456,6 +461,11 @@ GenerateCommonBuilderMethods(io::Printer* printer) { "\n", "classname", name_resolver_->GetImmutableClassName(descriptor_)); + // Override methods declared in GeneratedMessage to return the concrete + // generated type so callsites won't depend on GeneratedMessage. This + // is needed to keep binary compatibility when we change generated code + // to subclass a different GeneratedMessage class (e.g., in v3.0.0 release + // we changed all generated code to subclass GeneratedMessageV3). printer->Print( "public Builder clone() {\n" " return (Builder) super.clone();\n" @@ -596,7 +606,6 @@ GenerateCommonBuilderMethods(io::Printer* printer) { " return this;\n" "}\n" "\n"); - } } @@ -690,7 +699,7 @@ void MessageBuilderGenerator::GenerateIsInitialized( case FieldDescriptor::LABEL_REPEATED: if (IsMapEntry(field->message_type())) { printer->Print( - "for ($type$ item : get$name$().values()) {\n" + "for ($type$ item : get$name$Map().values()) {\n" " if (!item.isInitialized()) {\n" " return false;\n" " }\n" diff --git a/src/google/protobuf/compiler/java/java_message_field_lite.cc b/src/google/protobuf/compiler/java/java_message_field_lite.cc index 14281816..cba18360 100644 --- a/src/google/protobuf/compiler/java/java_message_field_lite.cc +++ b/src/google/protobuf/compiler/java/java_message_field_lite.cc @@ -145,6 +145,7 @@ GenerateInterfaceMembers(io::Printer* printer) const { void ImmutableMessageFieldLiteGenerator:: GenerateMembers(io::Printer* printer) const { + printer->Print(variables_, "private $type$ $name$_;\n"); PrintExtraFieldInfo(variables_, printer); diff --git a/src/google/protobuf/compiler/java/java_message_lite.cc b/src/google/protobuf/compiler/java/java_message_lite.cc index 7c8c4a03..0c5a1f8a 100644 --- a/src/google/protobuf/compiler/java/java_message_lite.cc +++ b/src/google/protobuf/compiler/java/java_message_lite.cc @@ -179,6 +179,7 @@ void ImmutableMessageLiteGenerator::Generate(io::Printer* printer) { MaybePrintGeneratedAnnotation(context_, printer, descriptor_, /* immutable = */ true); + // The builder_type stores the super type name of the nested Builder class. string builder_type; if (descriptor_->extension_range_count() > 0) { @@ -203,7 +204,6 @@ void ImmutableMessageLiteGenerator::Generate(io::Printer* printer) { } printer->Indent(); - GenerateConstructor(printer); // Nested types @@ -748,7 +748,7 @@ void ImmutableMessageLiteGenerator::GenerateDynamicMethodIsInitialized( case FieldDescriptor::LABEL_REPEATED: if (IsMapEntry(field->message_type())) { printer->Print( - "for ($type$ item : get$name$().values()) {\n" + "for ($type$ item : get$name$Map().values()) {\n" " if (!item.isInitialized()) {\n" " if (shouldMemoize) {\n" " memoizedIsInitialized = 0;\n" diff --git a/src/google/protobuf/compiler/java/java_service.cc b/src/google/protobuf/compiler/java/java_service.cc index 9f34f010..cfa8295d 100644 --- a/src/google/protobuf/compiler/java/java_service.cc +++ b/src/google/protobuf/compiler/java/java_service.cc @@ -184,6 +184,10 @@ void ImmutableServiceGenerator::GenerateAbstractMethods(io::Printer* printer) { } } +string ImmutableServiceGenerator::GetOutput(const MethodDescriptor* method) { + return name_resolver_->GetImmutableClassName(method->output_type()); +} + void ImmutableServiceGenerator::GenerateCallMethod(io::Printer* printer) { printer->Print( "\n" @@ -209,8 +213,7 @@ void ImmutableServiceGenerator::GenerateCallMethod(io::Printer* printer) { vars["method"] = UnderscoresToCamelCase(method); vars["input"] = name_resolver_->GetImmutableClassName( method->input_type()); - vars["output"] = name_resolver_->GetImmutableClassName( - method->output_type()); + vars["output"] = GetOutput(method); printer->Print(vars, "case $index$:\n" " this.$method$(controller, ($input$)request,\n" @@ -257,8 +260,7 @@ void ImmutableServiceGenerator::GenerateCallBlockingMethod( vars["method"] = UnderscoresToCamelCase(method); vars["input"] = name_resolver_->GetImmutableClassName( method->input_type()); - vars["output"] = name_resolver_->GetImmutableClassName( - method->output_type()); + vars["output"] = GetOutput(method); printer->Print(vars, "case $index$:\n" " return impl.$method$(controller, ($input$)request);\n"); @@ -353,8 +355,7 @@ void ImmutableServiceGenerator::GenerateStub(io::Printer* printer) { map vars; vars["index"] = SimpleItoa(i); - vars["output"] = name_resolver_->GetImmutableClassName( - method->output_type()); + vars["output"] = GetOutput(method); printer->Print(vars, "channel.callMethod(\n" " getDescriptor().getMethods().get($index$),\n" @@ -418,8 +419,7 @@ void ImmutableServiceGenerator::GenerateBlockingStub(io::Printer* printer) { map vars; vars["index"] = SimpleItoa(i); - vars["output"] = name_resolver_->GetImmutableClassName( - method->output_type()); + vars["output"] = GetOutput(method); printer->Print(vars, "return ($output$) channel.callBlockingMethod(\n" " getDescriptor().getMethods().get($index$),\n" @@ -443,7 +443,7 @@ void ImmutableServiceGenerator::GenerateMethodSignature(io::Printer* printer, map vars; vars["name"] = UnderscoresToCamelCase(method); vars["input"] = name_resolver_->GetImmutableClassName(method->input_type()); - vars["output"] = name_resolver_->GetImmutableClassName(method->output_type()); + vars["output"] = GetOutput(method); vars["abstract"] = (is_abstract == IS_ABSTRACT) ? "abstract" : ""; printer->Print(vars, "public $abstract$ void $name$(\n" @@ -458,7 +458,7 @@ void ImmutableServiceGenerator::GenerateBlockingMethodSignature( map vars; vars["method"] = UnderscoresToCamelCase(method); vars["input"] = name_resolver_->GetImmutableClassName(method->input_type()); - vars["output"] = name_resolver_->GetImmutableClassName(method->output_type()); + vars["output"] = GetOutput(method); printer->Print(vars, "\n" "public $output$ $method$(\n" diff --git a/src/google/protobuf/compiler/java/java_service.h b/src/google/protobuf/compiler/java/java_service.h index 5fc9e2f6..12b3f942 100644 --- a/src/google/protobuf/compiler/java/java_service.h +++ b/src/google/protobuf/compiler/java/java_service.h @@ -122,6 +122,9 @@ class ImmutableServiceGenerator : public ServiceGenerator { void GenerateBlockingMethodSignature(io::Printer* printer, const MethodDescriptor* method); + // Return the output type of the method. + string GetOutput(const MethodDescriptor* method); + Context* context_; ClassNameResolver* name_resolver_; GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(ImmutableServiceGenerator); diff --git a/src/google/protobuf/compiler/java/java_shared_code_generator.cc b/src/google/protobuf/compiler/java/java_shared_code_generator.cc index 52893721..18bf1f51 100644 --- a/src/google/protobuf/compiler/java/java_shared_code_generator.cc +++ b/src/google/protobuf/compiler/java/java_shared_code_generator.cc @@ -119,7 +119,6 @@ void SharedCodeGenerator::Generate(GeneratorContext* context, } } - void SharedCodeGenerator::GenerateDescriptors(io::Printer* printer) { // Embed the descriptor. We simply serialize the entire FileDescriptorProto // and embed it as a string literal, which is parsed and built into real @@ -134,7 +133,6 @@ void SharedCodeGenerator::GenerateDescriptors(io::Printer* printer) { FileDescriptorProto file_proto; file_->CopyTo(&file_proto); - string file_data; file_proto.SerializeToString(&file_data); diff --git a/src/google/protobuf/compiler/js/js_generator.cc b/src/google/protobuf/compiler/js/js_generator.cc index 58c77d00..1a882057 100755 --- a/src/google/protobuf/compiler/js/js_generator.cc +++ b/src/google/protobuf/compiler/js/js_generator.cc @@ -153,8 +153,8 @@ string StripProto(const string& filename) { // Given a filename like foo/bar/baz.proto, returns the corresponding JavaScript // file foo/bar/baz.js. -string GetJSFilename(const string& filename) { - return StripProto(filename) + "_pb.js"; +string GetJSFilename(const GeneratorOptions& options, const string& filename) { + return StripProto(filename) + options.GetFileNameExtension(); } // Given a filename like foo/bar/baz.proto, returns the root directory @@ -273,7 +273,7 @@ string GetPath(const GeneratorOptions& options, string MaybeCrossFileRef(const GeneratorOptions& options, const FileDescriptor* from_file, const Descriptor* to_message) { - if (options.import_style == GeneratorOptions::IMPORT_COMMONJS && + if (options.import_style == GeneratorOptions::kImportCommonJs && from_file != to_message->file()) { // Cross-file ref in CommonJS needs to use the module alias instead of // the global name. @@ -405,21 +405,24 @@ string ToFileName(const string& input) { // that top-level extensions should go in. string GetExtensionFileName(const GeneratorOptions& options, const FileDescriptor* file) { - return options.output_dir + "/" + ToFileName(GetPath(options, file)) + ".js"; + return options.output_dir + "/" + ToFileName(GetPath(options, file)) + + options.GetFileNameExtension(); } // When we're generating one output file per type name, this is the filename // that a top-level message should go in. string GetMessageFileName(const GeneratorOptions& options, const Descriptor* desc) { - return options.output_dir + "/" + ToFileName(desc->name()) + ".js"; + return options.output_dir + "/" + ToFileName(desc->name()) + + options.GetFileNameExtension(); } // When we're generating one output file per type name, this is the filename // that a top-level message should go in. string GetEnumFileName(const GeneratorOptions& options, const EnumDescriptor* desc) { - return options.output_dir + "/" + ToFileName(desc->name()) + ".js"; + return options.output_dir + "/" + ToFileName(desc->name()) + + options.GetFileNameExtension(); } // Returns the message/response ID, if set. @@ -444,9 +447,19 @@ bool IgnoreField(const FieldDescriptor* field) { } +// Used inside Google only -- do not remove. +bool ShouldTreatMapsAsRepeatedFields(const FileDescriptor& descriptor) { + return false; +} + // Do we ignore this message type? bool IgnoreMessage(const GeneratorOptions& options, const Descriptor* d) { - return d->options().map_entry(); + return d->options().map_entry() && + !ShouldTreatMapsAsRepeatedFields(*d->file()); +} + +bool IsMap(const GeneratorOptions& options, const FieldDescriptor* field) { + return field->is_map() && !ShouldTreatMapsAsRepeatedFields(*field->file()); } // Does JSPB ignore this entire oneof? True only if all fields are ignored. @@ -459,10 +472,8 @@ bool IgnoreOneof(const OneofDescriptor* oneof) { return true; } -string JSIdent(const GeneratorOptions& options, - const FieldDescriptor* field, - bool is_upper_camel, - bool is_map) { +string JSIdent(const GeneratorOptions& options, const FieldDescriptor* field, + bool is_upper_camel, bool is_map, bool drop_list) { string result; if (field->type() == FieldDescriptor::TYPE_GROUP) { result = is_upper_camel ? @@ -473,10 +484,10 @@ string JSIdent(const GeneratorOptions& options, ToUpperCamel(ParseLowerUnderscore(field->name())) : ToLowerCamel(ParseLowerUnderscore(field->name())); } - if (is_map || (field->is_map())) { + if (is_map || IsMap(options, field)) { // JSPB-style or proto3-style map. result += "Map"; - } else if (field->is_repeated()) { + } else if (!drop_list && field->is_repeated()) { // Repeated field. result += "List"; } @@ -485,11 +496,10 @@ string JSIdent(const GeneratorOptions& options, string JSObjectFieldName(const GeneratorOptions& options, const FieldDescriptor* field) { - string name = JSIdent( - options, - field, - /* is_upper_camel = */ false, - /* is_map = */ false); + string name = JSIdent(options, field, + /* is_upper_camel = */ false, + /* is_map = */ false, + /* drop_list = */ false); if (IsReserved(name)) { name = "pb_" + name; } @@ -514,10 +524,11 @@ string JSByteGetterSuffix(BytesMode bytes_mode) { // name, e.g. MyField for .getMyField(). string JSGetterName(const GeneratorOptions& options, const FieldDescriptor* field, - BytesMode bytes_mode = BYTES_DEFAULT) { + BytesMode bytes_mode = BYTES_DEFAULT, + bool drop_list = false) { string name = JSIdent(options, field, /* is_upper_camel = */ true, - /* is_map = */ false); + /* is_map = */ false, drop_list); if (field->type() == FieldDescriptor::TYPE_BYTES) { string suffix = JSByteGetterSuffix(bytes_mode); if (!suffix.empty()) { @@ -535,7 +546,8 @@ string JSMapGetterName(const GeneratorOptions& options, const FieldDescriptor* field) { return JSIdent(options, field, /* is_upper_camel = */ true, - /* is_map = */ true); + /* is_map = */ true, + /* drop_list = */ false); } @@ -768,6 +780,10 @@ string MaybeNumberString(const FieldDescriptor* field, const string& orig) { } string JSFieldDefault(const FieldDescriptor* field) { + if (field->is_repeated()) { + return "[]"; + } + switch (field->cpp_type()) { case FieldDescriptor::CPPTYPE_INT32: return MaybeNumberString( @@ -909,20 +925,91 @@ string JSTypeName(const GeneratorOptions& options, } } -bool HasFieldPresence(const FieldDescriptor* field); +bool UseBrokenPresenceSemantics(const GeneratorOptions& options, + const FieldDescriptor* field) { + if (field->file()->syntax() == FileDescriptor::SYNTAX_PROTO3) { + return options.broken_proto3_semantics; + } else if (field->file()->syntax() == FileDescriptor::SYNTAX_PROTO2) { + return false; + } else { + GOOGLE_LOG(FATAL) << "We can only handle syntax=proto2 and syntax=proto3."; + return false; + } +} + +// Returns true for fields that return "null" from accessors when they are +// unset. This should normally only be true for non-repeated submessages, but +// we have legacy users who relied on old behavior where accessors behaved this +// way. +bool ReturnsNullWhenUnset(const GeneratorOptions& options, + const FieldDescriptor* field) { + if (field->cpp_type() == FieldDescriptor::CPPTYPE_MESSAGE && + field->is_optional()) { + return true; + } + + // TODO(haberman): remove this case and unconditionally return false. + return UseBrokenPresenceSemantics(options, field) && !field->is_repeated() && + !field->has_default_value(); +} + +// In a sane world, this would be the same as ReturnsNullWhenUnset(). But in +// the status quo, some fields declare that they never return null/undefined +// even though they actually do: +// * required fields +// * optional enum fields +// * proto3 primitive fields. +bool DeclaredReturnTypeIsNullable(const GeneratorOptions& options, + const FieldDescriptor* field) { + if (field->is_required() || field->type() == FieldDescriptor::TYPE_ENUM) { + return false; + } + + if (field->file()->syntax() == FileDescriptor::SYNTAX_PROTO3 && + field->cpp_type() != FieldDescriptor::CPPTYPE_MESSAGE) { + return false; + } + + return ReturnsNullWhenUnset(options, field); +} + +bool SetterAcceptsUndefined(const GeneratorOptions& options, + const FieldDescriptor* field) { + if (ReturnsNullWhenUnset(options, field)) { + return true; + } + + // Broken presence semantics always accepts undefined for setters. + return UseBrokenPresenceSemantics(options, field); +} + +bool SetterAcceptsNull(const GeneratorOptions& options, + const FieldDescriptor* field) { + if (ReturnsNullWhenUnset(options, field)) { + return true; + } + + // With broken presence semantics, fields with defaults accept "null" for + // setters, but other fields do not. This is a strange quirk of the old + // codegen. + return UseBrokenPresenceSemantics(options, field) && + field->has_default_value(); +} + +// Returns types which are known to by non-nullable by default. +// The style guide requires that we omit "!" in this case. +bool IsPrimitive(const string& type) { + return type == "undefined" || type == "string" || type == "number" || + type == "boolean"; +} string JSFieldTypeAnnotation(const GeneratorOptions& options, const FieldDescriptor* field, - bool force_optional, + bool is_setter_argument, bool force_present, bool singular_if_not_packed, BytesMode bytes_mode = BYTES_DEFAULT) { - bool is_primitive = - (field->cpp_type() != FieldDescriptor::CPPTYPE_ENUM && - field->cpp_type() != FieldDescriptor::CPPTYPE_MESSAGE && - (field->type() != FieldDescriptor::TYPE_BYTES || - bytes_mode == BYTES_B64)); - + GOOGLE_CHECK(!(is_setter_argument && force_present)); string jstype = JSTypeName(options, field, bytes_mode); if (field->is_repeated() && @@ -931,27 +1018,35 @@ string JSFieldTypeAnnotation(const GeneratorOptions& options, bytes_mode == BYTES_DEFAULT) { jstype = "(Array|Array)"; } else { - if (!is_primitive) { + if (!IsPrimitive(jstype)) { jstype = "!" + jstype; } jstype = "Array.<" + jstype + ">"; } - if (!force_optional) { - jstype = "!" + jstype; - } } - if (field->is_optional() && is_primitive && - force_optional && !force_present) { - jstype += "?"; - } else if (field->is_required() && !is_primitive && !force_optional) { - jstype = "!" + jstype; - } + bool is_null_or_undefined = false; - if (force_optional && HasFieldPresence(field)) { - jstype += "|undefined"; + if (is_setter_argument) { + if (SetterAcceptsNull(options, field)) { + jstype = "?" + jstype; + is_null_or_undefined = true; + } + + if (SetterAcceptsUndefined(options, field)) { + jstype += "|undefined"; + is_null_or_undefined = true; + } + } else if (force_present) { + // Don't add null or undefined. + } else { + if (DeclaredReturnTypeIsNullable(options, field)) { + jstype = "?" + jstype; + is_null_or_undefined = true; + } } - if (force_present && jstype[0] != '!' && !is_primitive) { + + if (!is_null_or_undefined && !IsPrimitive(jstype)) { jstype = "!" + jstype; } @@ -1007,9 +1102,10 @@ string JSReturnDoc(const GeneratorOptions& options, return ""; } -bool HasRepeatedFields(const Descriptor* desc) { +bool HasRepeatedFields(const GeneratorOptions& options, + const Descriptor* desc) { for (int i = 0; i < desc->field_count(); i++) { - if (desc->field(i)->is_repeated() && !desc->field(i)->is_map()) { + if (desc->field(i)->is_repeated() && !IsMap(options, desc->field(i))) { return true; } } @@ -1020,8 +1116,9 @@ static const char* kRepeatedFieldArrayName = ".repeatedFields_"; string RepeatedFieldsArrayName(const GeneratorOptions& options, const Descriptor* desc) { - return HasRepeatedFields(desc) ? - (GetPath(options, desc) + kRepeatedFieldArrayName) : "null"; + return HasRepeatedFields(options, desc) + ? (GetPath(options, desc) + kRepeatedFieldArrayName) + : "null"; } bool HasOneofFields(const Descriptor* desc) { @@ -1041,10 +1138,11 @@ string OneofFieldsArrayName(const GeneratorOptions& options, (GetPath(options, desc) + kOneofGroupArrayName) : "null"; } -string RepeatedFieldNumberList(const Descriptor* desc) { +string RepeatedFieldNumberList(const GeneratorOptions& options, + const Descriptor* desc) { std::vector numbers; for (int i = 0; i < desc->field_count(); i++) { - if (desc->field(i)->is_repeated() && !desc->field(i)->is_map()) { + if (desc->field(i)->is_repeated() && !IsMap(options, desc->field(i))) { numbers.push_back(JSFieldIndex(desc->field(i))); } } @@ -1108,7 +1206,7 @@ string JSExtensionsObjectName(const GeneratorOptions& options, const FileDescriptor* from_file, const Descriptor* desc) { if (desc->full_name() == "google.protobuf.bridge.MessageSet") { - // TODO(haberman): fix this for the IMPORT_COMMONJS case. + // TODO(haberman): fix this for the kImportCommonJs case. return "jspb.Message.messageSetExtensions"; } else { return MaybeCrossFileRef(options, from_file, desc) + ".extensions"; @@ -1130,7 +1228,7 @@ const FieldDescriptor* MapFieldValue(const FieldDescriptor* field) { string FieldDefinition(const GeneratorOptions& options, const FieldDescriptor* field) { - if (field->is_map()) { + if (IsMap(options, field)) { const FieldDescriptor* key_field = MapFieldKey(field); const FieldDescriptor* value_field = MapFieldValue(field); string key_type = ProtoTypeName(options, key_field); @@ -1254,47 +1352,24 @@ string GetPivot(const Descriptor* desc) { return SimpleItoa(pivot); } -// Returns true for fields that represent "null" as distinct from the default -// value. See http://go/proto3#heading=h.kozewqqcqhuz for more information. -bool HasFieldPresence(const FieldDescriptor* field) { - if (field->is_repeated()) { +// Whether this field represents presence. For fields with presence, we +// generate extra methods (clearFoo() and hasFoo()) for this field. +bool HasFieldPresence(const GeneratorOptions& options, + const FieldDescriptor* field) { + if (field->is_repeated() || field->is_map()) { + // We say repeated fields and maps don't have presence, but we still do + // generate clearFoo() methods for them through a special case elsewhere. return false; } - return - (field->cpp_type() == FieldDescriptor::CPPTYPE_MESSAGE) || - (field->containing_oneof() != NULL) || - (field->file()->syntax() != FileDescriptor::SYNTAX_PROTO3); -} - -// For proto3 fields without presence, returns a string representing the default -// value in JavaScript. See http://go/proto3#heading=h.kozewqqcqhuz for more -// information. -string Proto3PrimitiveFieldDefault(const FieldDescriptor* field) { - switch (field->cpp_type()) { - case FieldDescriptor::CPPTYPE_INT32: - case FieldDescriptor::CPPTYPE_INT64: - case FieldDescriptor::CPPTYPE_UINT32: - case FieldDescriptor::CPPTYPE_UINT64: { - return "0"; - } - - case FieldDescriptor::CPPTYPE_ENUM: - case FieldDescriptor::CPPTYPE_FLOAT: - case FieldDescriptor::CPPTYPE_DOUBLE: - return "0"; - - case FieldDescriptor::CPPTYPE_BOOL: - return "false"; - - case FieldDescriptor::CPPTYPE_STRING: // includes BYTES - return "\"\""; - - default: - // MESSAGE is handled separately. - assert(false); - return ""; + if (UseBrokenPresenceSemantics(options, field)) { + // Proto3 files with broken presence semantics have field presence. + return true; } + + return field->cpp_type() == FieldDescriptor::CPPTYPE_MESSAGE || + field->containing_oneof() != NULL || + field->file()->syntax() == FileDescriptor::SYNTAX_PROTO2; } // We use this to implement the semantics that same file can be generated @@ -1524,8 +1599,19 @@ void Generator::GenerateProvides(const GeneratorOptions& options, std::set* provided) const { for (std::set::iterator it = provided->begin(); it != provided->end(); ++it) { - printer->Print("goog.provide('$name$');\n", - "name", *it); + if (options.import_style == GeneratorOptions::kImportClosure) { + printer->Print("goog.provide('$name$');\n", "name", *it); + } else { + // We aren't using Closure's import system, but we use goog.exportSymbol() + // to construct the expected tree of objects, eg. + // + // goog.exportSymbol('foo.bar.Baz', null, this); + // + // // Later generated code expects foo.bar = {} to exist: + // foo.bar.Baz = function() { /* ... */ } + printer->Print("goog.exportSymbol('$name$', null, global);\n", "name", + *it); + } } } @@ -1548,7 +1634,7 @@ void Generator::GenerateRequiresForLibrary( const GeneratorOptions& options, io::Printer* printer, const vector& files, std::set* provided) const { - GOOGLE_CHECK_EQ(options.import_style, GeneratorOptions::IMPORT_CLOSURE); + GOOGLE_CHECK_EQ(options.import_style, GeneratorOptions::kImportClosure); // For Closure imports we need to import every message type individually. std::set required; std::set forwards; @@ -1623,6 +1709,10 @@ void Generator::GenerateRequiresImpl(const GeneratorOptions& options, } } if (require_extension) { + if (options.binary) { + printer->Print( + "goog.require('jspb.ExtensionFieldBinaryInfo');\n"); + } printer->Print( "goog.require('jspb.ExtensionFieldInfo');\n"); } @@ -1755,14 +1845,13 @@ void Generator::GenerateClass(const GeneratorOptions& options, GenerateClassDeserializeBinary(options, printer, desc); GenerateClassSerializeBinary(options, printer, desc); } - GenerateClassClone(options, printer, desc); GenerateClassRegistration(options, printer, desc); GenerateClassFields(options, printer, desc); if (IsExtendable(desc) && desc->full_name() != "google.protobuf.bridge.MessageSet") { GenerateClassExtensionFieldInfo(options, printer, desc); } - if (options.import_style != GeneratorOptions:: IMPORT_CLOSURE) { + if (options.import_style != GeneratorOptions::kImportClosure) { for (int i = 0; i < desc->extension_count(); i++) { GenerateExtension(options, printer, desc->extension(i)); } @@ -1820,7 +1909,7 @@ void Generator::GenerateClassConstructor(const GeneratorOptions& options, void Generator::GenerateClassFieldInfo(const GeneratorOptions& options, io::Printer* printer, const Descriptor* desc) const { - if (HasRepeatedFields(desc)) { + if (HasRepeatedFields(options, desc)) { printer->Print( "/**\n" " * List of repeated fields within this message type.\n" @@ -1831,7 +1920,7 @@ void Generator::GenerateClassFieldInfo(const GeneratorOptions& options, "\n", "classname", GetPath(options, desc), "rptfieldarray", kRepeatedFieldArrayName, - "rptfields", RepeatedFieldNumberList(desc)); + "rptfields", RepeatedFieldNumberList(options, desc)); } if (HasOneofFields(desc)) { @@ -2000,14 +2089,59 @@ void Generator::GenerateClassToObject(const GeneratorOptions& options, "classname", GetPath(options, desc)); } +void Generator::GenerateFieldValueExpression(io::Printer* printer, + const char *obj_reference, + const FieldDescriptor* field, + bool use_default) const { + bool is_float_or_double = + field->cpp_type() == FieldDescriptor::CPPTYPE_FLOAT || + field->cpp_type() == FieldDescriptor::CPPTYPE_DOUBLE; + if (use_default) { + if (is_float_or_double) { + // Coerce "Nan" and "Infinity" to actual float values. + // + // This will change null to 0, but that doesn't matter since we're getting + // with a default. + printer->Print("+"); + } + + printer->Print( + "jspb.Message.getFieldWithDefault($obj$, $index$, $default$)", + "obj", obj_reference, + "index", JSFieldIndex(field), + "default", JSFieldDefault(field)); + } else { + if (is_float_or_double) { + if (field->is_required()) { + // Use "+" to convert all fields to numeric (including null). + printer->Print( + "+jspb.Message.getField($obj$, $index$)", + "index", JSFieldIndex(field), + "obj", obj_reference); + } else { + // Converts "NaN" and "Infinity" while preserving null. + printer->Print( + "jspb.Message.get$cardinality$FloatingPointField($obj$, $index$)", + "cardinality", field->is_repeated() ? "Repeated" : "Optional", + "index", JSFieldIndex(field), + "obj", obj_reference); + } + } else { + printer->Print("jspb.Message.getField($obj$, $index$)", + "index", JSFieldIndex(field), + "obj", obj_reference); + } + } +} + void Generator::GenerateClassFieldToObject(const GeneratorOptions& options, io::Printer* printer, const FieldDescriptor* field) const { printer->Print("$fieldname$: ", "fieldname", JSObjectFieldName(options, field)); - if (field->is_map()) { - printer->Print("(f = msg.get$name$(true)) ? f.toArray() : []", + if (IsMap(options, field)) { + printer->Print("(f = msg.get$name$()) ? f.toArray() : []", "name", JSGetterName(options, field)); } else if (field->cpp_type() == FieldDescriptor::CPPTYPE_MESSAGE) { // Message field. @@ -2024,40 +2158,29 @@ void Generator::GenerateClassFieldToObject(const GeneratorOptions& options, "getter", JSGetterName(options, field), "type", SubmessageTypeRef(options, field)); } + } else if (field->type() == FieldDescriptor::TYPE_BYTES) { + // For bytes fields we want to always return the B64 data. + printer->Print("msg.get$getter$()", + "getter", JSGetterName(options, field, BYTES_B64)); } else { - // Simple field (singular or repeated). - if ((!HasFieldPresence(field) && !field->is_repeated()) || - field->type() == FieldDescriptor::TYPE_BYTES) { - // Delegate to the generated get() method in order not to duplicate - // the proto3-field-default-value or byte-coercion logic here. - printer->Print("msg.get$getter$()", - "getter", JSGetterName(options, field, BYTES_B64)); - } else { - if (field->has_default_value()) { - printer->Print("!msg.has$name$() ? $defaultValue$ : ", - "name", JSGetterName(options, field), - "defaultValue", JSFieldDefault(field)); - } - if (field->cpp_type() == FieldDescriptor::CPPTYPE_FLOAT || - field->cpp_type() == FieldDescriptor::CPPTYPE_DOUBLE) { - if (field->is_repeated()) { - printer->Print("jspb.Message.getRepeatedFloatingPointField(" - "msg, $index$)", - "index", JSFieldIndex(field)); - } else if (field->is_optional() && !field->has_default_value()) { - printer->Print("jspb.Message.getOptionalFloatingPointField(" - "msg, $index$)", - "index", JSFieldIndex(field)); - } else { - // Convert "NaN" to NaN. - printer->Print("+jspb.Message.getField(msg, $index$)", - "index", JSFieldIndex(field)); - } - } else { - printer->Print("jspb.Message.getField(msg, $index$)", - "index", JSFieldIndex(field)); - } + bool use_default = field->has_default_value(); + + if (field->file()->syntax() == FileDescriptor::SYNTAX_PROTO3 && + // Repeated fields get initialized to their default in the constructor + // (why?), so we emit a plain getField() call for them. + !field->is_repeated() && !UseBrokenPresenceSemantics(options, field)) { + // Proto3 puts all defaults (including implicit defaults) in toObject(). + // But for proto2 we leave the existing semantics unchanged: unset fields + // without default are unset. + use_default = true; } + + // We don't implement this by calling the accessors, because the semantics + // of the accessors are changing independently of the toObject() semantics. + // We are migrating the accessors to return defaults instead of null, but + // it may take longer to migrate toObject (or we might not want to do it at + // all). So we want to generate independent code. + GenerateFieldValueExpression(printer, "msg", field, use_default); } } @@ -2091,8 +2214,7 @@ void Generator::GenerateClassFieldFromObject( const GeneratorOptions& options, io::Printer* printer, const FieldDescriptor* field) const { - - if (field->is_map()) { + if (IsMap(options, field)) { // `msg` is a newly-constructed message object that has not yet built any // map containers wrapping underlying arrays, so we can simply directly set // the array here without fear of a stale wrapper. @@ -2133,21 +2255,6 @@ void Generator::GenerateClassFieldFromObject( } } -void Generator::GenerateClassClone(const GeneratorOptions& options, - io::Printer* printer, - const Descriptor* desc) const { - printer->Print( - "/**\n" - " * Creates a deep clone of this proto. No data is shared with the " - "original.\n" - " * @return {!$name$} The clone.\n" - " */\n" - "$name$.prototype.cloneMessage = function() {\n" - " return /** @type {!$name$} */ (jspb.Message.cloneMessage(this));\n" - "};\n\n\n", - "name", GetPath(options, desc)); -} - void Generator::GenerateClassRegistration(const GeneratorOptions& options, io::Printer* printer, const Descriptor* desc) const { @@ -2175,12 +2282,11 @@ void GenerateBytesWrapper(const GeneratorOptions& options, io::Printer* printer, const FieldDescriptor* field, BytesMode bytes_mode) { - string type = - JSFieldTypeAnnotation(options, field, - /* force_optional = */ false, - /* force_present = */ !HasFieldPresence(field), - /* singular_if_not_packed = */ false, - bytes_mode); + string type = JSFieldTypeAnnotation( + options, field, + /* is_setter_argument = */ false, + /* force_present = */ false, + /* singular_if_not_packed = */ false, bytes_mode); printer->Print( "/**\n" " * $fielddef$\n" @@ -2208,20 +2314,20 @@ void GenerateBytesWrapper(const GeneratorOptions& options, void Generator::GenerateClassField(const GeneratorOptions& options, io::Printer* printer, const FieldDescriptor* field) const { - if (field->is_map()) { + if (IsMap(options, field)) { const FieldDescriptor* key_field = MapFieldKey(field); const FieldDescriptor* value_field = MapFieldValue(field); // Map field: special handling to instantiate the map object on demand. string key_type = JSFieldTypeAnnotation( options, key_field, - /* force_optional = */ false, + /* is_setter_argument = */ false, /* force_present = */ true, /* singular_if_not_packed = */ false); string value_type = JSFieldTypeAnnotation( options, value_field, - /* force_optional = */ false, + /* is_setter_argument = */ false, /* force_present = */ true, /* singular_if_not_packed = */ false); @@ -2275,7 +2381,7 @@ void Generator::GenerateClassField(const GeneratorOptions& options, "fielddef", FieldDefinition(options, field), "comment", FieldComments(field, BYTES_DEFAULT), "type", JSFieldTypeAnnotation(options, field, - /* force_optional = */ false, + /* is_setter_argument = */ false, /* force_present = */ false, /* singular_if_not_packed = */ false)); printer->Print( @@ -2289,7 +2395,7 @@ void Generator::GenerateClassField(const GeneratorOptions& options, "class", GetPath(options, field->containing_type()), "name", JSGetterName(options, field), "type", JSFieldTypeAnnotation(options, field, - /* force_optional = */ false, + /* is_setter_argument = */ false, /* force_present = */ false, /* singular_if_not_packed = */ false), "rpt", (field->is_repeated() ? "Repeated" : ""), @@ -2298,12 +2404,12 @@ void Generator::GenerateClassField(const GeneratorOptions& options, "required", (field->label() == FieldDescriptor::LABEL_REQUIRED ? ", 1" : "")); printer->Print( - "/** @param {$optionaltype$} value $returndoc$ */\n" + "/** @param {$optionaltype$} value$returndoc$ */\n" "$class$.prototype.set$name$ = function(value) {\n" " jspb.Message.set$oneoftag$$repeatedtag$WrapperField(", "optionaltype", JSFieldTypeAnnotation(options, field, - /* force_optional = */ true, + /* is_setter_argument = */ true, /* force_present = */ false, /* singular_if_not_packed = */ false), "returndoc", JSReturnDoc(options, field), @@ -2322,16 +2428,9 @@ void Generator::GenerateClassField(const GeneratorOptions& options, (", " + JSOneofArray(options, field)) : ""), "returnvalue", JSReturnClause(field)); - printer->Print( - "$class$.prototype.clear$name$ = function() {\n" - " this.set$name$($clearedvalue$);$returnvalue$\n" - "};\n" - "\n" - "\n", - "class", GetPath(options, field->containing_type()), - "name", JSGetterName(options, field), - "clearedvalue", (field->is_repeated() ? "[]" : "undefined"), - "returnvalue", JSReturnClause(field)); + if (field->is_repeated()) { + GenerateRepeatedMessageHelperMethods(options, printer, field); + } } else { bool untyped = @@ -2345,12 +2444,12 @@ void Generator::GenerateClassField(const GeneratorOptions& options, BytesMode bytes_mode = field->type() == FieldDescriptor::TYPE_BYTES && !options.binary ? BYTES_B64 : BYTES_DEFAULT; - string typed_annotation = - JSFieldTypeAnnotation(options, field, - /* force_optional = */ false, - /* force_present = */ !HasFieldPresence(field), - /* singular_if_not_packed = */ false, - /* bytes_mode = */ bytes_mode); + string typed_annotation = JSFieldTypeAnnotation( + options, field, + /* is_setter_argument = */ false, + /* force_present = */ false, + /* singular_if_not_packed = */ false, + /* bytes_mode = */ bytes_mode); if (untyped) { printer->Print( "/**\n" @@ -2382,36 +2481,21 @@ void Generator::GenerateClassField(const GeneratorOptions& options, "type", typed_annotation); } - // For proto3 fields without presence, use special getters that will return - // defaults when the field is unset, possibly constructing a value if - // required. - if (!HasFieldPresence(field) && !field->is_repeated()) { - printer->Print("jspb.Message.getFieldProto3(this, $index$, $default$)", - "index", JSFieldIndex(field), - "default", Proto3PrimitiveFieldDefault(field)); - } else { - if (!field->is_repeated()) { - printer->Print("!this.has$name$() ? $defaultValue$ : ", - "name", JSGetterName(options, field), - "defaultValue", JSFieldDefault(field)); - } - if (field->cpp_type() == FieldDescriptor::CPPTYPE_FLOAT || - field->cpp_type() == FieldDescriptor::CPPTYPE_DOUBLE) { - if (field->is_repeated()) { - printer->Print("jspb.Message.getRepeatedFloatingPointField(" - "this, $index$)", - "index", JSFieldIndex(field)); - } else { - // Convert "NaN" to NaN. - printer->Print("+jspb.Message.getField(this, $index$)", - "index", JSFieldIndex(field)); - } - } else { - printer->Print("jspb.Message.getField(this, $index$)", - "index", JSFieldIndex(field)); - } + bool use_default = !ReturnsNullWhenUnset(options, field); + + // Raw fields with no default set should just return undefined. + if (untyped && !field->has_default_value()) { + use_default = false; + } + + // Repeated fields get initialized to their default in the constructor + // (why?), so we emit a plain getField() call for them. + if (field->is_repeated()) { + use_default = false; } + GenerateFieldValueExpression(printer, "this", field, use_default); + if (untyped) { printer->Print( ";\n" @@ -2434,17 +2518,17 @@ void Generator::GenerateClassField(const GeneratorOptions& options, if (untyped) { printer->Print( "/**\n" - " * @param {*} value $returndoc$\n" + " * @param {*} value$returndoc$\n" " */\n", "returndoc", JSReturnDoc(options, field)); } else { printer->Print( - "/** @param {$optionaltype$} value $returndoc$ */\n", - "optionaltype", - JSFieldTypeAnnotation(options, field, - /* force_optional = */ true, - /* force_present = */ !HasFieldPresence(field), - /* singular_if_not_packed = */ false), + "/** @param {$optionaltype$} value$returndoc$ */\n", "optionaltype", + JSFieldTypeAnnotation( + options, field, + /* is_setter_argument = */ true, + /* force_present = */ false, + /* singular_if_not_packed = */ false), "returndoc", JSReturnDoc(options, field)); } printer->Print( @@ -2471,36 +2555,70 @@ void Generator::GenerateClassField(const GeneratorOptions& options, if (untyped) { printer->Print( "/**\n" - " * Clears the value. $returndoc$\n" + " * Clears the value.$returndoc$\n" " */\n", "returndoc", JSReturnDoc(options, field)); } - if (HasFieldPresence(field) || field->is_repeated()) { - printer->Print( - "$class$.prototype.clear$name$ = function() {\n" - " jspb.Message.set$oneoftag$Field(this, $index$$oneofgroup$, ", - "class", GetPath(options, field->containing_type()), - "name", JSGetterName(options, field), - "oneoftag", (field->containing_oneof() ? "Oneof" : ""), - "oneofgroup", (field->containing_oneof() ? - (", " + JSOneofArray(options, field)) : ""), - "index", JSFieldIndex(field)); - printer->Print( - "$clearedvalue$);$returnvalue$\n" - "};\n" - "\n" - "\n", - "clearedvalue", (field->is_repeated() ? "[]" : "undefined"), - "returnvalue", JSReturnClause(field)); + + if (field->is_repeated()) { + GenerateRepeatedPrimitiveHelperMethods(options, printer, field, untyped); } } - if (HasFieldPresence(field)) { + // Generate clearFoo() method for map fields, repeated fields, and other + // fields with presence. + if (IsMap(options, field)) { + printer->Print( + "$class$.prototype.clear$name$ = function() {\n" + " this.get$name$().clear();$returnvalue$\n" + "};\n" + "\n" + "\n", + "class", GetPath(options, field->containing_type()), + "name", JSGetterName(options, field), + "returnvalue", JSReturnClause(field)); + } else if (field->is_repeated() || + (field->cpp_type() == FieldDescriptor::CPPTYPE_MESSAGE && + !field->is_required())) { + // Fields where we can delegate to the regular setter. + printer->Print( + "$class$.prototype.clear$name$ = function() {\n" + " this.set$name$($clearedvalue$);$returnvalue$\n" + "};\n" + "\n" + "\n", + "class", GetPath(options, field->containing_type()), + "name", JSGetterName(options, field), + "clearedvalue", (field->is_repeated() ? "[]" : "undefined"), + "returnvalue", JSReturnClause(field)); + } else if (HasFieldPresence(options, field)) { + // Fields where we can't delegate to the regular setter because it doesn't + // accept "undefined" as an argument. + printer->Print( + "$class$.prototype.clear$name$ = function() {\n" + " jspb.Message.set$maybeoneof$Field(this, " + "$index$$maybeoneofgroup$, ", + "class", GetPath(options, field->containing_type()), + "name", JSGetterName(options, field), + "maybeoneof", (field->containing_oneof() ? "Oneof" : ""), + "maybeoneofgroup", (field->containing_oneof() ? + (", " + JSOneofArray(options, field)) : ""), + "index", JSFieldIndex(field)); + printer->Print( + "$clearedvalue$);$returnvalue$\n" + "};\n" + "\n" + "\n", + "clearedvalue", (field->is_repeated() ? "[]" : "undefined"), + "returnvalue", JSReturnClause(field)); + } + + if (HasFieldPresence(options, field)) { printer->Print( "/**\n" " * Returns whether this field is set.\n" - " * @return{!boolean}\n" + " * @return {!boolean}\n" " */\n" "$class$.prototype.has$name$ = function() {\n" " return jspb.Message.getField(this, $index$) != null;\n" @@ -2513,6 +2631,59 @@ void Generator::GenerateClassField(const GeneratorOptions& options, } } +void Generator::GenerateRepeatedPrimitiveHelperMethods( + const GeneratorOptions& options, io::Printer* printer, + const FieldDescriptor* field, bool untyped) const { + printer->Print( + "/**\n" + " * @param {!$optionaltype$} value\n" + " * @param {number=} opt_index\n" + " */\n" + "$class$.prototype.add$name$ = function(value, opt_index) {\n" + " jspb.Message.addToRepeatedField(this, $index$", + "class", GetPath(options, field->containing_type()), "name", + JSGetterName(options, field, BYTES_DEFAULT, + /* drop_list = */ true), + "optionaltype", JSTypeName(options, field, BYTES_DEFAULT), "index", + JSFieldIndex(field)); + printer->Print( + "$oneofgroup$, $type$value$rptvalueinit$$typeclose$, opt_index);\n" + "};\n" + "\n" + "\n", + "type", untyped ? "/** @type{string|number|boolean|!Uint8Array} */(" : "", + "typeclose", untyped ? ")" : "", "oneofgroup", + (field->containing_oneof() ? (", " + JSOneofArray(options, field)) : ""), + "rptvalueinit", ""); +} + +void Generator::GenerateRepeatedMessageHelperMethods( + const GeneratorOptions& options, io::Printer* printer, + const FieldDescriptor* field) const { + printer->Print( + "/**\n" + " * @param {!$optionaltype$=} opt_value\n" + " * @param {number=} opt_index\n" + " * @return {!$optionaltype$}\n" + " */\n" + "$class$.prototype.add$name$ = function(opt_value, opt_index) {\n" + " return jspb.Message.addTo$repeatedtag$WrapperField(", + "optionaltype", JSTypeName(options, field, BYTES_DEFAULT), "class", + GetPath(options, field->containing_type()), "name", + JSGetterName(options, field, BYTES_DEFAULT, + /* drop_list = */ true), + "repeatedtag", (field->is_repeated() ? "Repeated" : "")); + + printer->Print( + "this, $index$$oneofgroup$, opt_value, $ctor$, opt_index);\n" + "};\n" + "\n" + "\n", + "index", JSFieldIndex(field), "oneofgroup", + (field->containing_oneof() ? (", " + JSOneofArray(options, field)) : ""), + "ctor", GetPath(options, field->message_type())); +} + void Generator::GenerateClassExtensionFieldInfo(const GeneratorOptions& options, io::Printer* printer, const Descriptor* desc) const { @@ -2554,7 +2725,7 @@ void Generator::GenerateClassExtensionFieldInfo(const GeneratorOptions& options, "so that it\n" " * works in OPTIMIZED mode.\n" " *\n" - " * @type {!Object.}\n" + " * @type {!Object.}\n" " */\n" "$class$.extensionsBinary = {};\n" "\n", @@ -2636,7 +2807,7 @@ void Generator::GenerateClassDeserializeBinaryField( printer->Print(" case $num$:\n", "num", SimpleItoa(field->number())); - if (field->is_map()) { + if (IsMap(options, field)) { const FieldDescriptor* key_field = MapFieldKey(field); const FieldDescriptor* value_field = MapFieldValue(field); printer->Print( @@ -2757,11 +2928,18 @@ void Generator::GenerateClassSerializeBinaryField( const GeneratorOptions& options, io::Printer* printer, const FieldDescriptor* field) const { - if (HasFieldPresence(field) && + if (HasFieldPresence(options, field) && field->cpp_type() != FieldDescriptor::CPPTYPE_MESSAGE) { + string typed_annotation = JSFieldTypeAnnotation( + options, field, + /* is_setter_argument = */ false, + /* force_present = */ false, + /* singular_if_not_packed = */ false, + /* bytes_mode = */ BYTES_DEFAULT); printer->Print( - " f = jspb.Message.getField(this, $index$);\n", - "index", JSFieldIndex(field)); + " f = /** @type {$type$} */ (jspb.Message.getField(this, $index$));\n", + "index", JSFieldIndex(field), + "type", typed_annotation); } else { printer->Print( " f = this.get$name$($nolazy$);\n", @@ -2770,17 +2948,16 @@ void Generator::GenerateClassSerializeBinaryField( "nolazy", (field->is_map()) ? "true" : ""); } - // Print an `if (condition)` statement that evaluates to true if the field // goes on the wire. - if (field->is_map()) { + if (IsMap(options, field)) { printer->Print( " if (f && f.getLength() > 0) {\n"); } else if (field->is_repeated()) { printer->Print( " if (f.length > 0) {\n"); } else { - if (HasFieldPresence(field)) { + if (HasFieldPresence(options, field)) { printer->Print( " if (f != null) {\n"); } else { @@ -2820,7 +2997,7 @@ void Generator::GenerateClassSerializeBinaryField( } // Write the field on the wire. - if (field->is_map()) { + if (IsMap(options, field)) { const FieldDescriptor* key_field = MapFieldKey(field); const FieldDescriptor* value_field = MapFieldValue(field); printer->Print( @@ -2845,7 +3022,7 @@ void Generator::GenerateClassSerializeBinaryField( "index", SimpleItoa(field->number())); if (field->cpp_type() == FieldDescriptor::CPPTYPE_MESSAGE && - !(field->is_map())) { + !IsMap(options, field)) { printer->Print( ",\n" " $submsg$.serializeBinaryToWriter\n", @@ -2907,7 +3084,7 @@ void Generator::GenerateExtension(const GeneratorOptions& options, "class", extension_scope, "extensionType", JSFieldTypeAnnotation( options, field, - /* force_optional = */ false, + /* is_setter_argument = */ false, /* force_present = */ true, /* singular_if_not_packed = */ false)); printer->Print( @@ -2946,11 +3123,11 @@ void Generator::GenerateExtension(const GeneratorOptions& options, "binaryMessageSerializeFn", (field->cpp_type() == FieldDescriptor::CPPTYPE_MESSAGE) ? (SubmessageTypeRef(options, field) + - ".serializeBinaryToWriter") : "null", + ".serializeBinaryToWriter") : "undefined", "binaryMessageDeserializeFn", (field->cpp_type() == FieldDescriptor::CPPTYPE_MESSAGE) ? (SubmessageTypeRef(options, field) + - ".deserializeBinaryFromReader") : "null"); + ".deserializeBinaryFromReader") : "undefined"); printer->Print( " $isPacked$);\n", @@ -3005,17 +3182,31 @@ bool GeneratorOptions::ParseFromOptions( library = options[i].second; } else if (options[i].first == "import_style") { if (options[i].second == "closure") { - import_style = IMPORT_CLOSURE; + import_style = kImportClosure; } else if (options[i].second == "commonjs") { - import_style = IMPORT_COMMONJS; + import_style = kImportCommonJs; } else if (options[i].second == "browser") { - import_style = IMPORT_BROWSER; + import_style = kImportBrowser; } else if (options[i].second == "es6") { - import_style = IMPORT_ES6; + import_style = kImportEs6; } else { *error = "Unknown import style " + options[i].second + ", expected " + "one of: closure, commonjs, browser, es6."; } + } else if (options[i].first == "extension") { + extension = options[i].second; + } else if (options[i].first == "one_output_file_per_input_file") { + if (!options[i].second.empty()) { + *error = "Unexpected option value for one_output_file_per_input_file"; + return false; + } + one_output_file_per_input_file = true; + } else if (options[i].first == "broken_proto3_semantics") { + if (!options[i].second.empty()) { + *error = "Unexpected option value for broken_proto3_semantics"; + return false; + } + broken_proto3_semantics = true; } else { // Assume any other option is an output directory, as long as it is a bare // `key` rather than a `key=value` option. @@ -3027,14 +3218,37 @@ bool GeneratorOptions::ParseFromOptions( } } - if (!library.empty() && import_style != IMPORT_CLOSURE) { - *error = "The library option should only be used for " - "import_style=closure"; + if (import_style != kImportClosure && + (add_require_for_enums || testonly || !library.empty() || + error_on_name_conflict || broken_proto3_semantics || + extension != ".js" || one_output_file_per_input_file)) { + *error = + "The add_require_for_enums, testonly, library, error_on_name_conflict, " + "broken_proto3_semantics, extension, and " + "one_output_file_per_input_file options should only be used for " + "import_style=closure"; + return false; } return true; } +GeneratorOptions::OutputMode GeneratorOptions::output_mode() const { + // We use one output file per input file if we are not using Closure or if + // this is explicitly requested. + if (import_style != kImportClosure || one_output_file_per_input_file) { + return kOneOutputFilePerInputFile; + } + + // If a library name is provided, we put everything in that one file. + if (!library.empty()) { + return kEverythingInOneFile; + } + + // Otherwise, we create one output file per type. + return kOneOutputFilePerType; +} + void Generator::GenerateFilesInDepOrder( const GeneratorOptions& options, io::Printer* printer, @@ -3081,7 +3295,7 @@ void Generator::GenerateFile(const GeneratorOptions& options, GenerateHeader(options, printer); // Generate "require" statements. - if (options.import_style == GeneratorOptions::IMPORT_COMMONJS) { + if (options.import_style == GeneratorOptions::kImportCommonJs) { printer->Print("var jspb = require('google-protobuf');\n"); printer->Print("var goog = jspb;\n"); printer->Print("var global = Function('return this')();\n\n"); @@ -3091,42 +3305,43 @@ void Generator::GenerateFile(const GeneratorOptions& options, printer->Print( "var $alias$ = require('$file$');\n", "alias", ModuleAlias(name), - "file", GetRootPath(file->name(), name) + GetJSFilename(name)); + "file", GetRootPath(file->name(), name) + GetJSFilename(options, name)); } } - // We aren't using Closure's import system, but we use goog.exportSymbol() - // to construct the expected tree of objects, eg. - // - // goog.exportSymbol('foo.bar.Baz', null, this); - // - // // Later generated code expects foo.bar = {} to exist: - // foo.bar.Baz = function() { /* ... */ } set provided; - - // Cover the case where this file declares extensions but no messages. - // This will ensure that the file-level object will be declared to hold - // the extensions. + set extensions; for (int i = 0; i < file->extension_count(); i++) { - provided.insert(file->extension(i)->full_name()); + // We honor the jspb::ignore option here only when working with + // Closure-style imports. Use of this option is discouraged and so we want + // to avoid adding new support for it. + if (options.import_style == GeneratorOptions::kImportClosure && + IgnoreField(file->extension(i))) { + continue; + } + provided.insert(GetPath(options, file) + "." + + JSObjectFieldName(options, file->extension(i))); + extensions.insert(file->extension(i)); } FindProvidesForFile(options, printer, file, &provided); - for (std::set::iterator it = provided.begin(); - it != provided.end(); ++it) { - printer->Print("goog.exportSymbol('$name$', null, global);\n", - "name", *it); + GenerateProvides(options, printer, &provided); + vector files; + files.push_back(file); + if (options.import_style == GeneratorOptions::kImportClosure) { + GenerateRequiresForLibrary(options, printer, files, &provided); } GenerateClassesAndEnums(options, printer, file); - // Extensions nested inside messages are emitted inside - // GenerateClassesAndEnums(). - for (int i = 0; i < file->extension_count(); i++) { - GenerateExtension(options, printer, file->extension(i)); + // Generate code for top-level extensions. Extensions nested inside messages + // are emitted inside GenerateClassesAndEnums(). + for (set::const_iterator it = extensions.begin(); + it != extensions.end(); ++it) { + GenerateExtension(options, printer, *it); } - if (options.import_style == GeneratorOptions::IMPORT_COMMONJS) { + if (options.import_style == GeneratorOptions::kImportCommonJs) { printer->Print("goog.object.extend(exports, $package$);\n", "package", GetPath(options, file)); } @@ -3144,15 +3359,10 @@ bool Generator::GenerateAll(const vector& files, } - // There are three schemes for where output files go: - // - // - import_style = IMPORT_CLOSURE, library non-empty: all output in one file - // - import_style = IMPORT_CLOSURE, library empty: one output file per type - // - import_style != IMPORT_CLOSURE: one output file per .proto file - if (options.import_style == GeneratorOptions::IMPORT_CLOSURE && - options.library != "") { + if (options.output_mode() == GeneratorOptions::kEverythingInOneFile) { // All output should go in a single file. - string filename = options.output_dir + "/" + options.library + ".js"; + string filename = options.output_dir + "/" + options.library + + options.GetFileNameExtension(); google::protobuf::scoped_ptr output(context->Open(filename)); GOOGLE_CHECK(output.get()); io::Printer printer(output.get(), '$'); @@ -3187,7 +3397,7 @@ bool Generator::GenerateAll(const vector& files, if (printer.failed()) { return false; } - } else if (options.import_style == GeneratorOptions::IMPORT_CLOSURE) { + } else if (options.output_mode() == GeneratorOptions::kOneOutputFilePerType) { set allowed_set; if (!GenerateJspbAllowedSet(options, files, &allowed_set, error)) { return false; @@ -3279,13 +3489,14 @@ bool Generator::GenerateAll(const vector& files, } } } - } else { + } else /* options.output_mode() == kOneOutputFilePerInputFile */ { // Generate one output file per input (.proto) file. for (int i = 0; i < files.size(); i++) { const google::protobuf::FileDescriptor* file = files[i]; - string filename = options.output_dir + "/" + GetJSFilename(file->name()); + string filename = + options.output_dir + "/" + GetJSFilename(options, file->name()); google::protobuf::scoped_ptr output(context->Open(filename)); GOOGLE_CHECK(output.get()); io::Printer printer(output.get(), '$'); diff --git a/src/google/protobuf/compiler/js/js_generator.h b/src/google/protobuf/compiler/js/js_generator.h index 056c9897..4ca3493c 100755 --- a/src/google/protobuf/compiler/js/js_generator.h +++ b/src/google/protobuf/compiler/js/js_generator.h @@ -36,6 +36,8 @@ #include #include +#include +#include #include namespace google { @@ -53,43 +55,74 @@ namespace compiler { namespace js { struct GeneratorOptions { - // Add a `goog.requires()` call for each enum type used. If not set, a forward - // declaration with `goog.forwardDeclare` is produced instead. - bool add_require_for_enums; - // Set this as a test-only module via `goog.setTestOnly();`. - bool testonly; // Output path. string output_dir; // Namespace prefix. string namespace_prefix; - // Create a library with name _lib.js rather than a separate .js file - // per type? - string library; - // Error if there are two types that would generate the same output file? - bool error_on_name_conflict; // Enable binary-format support? bool binary; // What style of imports should be used. enum ImportStyle { - IMPORT_CLOSURE, // goog.require() - IMPORT_COMMONJS, // require() - IMPORT_BROWSER, // no import statements - IMPORT_ES6, // import { member } from '' + kImportClosure, // goog.require() + kImportCommonJs, // require() + kImportBrowser, // no import statements + kImportEs6, // import { member } from '' } import_style; GeneratorOptions() - : add_require_for_enums(false), - testonly(false), - output_dir("."), + : output_dir("."), namespace_prefix(""), + binary(false), + import_style(kImportClosure), + add_require_for_enums(false), + testonly(false), library(""), error_on_name_conflict(false), - binary(false), - import_style(IMPORT_CLOSURE) {} + broken_proto3_semantics(false), + extension(".js"), + one_output_file_per_input_file(false) {} bool ParseFromOptions( const vector< pair< string, string > >& options, string* error); + + // Returns the file name extension to use for generated code. + string GetFileNameExtension() const { + return import_style == kImportClosure ? extension : "_pb.js"; + } + + enum OutputMode { + // Create an output file for each input .proto file. + kOneOutputFilePerInputFile, + // Create an output file for each type. + kOneOutputFilePerType, + // Put everything in a single file named by the library option. + kEverythingInOneFile, + }; + + // Indicates how to output the generated code based on the provided options. + OutputMode output_mode() const; + + // The remaining options are only relevant when we are using kImportClosure. + + // Add a `goog.requires()` call for each enum type used. If not set, a + // forward declaration with `goog.forwardDeclare` is produced instead. + bool add_require_for_enums; + // Set this as a test-only module via `goog.setTestOnly();`. + bool testonly; + // Create a library with name _lib.js rather than a separate .js file + // per type? + string library; + // Error if there are two types that would generate the same output file? + bool error_on_name_conflict; + // Preserve the broken proto3 semantics from the old codegen? This amounts + // to using proto2 field presence semantics even for proto3 files. DO NOT + // USE except for migrating legacy code. + bool broken_proto3_semantics; + // The extension to use for output file names. + string extension; + // Create a separate output file for each input file? + bool one_output_file_per_input_file; }; // CodeGenerator implementation which generates a JavaScript source file and @@ -207,6 +240,11 @@ class LIBPROTOC_EXPORT Generator : public CodeGenerator { io::Printer* printer, const FileDescriptor* file) const; + void GenerateFieldValueExpression(io::Printer* printer, + const char* obj_reference, + const FieldDescriptor* field, + bool use_default) const; + // Generate definition for one class. void GenerateClass(const GeneratorOptions& options, io::Printer* printer, @@ -276,6 +314,17 @@ class LIBPROTOC_EXPORT Generator : public CodeGenerator { io::Printer* printer, const FieldDescriptor* field) const; + // Generate addFoo() method for repeated primitive fields. + void GenerateRepeatedPrimitiveHelperMethods(const GeneratorOptions& options, + io::Printer* printer, + const FieldDescriptor* field, + bool untyped) const; + + // Generate addFoo() method for repeated message fields. + void GenerateRepeatedMessageHelperMethods(const GeneratorOptions& options, + io::Printer* printer, + const FieldDescriptor* field) const; + GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(Generator); }; diff --git a/src/google/protobuf/compiler/main.cc b/src/google/protobuf/compiler/main.cc index b83b8f32..aca2a5b9 100644 --- a/src/google/protobuf/compiler/main.cc +++ b/src/google/protobuf/compiler/main.cc @@ -32,14 +32,20 @@ #include #include + +#ifndef OPENSOURCE_PROTOBUF_CPP_BOOTSTRAP #include #include +#endif // ! OPENSOURCE_PROTOBUF_CPP_BOOTSTRAP + +#ifndef OPENSOURCE_PROTOBUF_CPP_BOOTSTRAP #include #include #include #include #include #include +#endif // ! OPENSOURCE_PROTOBUF_CPP_BOOTSTRAP int main(int argc, char* argv[]) { @@ -51,12 +57,15 @@ int main(int argc, char* argv[]) { cli.RegisterGenerator("--cpp_out", "--cpp_opt", &cpp_generator, "Generate C++ header and source."); +#ifndef OPENSOURCE_PROTOBUF_CPP_BOOTSTRAP // Proto2 Java google::protobuf::compiler::java::JavaGenerator java_generator; cli.RegisterGenerator("--java_out", &java_generator, "Generate Java source file."); +#endif // !OPENSOURCE_PROTOBUF_CPP_BOOTSTRAP +#ifndef OPENSOURCE_PROTOBUF_CPP_BOOTSTRAP // Proto2 Python google::protobuf::compiler::python::Generator py_generator; cli.RegisterGenerator("--python_out", &py_generator, @@ -91,6 +100,7 @@ int main(int argc, char* argv[]) { google::protobuf::compiler::js::Generator js_generator; cli.RegisterGenerator("--js_out", &js_generator, "Generate JavaScript source."); +#endif // !OPENSOURCE_PROTOBUF_CPP_BOOTSTRAP return cli.Run(argc, argv); } diff --git a/src/google/protobuf/compiler/plugin.cc b/src/google/protobuf/compiler/plugin.cc index 2ff50f61..e1087601 100644 --- a/src/google/protobuf/compiler/plugin.cc +++ b/src/google/protobuf/compiler/plugin.cc @@ -118,35 +118,16 @@ bool GenerateCode(const CodeGeneratorRequest& request, GeneratorResponseContext context(response, parsed_files); - if (generator.HasGenerateAll()) { - string error; - bool succeeded = generator.GenerateAll( - parsed_files, request.parameter(), &context, &error); - - if (!succeeded && error.empty()) { - error = "Code generator returned false but provided no error " - "description."; - } - if (!error.empty()) { - response->set_error(error); - } - } else { - for (int i = 0; i < parsed_files.size(); i++) { - const FileDescriptor* file = parsed_files[i]; - - string error; - bool succeeded = generator.Generate( - file, request.parameter(), &context, &error); - - if (!succeeded && error.empty()) { - error = "Code generator returned false but provided no error " - "description."; - } - if (!error.empty()) { - response->set_error(file->name() + ": " + error); - break; - } - } + string error; + bool succeeded = generator.GenerateAll( + parsed_files, request.parameter(), &context, &error); + + if (!succeeded && error.empty()) { + error = "Code generator returned false but provided no error " + "description."; + } + if (!error.empty()) { + response->set_error(error); } return true; diff --git a/src/google/protobuf/compiler/plugin.pb.cc b/src/google/protobuf/compiler/plugin.pb.cc index 5247f9a2..1c19d46a 100644 --- a/src/google/protobuf/compiler/plugin.pb.cc +++ b/src/google/protobuf/compiler/plugin.pb.cc @@ -52,14 +52,13 @@ void protobuf_AssignDesc_google_2fprotobuf_2fcompiler_2fplugin_2eproto() { CodeGeneratorRequest_reflection_ = ::google::protobuf::internal::GeneratedMessageReflection::NewGeneratedMessageReflection( CodeGeneratorRequest_descriptor_, - CodeGeneratorRequest::default_instance_, + CodeGeneratorRequest::internal_default_instance(), CodeGeneratorRequest_offsets_, - GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(CodeGeneratorRequest, _has_bits_[0]), + GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(CodeGeneratorRequest, _has_bits_), -1, -1, sizeof(CodeGeneratorRequest), - GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(CodeGeneratorRequest, _internal_metadata_), - -1); + GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(CodeGeneratorRequest, _internal_metadata_)); CodeGeneratorResponse_descriptor_ = file->message_type(1); static const int CodeGeneratorResponse_offsets_[2] = { GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(CodeGeneratorResponse, error_), @@ -68,14 +67,13 @@ void protobuf_AssignDesc_google_2fprotobuf_2fcompiler_2fplugin_2eproto() { CodeGeneratorResponse_reflection_ = ::google::protobuf::internal::GeneratedMessageReflection::NewGeneratedMessageReflection( CodeGeneratorResponse_descriptor_, - CodeGeneratorResponse::default_instance_, + CodeGeneratorResponse::internal_default_instance(), CodeGeneratorResponse_offsets_, - GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(CodeGeneratorResponse, _has_bits_[0]), + GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(CodeGeneratorResponse, _has_bits_), -1, -1, sizeof(CodeGeneratorResponse), - GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(CodeGeneratorResponse, _internal_metadata_), - -1); + GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(CodeGeneratorResponse, _internal_metadata_)); CodeGeneratorResponse_File_descriptor_ = CodeGeneratorResponse_descriptor_->nested_type(0); static const int CodeGeneratorResponse_File_offsets_[3] = { GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(CodeGeneratorResponse_File, name_), @@ -85,20 +83,19 @@ void protobuf_AssignDesc_google_2fprotobuf_2fcompiler_2fplugin_2eproto() { CodeGeneratorResponse_File_reflection_ = ::google::protobuf::internal::GeneratedMessageReflection::NewGeneratedMessageReflection( CodeGeneratorResponse_File_descriptor_, - CodeGeneratorResponse_File::default_instance_, + CodeGeneratorResponse_File::internal_default_instance(), CodeGeneratorResponse_File_offsets_, - GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(CodeGeneratorResponse_File, _has_bits_[0]), + GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(CodeGeneratorResponse_File, _has_bits_), -1, -1, sizeof(CodeGeneratorResponse_File), - GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(CodeGeneratorResponse_File, _internal_metadata_), - -1); + GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(CodeGeneratorResponse_File, _internal_metadata_)); } namespace { GOOGLE_PROTOBUF_DECLARE_ONCE(protobuf_AssignDescriptors_once_); -inline void protobuf_AssignDescriptorsOnce() { +void protobuf_AssignDescriptorsOnce() { ::google::protobuf::GoogleOnceInit(&protobuf_AssignDescriptors_once_, &protobuf_AssignDesc_google_2fprotobuf_2fcompiler_2fplugin_2eproto); } @@ -107,32 +104,45 @@ void protobuf_RegisterTypes(const ::std::string&) GOOGLE_ATTRIBUTE_COLD; void protobuf_RegisterTypes(const ::std::string&) { protobuf_AssignDescriptorsOnce(); ::google::protobuf::MessageFactory::InternalRegisterGeneratedMessage( - CodeGeneratorRequest_descriptor_, &CodeGeneratorRequest::default_instance()); + CodeGeneratorRequest_descriptor_, CodeGeneratorRequest::internal_default_instance()); ::google::protobuf::MessageFactory::InternalRegisterGeneratedMessage( - CodeGeneratorResponse_descriptor_, &CodeGeneratorResponse::default_instance()); + CodeGeneratorResponse_descriptor_, CodeGeneratorResponse::internal_default_instance()); ::google::protobuf::MessageFactory::InternalRegisterGeneratedMessage( - CodeGeneratorResponse_File_descriptor_, &CodeGeneratorResponse_File::default_instance()); + CodeGeneratorResponse_File_descriptor_, CodeGeneratorResponse_File::internal_default_instance()); } } // namespace void protobuf_ShutdownFile_google_2fprotobuf_2fcompiler_2fplugin_2eproto() { - delete CodeGeneratorRequest::default_instance_; delete CodeGeneratorRequest_reflection_; - delete CodeGeneratorResponse::default_instance_; delete CodeGeneratorResponse_reflection_; - delete CodeGeneratorResponse_File::default_instance_; delete CodeGeneratorResponse_File_reflection_; } -void protobuf_AddDesc_google_2fprotobuf_2fcompiler_2fplugin_2eproto() GOOGLE_ATTRIBUTE_COLD; -void protobuf_AddDesc_google_2fprotobuf_2fcompiler_2fplugin_2eproto() { - static bool already_here = false; - if (already_here) return; - already_here = true; +void protobuf_InitDefaults_google_2fprotobuf_2fcompiler_2fplugin_2eproto_impl() { GOOGLE_PROTOBUF_VERIFY_VERSION; - ::google::protobuf::protobuf_AddDesc_google_2fprotobuf_2fdescriptor_2eproto(); + ::google::protobuf::protobuf_InitDefaults_google_2fprotobuf_2fdescriptor_2eproto(); + ::google::protobuf::internal::GetEmptyString(); + CodeGeneratorRequest::default_instance_.DefaultConstruct(); + ::google::protobuf::internal::GetEmptyString(); + CodeGeneratorResponse::default_instance_.DefaultConstruct(); + ::google::protobuf::internal::GetEmptyString(); + CodeGeneratorResponse_File::default_instance_.DefaultConstruct(); + CodeGeneratorRequest::default_instance_.get_mutable()->InitAsDefaultInstance(); + CodeGeneratorResponse::default_instance_.get_mutable()->InitAsDefaultInstance(); + CodeGeneratorResponse_File::default_instance_.get_mutable()->InitAsDefaultInstance(); +} + +GOOGLE_PROTOBUF_DECLARE_ONCE(protobuf_InitDefaults_google_2fprotobuf_2fcompiler_2fplugin_2eproto_once_); +void protobuf_InitDefaults_google_2fprotobuf_2fcompiler_2fplugin_2eproto() { + ::google::protobuf::GoogleOnceInit(&protobuf_InitDefaults_google_2fprotobuf_2fcompiler_2fplugin_2eproto_once_, + &protobuf_InitDefaults_google_2fprotobuf_2fcompiler_2fplugin_2eproto_impl); +} +void protobuf_AddDesc_google_2fprotobuf_2fcompiler_2fplugin_2eproto_impl() { + GOOGLE_PROTOBUF_VERIFY_VERSION; + + protobuf_InitDefaults_google_2fprotobuf_2fcompiler_2fplugin_2eproto(); ::google::protobuf::DescriptorPool::InternalAddGeneratedFile( "\n%google/protobuf/compiler/plugin.proto\022" "\030google.protobuf.compiler\032 google/protob" @@ -148,15 +158,15 @@ void protobuf_AddDesc_google_2fprotobuf_2fcompiler_2fplugin_2eproto() { "rotosZ\tplugin_go", 456); ::google::protobuf::MessageFactory::InternalRegisterGeneratedFile( "google/protobuf/compiler/plugin.proto", &protobuf_RegisterTypes); - CodeGeneratorRequest::default_instance_ = new CodeGeneratorRequest(); - CodeGeneratorResponse::default_instance_ = new CodeGeneratorResponse(); - CodeGeneratorResponse_File::default_instance_ = new CodeGeneratorResponse_File(); - CodeGeneratorRequest::default_instance_->InitAsDefaultInstance(); - CodeGeneratorResponse::default_instance_->InitAsDefaultInstance(); - CodeGeneratorResponse_File::default_instance_->InitAsDefaultInstance(); + ::google::protobuf::protobuf_AddDesc_google_2fprotobuf_2fdescriptor_2eproto(); ::google::protobuf::internal::OnShutdown(&protobuf_ShutdownFile_google_2fprotobuf_2fcompiler_2fplugin_2eproto); } +GOOGLE_PROTOBUF_DECLARE_ONCE(protobuf_AddDesc_google_2fprotobuf_2fcompiler_2fplugin_2eproto_once_); +void protobuf_AddDesc_google_2fprotobuf_2fcompiler_2fplugin_2eproto() { + ::google::protobuf::GoogleOnceInit(&protobuf_AddDesc_google_2fprotobuf_2fcompiler_2fplugin_2eproto_once_, + &protobuf_AddDesc_google_2fprotobuf_2fcompiler_2fplugin_2eproto_impl); +} // Force AddDescriptors() to be called at static initialization time. struct StaticDescriptorInitializer_google_2fprotobuf_2fcompiler_2fplugin_2eproto { StaticDescriptorInitializer_google_2fprotobuf_2fcompiler_2fplugin_2eproto() { @@ -164,6 +174,16 @@ struct StaticDescriptorInitializer_google_2fprotobuf_2fcompiler_2fplugin_2eproto } } static_descriptor_initializer_google_2fprotobuf_2fcompiler_2fplugin_2eproto_; +namespace { + +static void MergeFromFail(int line) GOOGLE_ATTRIBUTE_COLD GOOGLE_ATTRIBUTE_NORETURN; +static void MergeFromFail(int line) { + ::google::protobuf::internal::MergeFromFail(__FILE__, line); +} + +} // namespace + + // =================================================================== #if !defined(_MSC_VER) || _MSC_VER >= 1900 @@ -174,6 +194,7 @@ const int CodeGeneratorRequest::kProtoFileFieldNumber; CodeGeneratorRequest::CodeGeneratorRequest() : ::google::protobuf::Message(), _internal_metadata_(NULL) { + if (this != internal_default_instance()) protobuf_InitDefaults_google_2fprotobuf_2fcompiler_2fplugin_2eproto(); SharedCtor(); // @@protoc_insertion_point(constructor:google.protobuf.compiler.CodeGeneratorRequest) } @@ -185,15 +206,13 @@ CodeGeneratorRequest::CodeGeneratorRequest(const CodeGeneratorRequest& from) : ::google::protobuf::Message(), _internal_metadata_(NULL) { SharedCtor(); - MergeFrom(from); + UnsafeMergeFrom(from); // @@protoc_insertion_point(copy_constructor:google.protobuf.compiler.CodeGeneratorRequest) } void CodeGeneratorRequest::SharedCtor() { - ::google::protobuf::internal::GetEmptyString(); _cached_size_ = 0; parameter_.UnsafeSetDefault(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); - ::memset(_has_bits_, 0, sizeof(_has_bits_)); } CodeGeneratorRequest::~CodeGeneratorRequest() { @@ -203,8 +222,6 @@ CodeGeneratorRequest::~CodeGeneratorRequest() { void CodeGeneratorRequest::SharedDtor() { parameter_.DestroyNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); - if (this != default_instance_) { - } } void CodeGeneratorRequest::SetCachedSize(int size) const { @@ -218,11 +235,11 @@ const ::google::protobuf::Descriptor* CodeGeneratorRequest::descriptor() { } const CodeGeneratorRequest& CodeGeneratorRequest::default_instance() { - if (default_instance_ == NULL) protobuf_AddDesc_google_2fprotobuf_2fcompiler_2fplugin_2eproto(); - return *default_instance_; + protobuf_InitDefaults_google_2fprotobuf_2fcompiler_2fplugin_2eproto(); + return *internal_default_instance(); } -CodeGeneratorRequest* CodeGeneratorRequest::default_instance_ = NULL; +::google::protobuf::internal::ExplicitlyConstructed CodeGeneratorRequest::default_instance_; CodeGeneratorRequest* CodeGeneratorRequest::New(::google::protobuf::Arena* arena) const { CodeGeneratorRequest* n = new CodeGeneratorRequest; @@ -239,7 +256,7 @@ void CodeGeneratorRequest::Clear() { } file_to_generate_.Clear(); proto_file_.Clear(); - ::memset(_has_bits_, 0, sizeof(_has_bits_)); + _has_bits_.Clear(); if (_internal_metadata_.have_unknown_fields()) { mutable_unknown_fields()->Clear(); } @@ -406,9 +423,9 @@ void CodeGeneratorRequest::SerializeWithCachedSizes( return target; } -int CodeGeneratorRequest::ByteSize() const { +size_t CodeGeneratorRequest::ByteSizeLong() const { // @@protoc_insertion_point(message_byte_size_start:google.protobuf.compiler.CodeGeneratorRequest) - int total_size = 0; + size_t total_size = 0; // optional string parameter = 2; if (has_parameter()) { @@ -418,18 +435,22 @@ int CodeGeneratorRequest::ByteSize() const { } // repeated string file_to_generate = 1; - total_size += 1 * this->file_to_generate_size(); + total_size += 1 * + ::google::protobuf::internal::FromIntSize(this->file_to_generate_size()); for (int i = 0; i < this->file_to_generate_size(); i++) { total_size += ::google::protobuf::internal::WireFormatLite::StringSize( this->file_to_generate(i)); } // repeated .google.protobuf.FileDescriptorProto proto_file = 15; - total_size += 1 * this->proto_file_size(); - for (int i = 0; i < this->proto_file_size(); i++) { - total_size += - ::google::protobuf::internal::WireFormatLite::MessageSizeNoVirtual( - this->proto_file(i)); + { + unsigned int count = this->proto_file_size(); + total_size += 1UL * count; + for (unsigned int i = 0; i < count; i++) { + total_size += + ::google::protobuf::internal::WireFormatLite::MessageSizeNoVirtual( + this->proto_file(i)); + } } if (_internal_metadata_.have_unknown_fields()) { @@ -437,18 +458,17 @@ int CodeGeneratorRequest::ByteSize() const { ::google::protobuf::internal::WireFormat::ComputeUnknownFieldsSize( unknown_fields()); } + int cached_size = ::google::protobuf::internal::ToCachedSize(total_size); GOOGLE_SAFE_CONCURRENT_WRITES_BEGIN(); - _cached_size_ = total_size; + _cached_size_ = cached_size; GOOGLE_SAFE_CONCURRENT_WRITES_END(); return total_size; } void CodeGeneratorRequest::MergeFrom(const ::google::protobuf::Message& from) { // @@protoc_insertion_point(generalized_merge_from_start:google.protobuf.compiler.CodeGeneratorRequest) - if (GOOGLE_PREDICT_FALSE(&from == this)) { - ::google::protobuf::internal::MergeFromFail(__FILE__, __LINE__); - } - const CodeGeneratorRequest* source = + if (GOOGLE_PREDICT_FALSE(&from == this)) MergeFromFail(__LINE__); + const CodeGeneratorRequest* source = ::google::protobuf::internal::DynamicCastToGenerated( &from); if (source == NULL) { @@ -456,16 +476,22 @@ void CodeGeneratorRequest::MergeFrom(const ::google::protobuf::Message& from) { ::google::protobuf::internal::ReflectionOps::Merge(from, this); } else { // @@protoc_insertion_point(generalized_merge_from_cast_success:google.protobuf.compiler.CodeGeneratorRequest) - MergeFrom(*source); + UnsafeMergeFrom(*source); } } void CodeGeneratorRequest::MergeFrom(const CodeGeneratorRequest& from) { // @@protoc_insertion_point(class_specific_merge_from_start:google.protobuf.compiler.CodeGeneratorRequest) - if (GOOGLE_PREDICT_FALSE(&from == this)) { - ::google::protobuf::internal::MergeFromFail(__FILE__, __LINE__); + if (GOOGLE_PREDICT_TRUE(&from != this)) { + UnsafeMergeFrom(from); + } else { + MergeFromFail(__LINE__); } - file_to_generate_.MergeFrom(from.file_to_generate_); +} + +void CodeGeneratorRequest::UnsafeMergeFrom(const CodeGeneratorRequest& from) { + GOOGLE_DCHECK(&from != this); + file_to_generate_.UnsafeMergeFrom(from.file_to_generate_); proto_file_.MergeFrom(from.proto_file_); if (from._has_bits_[1 / 32] & (0xffu << (1 % 32))) { if (from.has_parameter()) { @@ -474,7 +500,8 @@ void CodeGeneratorRequest::MergeFrom(const CodeGeneratorRequest& from) { } } if (from._internal_metadata_.have_unknown_fields()) { - mutable_unknown_fields()->MergeFrom(from.unknown_fields()); + ::google::protobuf::UnknownFieldSet::MergeToInternalMetdata( + from.unknown_fields(), &_internal_metadata_); } } @@ -489,7 +516,7 @@ void CodeGeneratorRequest::CopyFrom(const CodeGeneratorRequest& from) { // @@protoc_insertion_point(class_specific_copy_from_start:google.protobuf.compiler.CodeGeneratorRequest) if (&from == this) return; Clear(); - MergeFrom(from); + UnsafeMergeFrom(from); } bool CodeGeneratorRequest::IsInitialized() const { @@ -529,49 +556,49 @@ int CodeGeneratorRequest::file_to_generate_size() const { void CodeGeneratorRequest::clear_file_to_generate() { file_to_generate_.Clear(); } - const ::std::string& CodeGeneratorRequest::file_to_generate(int index) const { +const ::std::string& CodeGeneratorRequest::file_to_generate(int index) const { // @@protoc_insertion_point(field_get:google.protobuf.compiler.CodeGeneratorRequest.file_to_generate) return file_to_generate_.Get(index); } - ::std::string* CodeGeneratorRequest::mutable_file_to_generate(int index) { +::std::string* CodeGeneratorRequest::mutable_file_to_generate(int index) { // @@protoc_insertion_point(field_mutable:google.protobuf.compiler.CodeGeneratorRequest.file_to_generate) return file_to_generate_.Mutable(index); } - void CodeGeneratorRequest::set_file_to_generate(int index, const ::std::string& value) { +void CodeGeneratorRequest::set_file_to_generate(int index, const ::std::string& value) { // @@protoc_insertion_point(field_set:google.protobuf.compiler.CodeGeneratorRequest.file_to_generate) file_to_generate_.Mutable(index)->assign(value); } - void CodeGeneratorRequest::set_file_to_generate(int index, const char* value) { +void CodeGeneratorRequest::set_file_to_generate(int index, const char* value) { file_to_generate_.Mutable(index)->assign(value); // @@protoc_insertion_point(field_set_char:google.protobuf.compiler.CodeGeneratorRequest.file_to_generate) } - void CodeGeneratorRequest::set_file_to_generate(int index, const char* value, size_t size) { +void CodeGeneratorRequest::set_file_to_generate(int index, const char* value, size_t size) { file_to_generate_.Mutable(index)->assign( reinterpret_cast(value), size); // @@protoc_insertion_point(field_set_pointer:google.protobuf.compiler.CodeGeneratorRequest.file_to_generate) } - ::std::string* CodeGeneratorRequest::add_file_to_generate() { +::std::string* CodeGeneratorRequest::add_file_to_generate() { // @@protoc_insertion_point(field_add_mutable:google.protobuf.compiler.CodeGeneratorRequest.file_to_generate) return file_to_generate_.Add(); } - void CodeGeneratorRequest::add_file_to_generate(const ::std::string& value) { +void CodeGeneratorRequest::add_file_to_generate(const ::std::string& value) { file_to_generate_.Add()->assign(value); // @@protoc_insertion_point(field_add:google.protobuf.compiler.CodeGeneratorRequest.file_to_generate) } - void CodeGeneratorRequest::add_file_to_generate(const char* value) { +void CodeGeneratorRequest::add_file_to_generate(const char* value) { file_to_generate_.Add()->assign(value); // @@protoc_insertion_point(field_add_char:google.protobuf.compiler.CodeGeneratorRequest.file_to_generate) } - void CodeGeneratorRequest::add_file_to_generate(const char* value, size_t size) { +void CodeGeneratorRequest::add_file_to_generate(const char* value, size_t size) { file_to_generate_.Add()->assign(reinterpret_cast(value), size); // @@protoc_insertion_point(field_add_pointer:google.protobuf.compiler.CodeGeneratorRequest.file_to_generate) } - const ::google::protobuf::RepeatedPtrField< ::std::string>& +const ::google::protobuf::RepeatedPtrField< ::std::string>& CodeGeneratorRequest::file_to_generate() const { // @@protoc_insertion_point(field_list:google.protobuf.compiler.CodeGeneratorRequest.file_to_generate) return file_to_generate_; } - ::google::protobuf::RepeatedPtrField< ::std::string>* +::google::protobuf::RepeatedPtrField< ::std::string>* CodeGeneratorRequest::mutable_file_to_generate() { // @@protoc_insertion_point(field_mutable_list:google.protobuf.compiler.CodeGeneratorRequest.file_to_generate) return &file_to_generate_; @@ -591,37 +618,37 @@ void CodeGeneratorRequest::clear_parameter() { parameter_.ClearToEmptyNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); clear_has_parameter(); } - const ::std::string& CodeGeneratorRequest::parameter() const { +const ::std::string& CodeGeneratorRequest::parameter() const { // @@protoc_insertion_point(field_get:google.protobuf.compiler.CodeGeneratorRequest.parameter) return parameter_.GetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); } - void CodeGeneratorRequest::set_parameter(const ::std::string& value) { +void CodeGeneratorRequest::set_parameter(const ::std::string& value) { set_has_parameter(); parameter_.SetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), value); // @@protoc_insertion_point(field_set:google.protobuf.compiler.CodeGeneratorRequest.parameter) } - void CodeGeneratorRequest::set_parameter(const char* value) { +void CodeGeneratorRequest::set_parameter(const char* value) { set_has_parameter(); parameter_.SetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), ::std::string(value)); // @@protoc_insertion_point(field_set_char:google.protobuf.compiler.CodeGeneratorRequest.parameter) } - void CodeGeneratorRequest::set_parameter(const char* value, size_t size) { +void CodeGeneratorRequest::set_parameter(const char* value, size_t size) { set_has_parameter(); parameter_.SetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), ::std::string(reinterpret_cast(value), size)); // @@protoc_insertion_point(field_set_pointer:google.protobuf.compiler.CodeGeneratorRequest.parameter) } - ::std::string* CodeGeneratorRequest::mutable_parameter() { +::std::string* CodeGeneratorRequest::mutable_parameter() { set_has_parameter(); // @@protoc_insertion_point(field_mutable:google.protobuf.compiler.CodeGeneratorRequest.parameter) return parameter_.MutableNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); } - ::std::string* CodeGeneratorRequest::release_parameter() { +::std::string* CodeGeneratorRequest::release_parameter() { // @@protoc_insertion_point(field_release:google.protobuf.compiler.CodeGeneratorRequest.parameter) clear_has_parameter(); return parameter_.ReleaseNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); } - void CodeGeneratorRequest::set_allocated_parameter(::std::string* parameter) { +void CodeGeneratorRequest::set_allocated_parameter(::std::string* parameter) { if (parameter != NULL) { set_has_parameter(); } else { @@ -673,6 +700,7 @@ const int CodeGeneratorResponse_File::kContentFieldNumber; CodeGeneratorResponse_File::CodeGeneratorResponse_File() : ::google::protobuf::Message(), _internal_metadata_(NULL) { + if (this != internal_default_instance()) protobuf_InitDefaults_google_2fprotobuf_2fcompiler_2fplugin_2eproto(); SharedCtor(); // @@protoc_insertion_point(constructor:google.protobuf.compiler.CodeGeneratorResponse.File) } @@ -684,17 +712,15 @@ CodeGeneratorResponse_File::CodeGeneratorResponse_File(const CodeGeneratorRespon : ::google::protobuf::Message(), _internal_metadata_(NULL) { SharedCtor(); - MergeFrom(from); + UnsafeMergeFrom(from); // @@protoc_insertion_point(copy_constructor:google.protobuf.compiler.CodeGeneratorResponse.File) } void CodeGeneratorResponse_File::SharedCtor() { - ::google::protobuf::internal::GetEmptyString(); _cached_size_ = 0; name_.UnsafeSetDefault(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); insertion_point_.UnsafeSetDefault(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); content_.UnsafeSetDefault(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); - ::memset(_has_bits_, 0, sizeof(_has_bits_)); } CodeGeneratorResponse_File::~CodeGeneratorResponse_File() { @@ -706,8 +732,6 @@ void CodeGeneratorResponse_File::SharedDtor() { name_.DestroyNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); insertion_point_.DestroyNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); content_.DestroyNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); - if (this != default_instance_) { - } } void CodeGeneratorResponse_File::SetCachedSize(int size) const { @@ -721,11 +745,11 @@ const ::google::protobuf::Descriptor* CodeGeneratorResponse_File::descriptor() { } const CodeGeneratorResponse_File& CodeGeneratorResponse_File::default_instance() { - if (default_instance_ == NULL) protobuf_AddDesc_google_2fprotobuf_2fcompiler_2fplugin_2eproto(); - return *default_instance_; + protobuf_InitDefaults_google_2fprotobuf_2fcompiler_2fplugin_2eproto(); + return *internal_default_instance(); } -CodeGeneratorResponse_File* CodeGeneratorResponse_File::default_instance_ = NULL; +::google::protobuf::internal::ExplicitlyConstructed CodeGeneratorResponse_File::default_instance_; CodeGeneratorResponse_File* CodeGeneratorResponse_File::New(::google::protobuf::Arena* arena) const { CodeGeneratorResponse_File* n = new CodeGeneratorResponse_File; @@ -748,7 +772,7 @@ void CodeGeneratorResponse_File::Clear() { content_.ClearToEmptyNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); } } - ::memset(_has_bits_, 0, sizeof(_has_bits_)); + _has_bits_.Clear(); if (_internal_metadata_.have_unknown_fields()) { mutable_unknown_fields()->Clear(); } @@ -921,9 +945,9 @@ void CodeGeneratorResponse_File::SerializeWithCachedSizes( return target; } -int CodeGeneratorResponse_File::ByteSize() const { +size_t CodeGeneratorResponse_File::ByteSizeLong() const { // @@protoc_insertion_point(message_byte_size_start:google.protobuf.compiler.CodeGeneratorResponse.File) - int total_size = 0; + size_t total_size = 0; if (_has_bits_[0 / 32] & 7u) { // optional string name = 1; @@ -953,18 +977,17 @@ int CodeGeneratorResponse_File::ByteSize() const { ::google::protobuf::internal::WireFormat::ComputeUnknownFieldsSize( unknown_fields()); } + int cached_size = ::google::protobuf::internal::ToCachedSize(total_size); GOOGLE_SAFE_CONCURRENT_WRITES_BEGIN(); - _cached_size_ = total_size; + _cached_size_ = cached_size; GOOGLE_SAFE_CONCURRENT_WRITES_END(); return total_size; } void CodeGeneratorResponse_File::MergeFrom(const ::google::protobuf::Message& from) { // @@protoc_insertion_point(generalized_merge_from_start:google.protobuf.compiler.CodeGeneratorResponse.File) - if (GOOGLE_PREDICT_FALSE(&from == this)) { - ::google::protobuf::internal::MergeFromFail(__FILE__, __LINE__); - } - const CodeGeneratorResponse_File* source = + if (GOOGLE_PREDICT_FALSE(&from == this)) MergeFromFail(__LINE__); + const CodeGeneratorResponse_File* source = ::google::protobuf::internal::DynamicCastToGenerated( &from); if (source == NULL) { @@ -972,15 +995,21 @@ void CodeGeneratorResponse_File::MergeFrom(const ::google::protobuf::Message& fr ::google::protobuf::internal::ReflectionOps::Merge(from, this); } else { // @@protoc_insertion_point(generalized_merge_from_cast_success:google.protobuf.compiler.CodeGeneratorResponse.File) - MergeFrom(*source); + UnsafeMergeFrom(*source); } } void CodeGeneratorResponse_File::MergeFrom(const CodeGeneratorResponse_File& from) { // @@protoc_insertion_point(class_specific_merge_from_start:google.protobuf.compiler.CodeGeneratorResponse.File) - if (GOOGLE_PREDICT_FALSE(&from == this)) { - ::google::protobuf::internal::MergeFromFail(__FILE__, __LINE__); + if (GOOGLE_PREDICT_TRUE(&from != this)) { + UnsafeMergeFrom(from); + } else { + MergeFromFail(__LINE__); } +} + +void CodeGeneratorResponse_File::UnsafeMergeFrom(const CodeGeneratorResponse_File& from) { + GOOGLE_DCHECK(&from != this); if (from._has_bits_[0 / 32] & (0xffu << (0 % 32))) { if (from.has_name()) { set_has_name(); @@ -996,7 +1025,8 @@ void CodeGeneratorResponse_File::MergeFrom(const CodeGeneratorResponse_File& fro } } if (from._internal_metadata_.have_unknown_fields()) { - mutable_unknown_fields()->MergeFrom(from.unknown_fields()); + ::google::protobuf::UnknownFieldSet::MergeToInternalMetdata( + from.unknown_fields(), &_internal_metadata_); } } @@ -1011,7 +1041,7 @@ void CodeGeneratorResponse_File::CopyFrom(const CodeGeneratorResponse_File& from // @@protoc_insertion_point(class_specific_copy_from_start:google.protobuf.compiler.CodeGeneratorResponse.File) if (&from == this) return; Clear(); - MergeFrom(from); + UnsafeMergeFrom(from); } bool CodeGeneratorResponse_File::IsInitialized() const { @@ -1050,6 +1080,7 @@ const int CodeGeneratorResponse::kFileFieldNumber; CodeGeneratorResponse::CodeGeneratorResponse() : ::google::protobuf::Message(), _internal_metadata_(NULL) { + if (this != internal_default_instance()) protobuf_InitDefaults_google_2fprotobuf_2fcompiler_2fplugin_2eproto(); SharedCtor(); // @@protoc_insertion_point(constructor:google.protobuf.compiler.CodeGeneratorResponse) } @@ -1061,15 +1092,13 @@ CodeGeneratorResponse::CodeGeneratorResponse(const CodeGeneratorResponse& from) : ::google::protobuf::Message(), _internal_metadata_(NULL) { SharedCtor(); - MergeFrom(from); + UnsafeMergeFrom(from); // @@protoc_insertion_point(copy_constructor:google.protobuf.compiler.CodeGeneratorResponse) } void CodeGeneratorResponse::SharedCtor() { - ::google::protobuf::internal::GetEmptyString(); _cached_size_ = 0; error_.UnsafeSetDefault(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); - ::memset(_has_bits_, 0, sizeof(_has_bits_)); } CodeGeneratorResponse::~CodeGeneratorResponse() { @@ -1079,8 +1108,6 @@ CodeGeneratorResponse::~CodeGeneratorResponse() { void CodeGeneratorResponse::SharedDtor() { error_.DestroyNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); - if (this != default_instance_) { - } } void CodeGeneratorResponse::SetCachedSize(int size) const { @@ -1094,11 +1121,11 @@ const ::google::protobuf::Descriptor* CodeGeneratorResponse::descriptor() { } const CodeGeneratorResponse& CodeGeneratorResponse::default_instance() { - if (default_instance_ == NULL) protobuf_AddDesc_google_2fprotobuf_2fcompiler_2fplugin_2eproto(); - return *default_instance_; + protobuf_InitDefaults_google_2fprotobuf_2fcompiler_2fplugin_2eproto(); + return *internal_default_instance(); } -CodeGeneratorResponse* CodeGeneratorResponse::default_instance_ = NULL; +::google::protobuf::internal::ExplicitlyConstructed CodeGeneratorResponse::default_instance_; CodeGeneratorResponse* CodeGeneratorResponse::New(::google::protobuf::Arena* arena) const { CodeGeneratorResponse* n = new CodeGeneratorResponse; @@ -1114,7 +1141,7 @@ void CodeGeneratorResponse::Clear() { error_.ClearToEmptyNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); } file_.Clear(); - ::memset(_has_bits_, 0, sizeof(_has_bits_)); + _has_bits_.Clear(); if (_internal_metadata_.have_unknown_fields()) { mutable_unknown_fields()->Clear(); } @@ -1241,9 +1268,9 @@ void CodeGeneratorResponse::SerializeWithCachedSizes( return target; } -int CodeGeneratorResponse::ByteSize() const { +size_t CodeGeneratorResponse::ByteSizeLong() const { // @@protoc_insertion_point(message_byte_size_start:google.protobuf.compiler.CodeGeneratorResponse) - int total_size = 0; + size_t total_size = 0; // optional string error = 1; if (has_error()) { @@ -1253,11 +1280,14 @@ int CodeGeneratorResponse::ByteSize() const { } // repeated .google.protobuf.compiler.CodeGeneratorResponse.File file = 15; - total_size += 1 * this->file_size(); - for (int i = 0; i < this->file_size(); i++) { - total_size += - ::google::protobuf::internal::WireFormatLite::MessageSizeNoVirtual( - this->file(i)); + { + unsigned int count = this->file_size(); + total_size += 1UL * count; + for (unsigned int i = 0; i < count; i++) { + total_size += + ::google::protobuf::internal::WireFormatLite::MessageSizeNoVirtual( + this->file(i)); + } } if (_internal_metadata_.have_unknown_fields()) { @@ -1265,18 +1295,17 @@ int CodeGeneratorResponse::ByteSize() const { ::google::protobuf::internal::WireFormat::ComputeUnknownFieldsSize( unknown_fields()); } + int cached_size = ::google::protobuf::internal::ToCachedSize(total_size); GOOGLE_SAFE_CONCURRENT_WRITES_BEGIN(); - _cached_size_ = total_size; + _cached_size_ = cached_size; GOOGLE_SAFE_CONCURRENT_WRITES_END(); return total_size; } void CodeGeneratorResponse::MergeFrom(const ::google::protobuf::Message& from) { // @@protoc_insertion_point(generalized_merge_from_start:google.protobuf.compiler.CodeGeneratorResponse) - if (GOOGLE_PREDICT_FALSE(&from == this)) { - ::google::protobuf::internal::MergeFromFail(__FILE__, __LINE__); - } - const CodeGeneratorResponse* source = + if (GOOGLE_PREDICT_FALSE(&from == this)) MergeFromFail(__LINE__); + const CodeGeneratorResponse* source = ::google::protobuf::internal::DynamicCastToGenerated( &from); if (source == NULL) { @@ -1284,15 +1313,21 @@ void CodeGeneratorResponse::MergeFrom(const ::google::protobuf::Message& from) { ::google::protobuf::internal::ReflectionOps::Merge(from, this); } else { // @@protoc_insertion_point(generalized_merge_from_cast_success:google.protobuf.compiler.CodeGeneratorResponse) - MergeFrom(*source); + UnsafeMergeFrom(*source); } } void CodeGeneratorResponse::MergeFrom(const CodeGeneratorResponse& from) { // @@protoc_insertion_point(class_specific_merge_from_start:google.protobuf.compiler.CodeGeneratorResponse) - if (GOOGLE_PREDICT_FALSE(&from == this)) { - ::google::protobuf::internal::MergeFromFail(__FILE__, __LINE__); + if (GOOGLE_PREDICT_TRUE(&from != this)) { + UnsafeMergeFrom(from); + } else { + MergeFromFail(__LINE__); } +} + +void CodeGeneratorResponse::UnsafeMergeFrom(const CodeGeneratorResponse& from) { + GOOGLE_DCHECK(&from != this); file_.MergeFrom(from.file_); if (from._has_bits_[0 / 32] & (0xffu << (0 % 32))) { if (from.has_error()) { @@ -1301,7 +1336,8 @@ void CodeGeneratorResponse::MergeFrom(const CodeGeneratorResponse& from) { } } if (from._internal_metadata_.have_unknown_fields()) { - mutable_unknown_fields()->MergeFrom(from.unknown_fields()); + ::google::protobuf::UnknownFieldSet::MergeToInternalMetdata( + from.unknown_fields(), &_internal_metadata_); } } @@ -1316,7 +1352,7 @@ void CodeGeneratorResponse::CopyFrom(const CodeGeneratorResponse& from) { // @@protoc_insertion_point(class_specific_copy_from_start:google.protobuf.compiler.CodeGeneratorResponse) if (&from == this) return; Clear(); - MergeFrom(from); + UnsafeMergeFrom(from); } bool CodeGeneratorResponse::IsInitialized() const { @@ -1361,37 +1397,37 @@ void CodeGeneratorResponse_File::clear_name() { name_.ClearToEmptyNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); clear_has_name(); } - const ::std::string& CodeGeneratorResponse_File::name() const { +const ::std::string& CodeGeneratorResponse_File::name() const { // @@protoc_insertion_point(field_get:google.protobuf.compiler.CodeGeneratorResponse.File.name) return name_.GetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); } - void CodeGeneratorResponse_File::set_name(const ::std::string& value) { +void CodeGeneratorResponse_File::set_name(const ::std::string& value) { set_has_name(); name_.SetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), value); // @@protoc_insertion_point(field_set:google.protobuf.compiler.CodeGeneratorResponse.File.name) } - void CodeGeneratorResponse_File::set_name(const char* value) { +void CodeGeneratorResponse_File::set_name(const char* value) { set_has_name(); name_.SetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), ::std::string(value)); // @@protoc_insertion_point(field_set_char:google.protobuf.compiler.CodeGeneratorResponse.File.name) } - void CodeGeneratorResponse_File::set_name(const char* value, size_t size) { +void CodeGeneratorResponse_File::set_name(const char* value, size_t size) { set_has_name(); name_.SetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), ::std::string(reinterpret_cast(value), size)); // @@protoc_insertion_point(field_set_pointer:google.protobuf.compiler.CodeGeneratorResponse.File.name) } - ::std::string* CodeGeneratorResponse_File::mutable_name() { +::std::string* CodeGeneratorResponse_File::mutable_name() { set_has_name(); // @@protoc_insertion_point(field_mutable:google.protobuf.compiler.CodeGeneratorResponse.File.name) return name_.MutableNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); } - ::std::string* CodeGeneratorResponse_File::release_name() { +::std::string* CodeGeneratorResponse_File::release_name() { // @@protoc_insertion_point(field_release:google.protobuf.compiler.CodeGeneratorResponse.File.name) clear_has_name(); return name_.ReleaseNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); } - void CodeGeneratorResponse_File::set_allocated_name(::std::string* name) { +void CodeGeneratorResponse_File::set_allocated_name(::std::string* name) { if (name != NULL) { set_has_name(); } else { @@ -1415,37 +1451,37 @@ void CodeGeneratorResponse_File::clear_insertion_point() { insertion_point_.ClearToEmptyNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); clear_has_insertion_point(); } - const ::std::string& CodeGeneratorResponse_File::insertion_point() const { +const ::std::string& CodeGeneratorResponse_File::insertion_point() const { // @@protoc_insertion_point(field_get:google.protobuf.compiler.CodeGeneratorResponse.File.insertion_point) return insertion_point_.GetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); } - void CodeGeneratorResponse_File::set_insertion_point(const ::std::string& value) { +void CodeGeneratorResponse_File::set_insertion_point(const ::std::string& value) { set_has_insertion_point(); insertion_point_.SetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), value); // @@protoc_insertion_point(field_set:google.protobuf.compiler.CodeGeneratorResponse.File.insertion_point) } - void CodeGeneratorResponse_File::set_insertion_point(const char* value) { +void CodeGeneratorResponse_File::set_insertion_point(const char* value) { set_has_insertion_point(); insertion_point_.SetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), ::std::string(value)); // @@protoc_insertion_point(field_set_char:google.protobuf.compiler.CodeGeneratorResponse.File.insertion_point) } - void CodeGeneratorResponse_File::set_insertion_point(const char* value, size_t size) { +void CodeGeneratorResponse_File::set_insertion_point(const char* value, size_t size) { set_has_insertion_point(); insertion_point_.SetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), ::std::string(reinterpret_cast(value), size)); // @@protoc_insertion_point(field_set_pointer:google.protobuf.compiler.CodeGeneratorResponse.File.insertion_point) } - ::std::string* CodeGeneratorResponse_File::mutable_insertion_point() { +::std::string* CodeGeneratorResponse_File::mutable_insertion_point() { set_has_insertion_point(); // @@protoc_insertion_point(field_mutable:google.protobuf.compiler.CodeGeneratorResponse.File.insertion_point) return insertion_point_.MutableNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); } - ::std::string* CodeGeneratorResponse_File::release_insertion_point() { +::std::string* CodeGeneratorResponse_File::release_insertion_point() { // @@protoc_insertion_point(field_release:google.protobuf.compiler.CodeGeneratorResponse.File.insertion_point) clear_has_insertion_point(); return insertion_point_.ReleaseNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); } - void CodeGeneratorResponse_File::set_allocated_insertion_point(::std::string* insertion_point) { +void CodeGeneratorResponse_File::set_allocated_insertion_point(::std::string* insertion_point) { if (insertion_point != NULL) { set_has_insertion_point(); } else { @@ -1469,37 +1505,37 @@ void CodeGeneratorResponse_File::clear_content() { content_.ClearToEmptyNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); clear_has_content(); } - const ::std::string& CodeGeneratorResponse_File::content() const { +const ::std::string& CodeGeneratorResponse_File::content() const { // @@protoc_insertion_point(field_get:google.protobuf.compiler.CodeGeneratorResponse.File.content) return content_.GetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); } - void CodeGeneratorResponse_File::set_content(const ::std::string& value) { +void CodeGeneratorResponse_File::set_content(const ::std::string& value) { set_has_content(); content_.SetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), value); // @@protoc_insertion_point(field_set:google.protobuf.compiler.CodeGeneratorResponse.File.content) } - void CodeGeneratorResponse_File::set_content(const char* value) { +void CodeGeneratorResponse_File::set_content(const char* value) { set_has_content(); content_.SetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), ::std::string(value)); // @@protoc_insertion_point(field_set_char:google.protobuf.compiler.CodeGeneratorResponse.File.content) } - void CodeGeneratorResponse_File::set_content(const char* value, size_t size) { +void CodeGeneratorResponse_File::set_content(const char* value, size_t size) { set_has_content(); content_.SetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), ::std::string(reinterpret_cast(value), size)); // @@protoc_insertion_point(field_set_pointer:google.protobuf.compiler.CodeGeneratorResponse.File.content) } - ::std::string* CodeGeneratorResponse_File::mutable_content() { +::std::string* CodeGeneratorResponse_File::mutable_content() { set_has_content(); // @@protoc_insertion_point(field_mutable:google.protobuf.compiler.CodeGeneratorResponse.File.content) return content_.MutableNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); } - ::std::string* CodeGeneratorResponse_File::release_content() { +::std::string* CodeGeneratorResponse_File::release_content() { // @@protoc_insertion_point(field_release:google.protobuf.compiler.CodeGeneratorResponse.File.content) clear_has_content(); return content_.ReleaseNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); } - void CodeGeneratorResponse_File::set_allocated_content(::std::string* content) { +void CodeGeneratorResponse_File::set_allocated_content(::std::string* content) { if (content != NULL) { set_has_content(); } else { @@ -1527,37 +1563,37 @@ void CodeGeneratorResponse::clear_error() { error_.ClearToEmptyNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); clear_has_error(); } - const ::std::string& CodeGeneratorResponse::error() const { +const ::std::string& CodeGeneratorResponse::error() const { // @@protoc_insertion_point(field_get:google.protobuf.compiler.CodeGeneratorResponse.error) return error_.GetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); } - void CodeGeneratorResponse::set_error(const ::std::string& value) { +void CodeGeneratorResponse::set_error(const ::std::string& value) { set_has_error(); error_.SetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), value); // @@protoc_insertion_point(field_set:google.protobuf.compiler.CodeGeneratorResponse.error) } - void CodeGeneratorResponse::set_error(const char* value) { +void CodeGeneratorResponse::set_error(const char* value) { set_has_error(); error_.SetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), ::std::string(value)); // @@protoc_insertion_point(field_set_char:google.protobuf.compiler.CodeGeneratorResponse.error) } - void CodeGeneratorResponse::set_error(const char* value, size_t size) { +void CodeGeneratorResponse::set_error(const char* value, size_t size) { set_has_error(); error_.SetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), ::std::string(reinterpret_cast(value), size)); // @@protoc_insertion_point(field_set_pointer:google.protobuf.compiler.CodeGeneratorResponse.error) } - ::std::string* CodeGeneratorResponse::mutable_error() { +::std::string* CodeGeneratorResponse::mutable_error() { set_has_error(); // @@protoc_insertion_point(field_mutable:google.protobuf.compiler.CodeGeneratorResponse.error) return error_.MutableNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); } - ::std::string* CodeGeneratorResponse::release_error() { +::std::string* CodeGeneratorResponse::release_error() { // @@protoc_insertion_point(field_release:google.protobuf.compiler.CodeGeneratorResponse.error) clear_has_error(); return error_.ReleaseNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); } - void CodeGeneratorResponse::set_allocated_error(::std::string* error) { +void CodeGeneratorResponse::set_allocated_error(::std::string* error) { if (error != NULL) { set_has_error(); } else { diff --git a/src/google/protobuf/compiler/plugin.pb.h b/src/google/protobuf/compiler/plugin.pb.h index 282c977d..709ab6ba 100644 --- a/src/google/protobuf/compiler/plugin.pb.h +++ b/src/google/protobuf/compiler/plugin.pb.h @@ -36,6 +36,7 @@ namespace compiler { // Internal implementation detail -- do not call these. void LIBPROTOC_EXPORT protobuf_AddDesc_google_2fprotobuf_2fcompiler_2fplugin_2eproto(); +void LIBPROTOC_EXPORT protobuf_InitDefaults_google_2fprotobuf_2fcompiler_2fplugin_2eproto(); void protobuf_AssignDesc_google_2fprotobuf_2fcompiler_2fplugin_2eproto(); void protobuf_ShutdownFile_google_2fprotobuf_2fcompiler_2fplugin_2eproto(); @@ -68,6 +69,10 @@ class LIBPROTOC_EXPORT CodeGeneratorRequest : public ::google::protobuf::Message static const ::google::protobuf::Descriptor* descriptor(); static const CodeGeneratorRequest& default_instance(); + static inline const CodeGeneratorRequest* internal_default_instance() { + return &default_instance_.get(); + } + void Swap(CodeGeneratorRequest* other); // implements Message ---------------------------------------------- @@ -82,7 +87,7 @@ class LIBPROTOC_EXPORT CodeGeneratorRequest : public ::google::protobuf::Message void Clear(); bool IsInitialized() const; - int ByteSize() const; + size_t ByteSizeLong() const; bool MergePartialFromCodedStream( ::google::protobuf::io::CodedInputStream* input); void SerializeWithCachedSizes( @@ -98,6 +103,7 @@ class LIBPROTOC_EXPORT CodeGeneratorRequest : public ::google::protobuf::Message void SharedDtor(); void SetCachedSize(int size) const; void InternalSwap(CodeGeneratorRequest* other); + void UnsafeMergeFrom(const CodeGeneratorRequest& from); private: inline ::google::protobuf::Arena* GetArenaNoVirtual() const { return _internal_metadata_.arena(); @@ -159,17 +165,18 @@ class LIBPROTOC_EXPORT CodeGeneratorRequest : public ::google::protobuf::Message inline void clear_has_parameter(); ::google::protobuf::internal::InternalMetadataWithArena _internal_metadata_; - ::google::protobuf::uint32 _has_bits_[1]; + ::google::protobuf::internal::HasBits<1> _has_bits_; mutable int _cached_size_; ::google::protobuf::RepeatedPtrField< ::std::string> file_to_generate_; - ::google::protobuf::internal::ArenaStringPtr parameter_; ::google::protobuf::RepeatedPtrField< ::google::protobuf::FileDescriptorProto > proto_file_; - friend void LIBPROTOC_EXPORT protobuf_AddDesc_google_2fprotobuf_2fcompiler_2fplugin_2eproto(); + ::google::protobuf::internal::ArenaStringPtr parameter_; + friend void LIBPROTOC_EXPORT protobuf_InitDefaults_google_2fprotobuf_2fcompiler_2fplugin_2eproto_impl(); + friend void LIBPROTOC_EXPORT protobuf_AddDesc_google_2fprotobuf_2fcompiler_2fplugin_2eproto_impl(); friend void protobuf_AssignDesc_google_2fprotobuf_2fcompiler_2fplugin_2eproto(); friend void protobuf_ShutdownFile_google_2fprotobuf_2fcompiler_2fplugin_2eproto(); void InitAsDefaultInstance(); - static CodeGeneratorRequest* default_instance_; + static ::google::protobuf::internal::ExplicitlyConstructed default_instance_; }; // ------------------------------------------------------------------- @@ -196,6 +203,10 @@ class LIBPROTOC_EXPORT CodeGeneratorResponse_File : public ::google::protobuf::M static const ::google::protobuf::Descriptor* descriptor(); static const CodeGeneratorResponse_File& default_instance(); + static inline const CodeGeneratorResponse_File* internal_default_instance() { + return &default_instance_.get(); + } + void Swap(CodeGeneratorResponse_File* other); // implements Message ---------------------------------------------- @@ -210,7 +221,7 @@ class LIBPROTOC_EXPORT CodeGeneratorResponse_File : public ::google::protobuf::M void Clear(); bool IsInitialized() const; - int ByteSize() const; + size_t ByteSizeLong() const; bool MergePartialFromCodedStream( ::google::protobuf::io::CodedInputStream* input); void SerializeWithCachedSizes( @@ -226,6 +237,7 @@ class LIBPROTOC_EXPORT CodeGeneratorResponse_File : public ::google::protobuf::M void SharedDtor(); void SetCachedSize(int size) const; void InternalSwap(CodeGeneratorResponse_File* other); + void UnsafeMergeFrom(const CodeGeneratorResponse_File& from); private: inline ::google::protobuf::Arena* GetArenaNoVirtual() const { return _internal_metadata_.arena(); @@ -287,17 +299,18 @@ class LIBPROTOC_EXPORT CodeGeneratorResponse_File : public ::google::protobuf::M inline void clear_has_content(); ::google::protobuf::internal::InternalMetadataWithArena _internal_metadata_; - ::google::protobuf::uint32 _has_bits_[1]; + ::google::protobuf::internal::HasBits<1> _has_bits_; mutable int _cached_size_; ::google::protobuf::internal::ArenaStringPtr name_; ::google::protobuf::internal::ArenaStringPtr insertion_point_; ::google::protobuf::internal::ArenaStringPtr content_; - friend void LIBPROTOC_EXPORT protobuf_AddDesc_google_2fprotobuf_2fcompiler_2fplugin_2eproto(); + friend void LIBPROTOC_EXPORT protobuf_InitDefaults_google_2fprotobuf_2fcompiler_2fplugin_2eproto_impl(); + friend void LIBPROTOC_EXPORT protobuf_AddDesc_google_2fprotobuf_2fcompiler_2fplugin_2eproto_impl(); friend void protobuf_AssignDesc_google_2fprotobuf_2fcompiler_2fplugin_2eproto(); friend void protobuf_ShutdownFile_google_2fprotobuf_2fcompiler_2fplugin_2eproto(); void InitAsDefaultInstance(); - static CodeGeneratorResponse_File* default_instance_; + static ::google::protobuf::internal::ExplicitlyConstructed default_instance_; }; // ------------------------------------------------------------------- @@ -324,6 +337,10 @@ class LIBPROTOC_EXPORT CodeGeneratorResponse : public ::google::protobuf::Messag static const ::google::protobuf::Descriptor* descriptor(); static const CodeGeneratorResponse& default_instance(); + static inline const CodeGeneratorResponse* internal_default_instance() { + return &default_instance_.get(); + } + void Swap(CodeGeneratorResponse* other); // implements Message ---------------------------------------------- @@ -338,7 +355,7 @@ class LIBPROTOC_EXPORT CodeGeneratorResponse : public ::google::protobuf::Messag void Clear(); bool IsInitialized() const; - int ByteSize() const; + size_t ByteSizeLong() const; bool MergePartialFromCodedStream( ::google::protobuf::io::CodedInputStream* input); void SerializeWithCachedSizes( @@ -354,6 +371,7 @@ class LIBPROTOC_EXPORT CodeGeneratorResponse : public ::google::protobuf::Messag void SharedDtor(); void SetCachedSize(int size) const; void InternalSwap(CodeGeneratorResponse* other); + void UnsafeMergeFrom(const CodeGeneratorResponse& from); private: inline ::google::protobuf::Arena* GetArenaNoVirtual() const { return _internal_metadata_.arena(); @@ -401,16 +419,17 @@ class LIBPROTOC_EXPORT CodeGeneratorResponse : public ::google::protobuf::Messag inline void clear_has_error(); ::google::protobuf::internal::InternalMetadataWithArena _internal_metadata_; - ::google::protobuf::uint32 _has_bits_[1]; + ::google::protobuf::internal::HasBits<1> _has_bits_; mutable int _cached_size_; - ::google::protobuf::internal::ArenaStringPtr error_; ::google::protobuf::RepeatedPtrField< ::google::protobuf::compiler::CodeGeneratorResponse_File > file_; - friend void LIBPROTOC_EXPORT protobuf_AddDesc_google_2fprotobuf_2fcompiler_2fplugin_2eproto(); + ::google::protobuf::internal::ArenaStringPtr error_; + friend void LIBPROTOC_EXPORT protobuf_InitDefaults_google_2fprotobuf_2fcompiler_2fplugin_2eproto_impl(); + friend void LIBPROTOC_EXPORT protobuf_AddDesc_google_2fprotobuf_2fcompiler_2fplugin_2eproto_impl(); friend void protobuf_AssignDesc_google_2fprotobuf_2fcompiler_2fplugin_2eproto(); friend void protobuf_ShutdownFile_google_2fprotobuf_2fcompiler_2fplugin_2eproto(); void InitAsDefaultInstance(); - static CodeGeneratorResponse* default_instance_; + static ::google::protobuf::internal::ExplicitlyConstructed default_instance_; }; // =================================================================== diff --git a/src/google/protobuf/compiler/python/python_generator.cc b/src/google/protobuf/compiler/python/python_generator.cc index d5468a0c..3b1b0d1d 100644 --- a/src/google/protobuf/compiler/python/python_generator.cc +++ b/src/google/protobuf/compiler/python/python_generator.cc @@ -88,8 +88,8 @@ string StripProto(const string& filename) { // Returns the Python module name expected for a given .proto filename. string ModuleName(const string& filename) { string basename = StripProto(filename); - StripString(&basename, "-", '_'); - StripString(&basename, "/", '.'); + ReplaceCharacters(&basename, "-", '_'); + ReplaceCharacters(&basename, "/", '.'); return basename + "_pb2"; } @@ -320,7 +320,7 @@ bool Generator::Generate(const FileDescriptor* file, file_ = file; string module_name = ModuleName(file->name()); string filename = module_name; - StripString(&filename, ".", '/'); + ReplaceCharacters(&filename, ".", '/'); filename += ".py"; FileDescriptorProto fdp; @@ -430,6 +430,15 @@ void Generator::PrintFileDescriptor() const { } printer_->Print("]"); } + if (file_->public_dependency_count() > 0) { + printer_->Print(",\npublic_dependencies=["); + for (int i = 0; i < file_->public_dependency_count(); ++i) { + string module_alias = ModuleAlias(file_->public_dependency(i)->name()); + printer_->Print("$module_alias$.DESCRIPTOR,", "module_alias", + module_alias); + } + printer_->Print("]"); + } // TODO(falk): Also print options and fix the message_type, enum_type, // service and extension later in the generation. @@ -1094,6 +1103,8 @@ void Generator::PrintFieldDescriptor( m["default_value"] = StringifyDefaultValue(field); m["is_extension"] = is_extension ? "True" : "False"; m["options"] = OptionsValue("FieldOptions", options_string); + m["json_name"] = field.has_json_name() ? + ", json_name='" + field.json_name() + "'": ""; // We always set message_type and enum_type to None at this point, and then // these fields in correctly after all referenced descriptors have been // defined and/or imported (see FixForeignFieldsInDescriptors()). @@ -1104,7 +1115,7 @@ void Generator::PrintFieldDescriptor( " has_default_value=$has_default_value$, default_value=$default_value$,\n" " message_type=None, enum_type=None, containing_type=None,\n" " is_extension=$is_extension$, extension_scope=None,\n" - " options=$options$)"; + " options=$options$$json_name$)"; printer_->Print(m, field_descriptor_decl); } diff --git a/src/google/protobuf/descriptor.cc b/src/google/protobuf/descriptor.cc index 9b20946c..4dccb585 100644 --- a/src/google/protobuf/descriptor.cc +++ b/src/google/protobuf/descriptor.cc @@ -69,6 +69,7 @@ #undef PACKAGE // autoheader #defines this. :( namespace google { + namespace protobuf { const FieldDescriptor::CppType @@ -164,6 +165,15 @@ const int FieldDescriptor::kLastReservedNumber; namespace { +// Note: I distrust ctype.h due to locales. +char ToUpper(char ch) { + return (ch >= 'a' && ch <= 'z') ? (ch - 'a' + 'A') : ch; +} + +char ToLower(char ch) { + return (ch >= 'A' && ch <= 'Z') ? (ch - 'A' + 'a') : ch; +} + string ToCamelCase(const string& input, bool lower_first) { bool capitalize_next = !lower_first; string result; @@ -173,12 +183,7 @@ string ToCamelCase(const string& input, bool lower_first) { if (input[i] == '_') { capitalize_next = true; } else if (capitalize_next) { - // Note: I distrust ctype.h due to locales. - if ('a' <= input[i] && input[i] <= 'z') { - result.push_back(input[i] - 'a' + 'A'); - } else { - result.push_back(input[i]); - } + result.push_back(ToUpper(input[i])); capitalize_next = false; } else { result.push_back(input[i]); @@ -186,13 +191,116 @@ string ToCamelCase(const string& input, bool lower_first) { } // Lower-case the first letter. - if (lower_first && !result.empty() && 'A' <= result[0] && result[0] <= 'Z') { - result[0] = result[0] - 'A' + 'a'; + if (lower_first && !result.empty()) { + result[0] = ToLower(result[0]); } return result; } +string ToJsonName(const string& input) { + bool capitalize_next = false; + string result; + result.reserve(input.size()); + + for (int i = 0; i < input.size(); i++) { + if (input[i] == '_') { + capitalize_next = true; + } else if (capitalize_next) { + result.push_back(ToUpper(input[i])); + capitalize_next = false; + } else { + result.push_back(input[i]); + } + } + + return result; +} + +string EnumValueToPascalCase(const string& input) { + bool next_upper = true; + string result; + result.reserve(input.size()); + + for (int i = 0; i < input.size(); i++) { + if (input[i] == '_') { + next_upper = true; + } else { + if (next_upper) { + result.push_back(ToUpper(input[i])); + } else { + result.push_back(ToLower(input[i])); + } + next_upper = false; + } + } + + return result; +} + +// Class to remove an enum prefix from enum values. +class PrefixRemover { + public: + PrefixRemover(StringPiece prefix) { + // Strip underscores and lower-case the prefix. + for (int i = 0; i < prefix.size(); i++) { + if (prefix[i] != '_') { + prefix_ += ascii_tolower(prefix[i]); + } + } + } + + // Tries to remove the enum prefix from this enum value. + // If this is not possible, returns the input verbatim. + string MaybeRemove(StringPiece str) { + // We can't just lowercase and strip str and look for a prefix. + // We need to properly recognize the difference between: + // + // enum Foo { + // FOO_BAR_BAZ = 0; + // FOO_BARBAZ = 1; + // } + // + // This is acceptable (though perhaps not advisable) because even when + // we PascalCase, these two will still be distinct (BarBaz vs. Barbaz). + size_t i, j; + + // Skip past prefix_ in str if we can. + for (i = 0, j = 0; i < str.size() && j < prefix_.size(); i++) { + if (str[i] == '_') { + continue; + } + + if (ascii_tolower(str[i]) != prefix_[j++]) { + return str.as_string(); + } + } + + // If we didn't make it through the prefix, we've failed to strip the + // prefix. + if (j < prefix_.size()) { + return str.as_string(); + } + + // Skip underscores between prefix and further characters. + while (i < str.size() && str[i] == '_') { + i++; + } + + // Enum label can't be the empty string. + if (i == str.size()) { + return str.as_string(); + } + + // We successfully stripped the prefix. + str.remove_prefix(i); + return str.as_string(); + } + + private: + string prefix_; +}; + // A DescriptorPool contains a bunch of hash_maps to implement the // various Find*By*() methods. Since hashtable lookups are O(1), it's // most efficient to construct a fixed set of large hash_maps used by @@ -2390,6 +2498,17 @@ void FieldDescriptor::DebugString(int depth, strings::SubstituteAndAppend(contents, " [default = $0", DefaultValueAsString(true)); } + if (has_json_name_) { + if (!bracketed) { + bracketed = true; + contents->append("["); + } else { + contents->append(", "); + } + contents->append("json_name = \""); + contents->append(CEscape(json_name())); + contents->append("\""); + } string formatted_options; if (FormatBracketedOptions(depth, options(), &formatted_options)) { @@ -2980,6 +3099,8 @@ class DescriptorBuilder { void BuildOneof(const OneofDescriptorProto& proto, Descriptor* parent, OneofDescriptor* result); + void CheckEnumValueUniqueness(const EnumDescriptorProto& proto, + const EnumDescriptor* result); void BuildEnum(const EnumDescriptorProto& proto, const Descriptor* parent, EnumDescriptor* result); @@ -4232,7 +4353,7 @@ void DescriptorBuilder::BuildFieldOrExtension(const FieldDescriptorProto& proto, result->json_name_ = tables_->AllocateString(proto.json_name()); } else { result->has_json_name_ = false; - result->json_name_ = result->camelcase_name_; + result->json_name_ = tables_->AllocateString(ToJsonName(proto.name())); } // Some compilers do not allow static_cast directly between two enum types, @@ -4540,6 +4661,61 @@ void DescriptorBuilder::BuildOneof(const OneofDescriptorProto& proto, proto, Symbol(result)); } +void DescriptorBuilder::CheckEnumValueUniqueness( + const EnumDescriptorProto& proto, const EnumDescriptor* result) { + + // Check that enum labels are still unique when we remove the enum prefix from + // values that have it. + // + // This will fail for something like: + // + // enum MyEnum { + // MY_ENUM_FOO = 0; + // FOO = 1; + // } + // + // By enforcing this reasonable constraint, we allow code generators to strip + // the prefix and/or PascalCase it without creating conflicts. This can lead + // to much nicer language-specific enums like: + // + // enum NameType { + // FirstName = 1, + // LastName = 2, + // } + // + // Instead of: + // + // enum NameType { + // NAME_TYPE_FIRST_NAME = 1, + // NAME_TYPE_LAST_NAME = 2, + // } + PrefixRemover remover(result->name()); + map values; + for (int i = 0; i < result->value_count(); i++) { + const google::protobuf::EnumValueDescriptor* value = result->value(i); + string stripped = + EnumValueToPascalCase(remover.MaybeRemove(value->name())); + std::pair::iterator, bool> + insert_result = values.insert(std::make_pair(stripped, value)); + bool inserted = insert_result.second; + + // We don't throw the error if the two conflicting symbols are identical, or + // if they map to the same number. In the former case, the normal symbol + // duplication error will fire so we don't need to (and its error message + // will make more sense). We allow the latter case so users can create + // aliases which add or remove the prefix (code generators that do prefix + // stripping should de-dup the labels in this case). + if (!inserted && insert_result.first->second->name() != value->name() && + insert_result.first->second->number() != value->number()) { + AddError(value->full_name(), proto.value(i), + DescriptorPool::ErrorCollector::NAME, + "When enum name is stripped and label is PascalCased (" + + stripped + "), this value label conflicts with " + + values[stripped]->name()); + } + } +} + void DescriptorBuilder::BuildEnum(const EnumDescriptorProto& proto, const Descriptor* parent, EnumDescriptor* result) { @@ -4568,6 +4744,8 @@ void DescriptorBuilder::BuildEnum(const EnumDescriptorProto& proto, BUILD_ARRAY(proto, result, value, BuildEnumValue, result); + CheckEnumValueUniqueness(proto, result); + // Copy options. if (!proto.has_options()) { result->options_ = NULL; // Will set to default_instance later. @@ -5254,7 +5432,6 @@ void DescriptorBuilder::ValidateProto3Enum( } } - void DescriptorBuilder::ValidateMessageOptions(Descriptor* message, const DescriptorProto& proto) { VALIDATE_OPTIONS_FROM_ARRAY(message, field, Field); @@ -5275,7 +5452,6 @@ void DescriptorBuilder::ValidateMessageOptions(Descriptor* message, max_extension_range)); } } - } void DescriptorBuilder::ValidateFieldOptions(FieldDescriptor* field, diff --git a/src/google/protobuf/descriptor.h b/src/google/protobuf/descriptor.h index b040b62c..0151e1d9 100644 --- a/src/google/protobuf/descriptor.h +++ b/src/google/protobuf/descriptor.h @@ -143,7 +143,7 @@ struct SourceLocation { // See the comments in SourceCodeInfo.Location (descriptor.proto) for details. string leading_comments; string trailing_comments; - vector leading_detached_comments; + std::vector leading_detached_comments; }; // Options when generating machine-parsable output from a descriptor with @@ -558,6 +558,10 @@ class LIBPROTOBUF_EXPORT FieldDescriptor { // Does this field have an explicitly-declared default value? bool has_default_value() const; + // Whether the user has specified the json_name field option in the .proto + // file. + bool has_json_name() const; + // Get the field default value if cpp_type() == CPPTYPE_INT32. If no // explicit default was defined, the default is 0. int32 default_value_int32() const; @@ -683,7 +687,7 @@ class LIBPROTOBUF_EXPORT FieldDescriptor { // file. bool has_json_name_; // If has_json_name_ is true, it's the value specified by the user. - // Otherwise, it has the same value as lowercase_name_. + // Otherwise, it has the same value as camelcase_name_. const string* json_name_; const FileDescriptor* file_; int number_; @@ -1699,6 +1703,7 @@ PROTOBUF_DEFINE_ACCESSOR(FieldDescriptor, message_type, const Descriptor*) PROTOBUF_DEFINE_ACCESSOR(FieldDescriptor, enum_type, const EnumDescriptor*) PROTOBUF_DEFINE_OPTIONS_ACCESSOR(FieldDescriptor, FieldOptions) PROTOBUF_DEFINE_ACCESSOR(FieldDescriptor, has_default_value, bool) +PROTOBUF_DEFINE_ACCESSOR(FieldDescriptor, has_json_name, bool) PROTOBUF_DEFINE_ACCESSOR(FieldDescriptor, default_value_int32 , int32 ) PROTOBUF_DEFINE_ACCESSOR(FieldDescriptor, default_value_int64 , int64 ) PROTOBUF_DEFINE_ACCESSOR(FieldDescriptor, default_value_uint32, uint32) diff --git a/src/google/protobuf/descriptor.pb.cc b/src/google/protobuf/descriptor.pb.cc index 13e8776f..3f310801 100644 --- a/src/google/protobuf/descriptor.pb.cc +++ b/src/google/protobuf/descriptor.pb.cc @@ -120,14 +120,13 @@ void protobuf_AssignDesc_google_2fprotobuf_2fdescriptor_2eproto() { FileDescriptorSet_reflection_ = ::google::protobuf::internal::GeneratedMessageReflection::NewGeneratedMessageReflection( FileDescriptorSet_descriptor_, - FileDescriptorSet::default_instance_, + FileDescriptorSet::internal_default_instance(), FileDescriptorSet_offsets_, - GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(FileDescriptorSet, _has_bits_[0]), + GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(FileDescriptorSet, _has_bits_), -1, -1, sizeof(FileDescriptorSet), - GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(FileDescriptorSet, _internal_metadata_), - -1); + GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(FileDescriptorSet, _internal_metadata_)); FileDescriptorProto_descriptor_ = file->message_type(1); static const int FileDescriptorProto_offsets_[12] = { GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(FileDescriptorProto, name_), @@ -146,14 +145,13 @@ void protobuf_AssignDesc_google_2fprotobuf_2fdescriptor_2eproto() { FileDescriptorProto_reflection_ = ::google::protobuf::internal::GeneratedMessageReflection::NewGeneratedMessageReflection( FileDescriptorProto_descriptor_, - FileDescriptorProto::default_instance_, + FileDescriptorProto::internal_default_instance(), FileDescriptorProto_offsets_, - GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(FileDescriptorProto, _has_bits_[0]), + GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(FileDescriptorProto, _has_bits_), -1, -1, sizeof(FileDescriptorProto), - GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(FileDescriptorProto, _internal_metadata_), - -1); + GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(FileDescriptorProto, _internal_metadata_)); DescriptorProto_descriptor_ = file->message_type(2); static const int DescriptorProto_offsets_[10] = { GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(DescriptorProto, name_), @@ -170,14 +168,13 @@ void protobuf_AssignDesc_google_2fprotobuf_2fdescriptor_2eproto() { DescriptorProto_reflection_ = ::google::protobuf::internal::GeneratedMessageReflection::NewGeneratedMessageReflection( DescriptorProto_descriptor_, - DescriptorProto::default_instance_, + DescriptorProto::internal_default_instance(), DescriptorProto_offsets_, - GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(DescriptorProto, _has_bits_[0]), + GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(DescriptorProto, _has_bits_), -1, -1, sizeof(DescriptorProto), - GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(DescriptorProto, _internal_metadata_), - -1); + GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(DescriptorProto, _internal_metadata_)); DescriptorProto_ExtensionRange_descriptor_ = DescriptorProto_descriptor_->nested_type(0); static const int DescriptorProto_ExtensionRange_offsets_[2] = { GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(DescriptorProto_ExtensionRange, start_), @@ -186,14 +183,13 @@ void protobuf_AssignDesc_google_2fprotobuf_2fdescriptor_2eproto() { DescriptorProto_ExtensionRange_reflection_ = ::google::protobuf::internal::GeneratedMessageReflection::NewGeneratedMessageReflection( DescriptorProto_ExtensionRange_descriptor_, - DescriptorProto_ExtensionRange::default_instance_, + DescriptorProto_ExtensionRange::internal_default_instance(), DescriptorProto_ExtensionRange_offsets_, - GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(DescriptorProto_ExtensionRange, _has_bits_[0]), + GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(DescriptorProto_ExtensionRange, _has_bits_), -1, -1, sizeof(DescriptorProto_ExtensionRange), - GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(DescriptorProto_ExtensionRange, _internal_metadata_), - -1); + GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(DescriptorProto_ExtensionRange, _internal_metadata_)); DescriptorProto_ReservedRange_descriptor_ = DescriptorProto_descriptor_->nested_type(1); static const int DescriptorProto_ReservedRange_offsets_[2] = { GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(DescriptorProto_ReservedRange, start_), @@ -202,14 +198,13 @@ void protobuf_AssignDesc_google_2fprotobuf_2fdescriptor_2eproto() { DescriptorProto_ReservedRange_reflection_ = ::google::protobuf::internal::GeneratedMessageReflection::NewGeneratedMessageReflection( DescriptorProto_ReservedRange_descriptor_, - DescriptorProto_ReservedRange::default_instance_, + DescriptorProto_ReservedRange::internal_default_instance(), DescriptorProto_ReservedRange_offsets_, - GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(DescriptorProto_ReservedRange, _has_bits_[0]), + GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(DescriptorProto_ReservedRange, _has_bits_), -1, -1, sizeof(DescriptorProto_ReservedRange), - GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(DescriptorProto_ReservedRange, _internal_metadata_), - -1); + GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(DescriptorProto_ReservedRange, _internal_metadata_)); FieldDescriptorProto_descriptor_ = file->message_type(3); static const int FieldDescriptorProto_offsets_[10] = { GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(FieldDescriptorProto, name_), @@ -226,14 +221,13 @@ void protobuf_AssignDesc_google_2fprotobuf_2fdescriptor_2eproto() { FieldDescriptorProto_reflection_ = ::google::protobuf::internal::GeneratedMessageReflection::NewGeneratedMessageReflection( FieldDescriptorProto_descriptor_, - FieldDescriptorProto::default_instance_, + FieldDescriptorProto::internal_default_instance(), FieldDescriptorProto_offsets_, - GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(FieldDescriptorProto, _has_bits_[0]), + GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(FieldDescriptorProto, _has_bits_), -1, -1, sizeof(FieldDescriptorProto), - GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(FieldDescriptorProto, _internal_metadata_), - -1); + GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(FieldDescriptorProto, _internal_metadata_)); FieldDescriptorProto_Type_descriptor_ = FieldDescriptorProto_descriptor_->enum_type(0); FieldDescriptorProto_Label_descriptor_ = FieldDescriptorProto_descriptor_->enum_type(1); OneofDescriptorProto_descriptor_ = file->message_type(4); @@ -244,14 +238,13 @@ void protobuf_AssignDesc_google_2fprotobuf_2fdescriptor_2eproto() { OneofDescriptorProto_reflection_ = ::google::protobuf::internal::GeneratedMessageReflection::NewGeneratedMessageReflection( OneofDescriptorProto_descriptor_, - OneofDescriptorProto::default_instance_, + OneofDescriptorProto::internal_default_instance(), OneofDescriptorProto_offsets_, - GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(OneofDescriptorProto, _has_bits_[0]), + GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(OneofDescriptorProto, _has_bits_), -1, -1, sizeof(OneofDescriptorProto), - GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(OneofDescriptorProto, _internal_metadata_), - -1); + GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(OneofDescriptorProto, _internal_metadata_)); EnumDescriptorProto_descriptor_ = file->message_type(5); static const int EnumDescriptorProto_offsets_[3] = { GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(EnumDescriptorProto, name_), @@ -261,14 +254,13 @@ void protobuf_AssignDesc_google_2fprotobuf_2fdescriptor_2eproto() { EnumDescriptorProto_reflection_ = ::google::protobuf::internal::GeneratedMessageReflection::NewGeneratedMessageReflection( EnumDescriptorProto_descriptor_, - EnumDescriptorProto::default_instance_, + EnumDescriptorProto::internal_default_instance(), EnumDescriptorProto_offsets_, - GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(EnumDescriptorProto, _has_bits_[0]), + GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(EnumDescriptorProto, _has_bits_), -1, -1, sizeof(EnumDescriptorProto), - GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(EnumDescriptorProto, _internal_metadata_), - -1); + GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(EnumDescriptorProto, _internal_metadata_)); EnumValueDescriptorProto_descriptor_ = file->message_type(6); static const int EnumValueDescriptorProto_offsets_[3] = { GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(EnumValueDescriptorProto, name_), @@ -278,14 +270,13 @@ void protobuf_AssignDesc_google_2fprotobuf_2fdescriptor_2eproto() { EnumValueDescriptorProto_reflection_ = ::google::protobuf::internal::GeneratedMessageReflection::NewGeneratedMessageReflection( EnumValueDescriptorProto_descriptor_, - EnumValueDescriptorProto::default_instance_, + EnumValueDescriptorProto::internal_default_instance(), EnumValueDescriptorProto_offsets_, - GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(EnumValueDescriptorProto, _has_bits_[0]), + GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(EnumValueDescriptorProto, _has_bits_), -1, -1, sizeof(EnumValueDescriptorProto), - GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(EnumValueDescriptorProto, _internal_metadata_), - -1); + GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(EnumValueDescriptorProto, _internal_metadata_)); ServiceDescriptorProto_descriptor_ = file->message_type(7); static const int ServiceDescriptorProto_offsets_[3] = { GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(ServiceDescriptorProto, name_), @@ -295,14 +286,13 @@ void protobuf_AssignDesc_google_2fprotobuf_2fdescriptor_2eproto() { ServiceDescriptorProto_reflection_ = ::google::protobuf::internal::GeneratedMessageReflection::NewGeneratedMessageReflection( ServiceDescriptorProto_descriptor_, - ServiceDescriptorProto::default_instance_, + ServiceDescriptorProto::internal_default_instance(), ServiceDescriptorProto_offsets_, - GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(ServiceDescriptorProto, _has_bits_[0]), + GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(ServiceDescriptorProto, _has_bits_), -1, -1, sizeof(ServiceDescriptorProto), - GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(ServiceDescriptorProto, _internal_metadata_), - -1); + GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(ServiceDescriptorProto, _internal_metadata_)); MethodDescriptorProto_descriptor_ = file->message_type(8); static const int MethodDescriptorProto_offsets_[6] = { GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(MethodDescriptorProto, name_), @@ -315,20 +305,18 @@ void protobuf_AssignDesc_google_2fprotobuf_2fdescriptor_2eproto() { MethodDescriptorProto_reflection_ = ::google::protobuf::internal::GeneratedMessageReflection::NewGeneratedMessageReflection( MethodDescriptorProto_descriptor_, - MethodDescriptorProto::default_instance_, + MethodDescriptorProto::internal_default_instance(), MethodDescriptorProto_offsets_, - GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(MethodDescriptorProto, _has_bits_[0]), + GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(MethodDescriptorProto, _has_bits_), -1, -1, sizeof(MethodDescriptorProto), - GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(MethodDescriptorProto, _internal_metadata_), - -1); + GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(MethodDescriptorProto, _internal_metadata_)); FileOptions_descriptor_ = file->message_type(9); - static const int FileOptions_offsets_[15] = { + static const int FileOptions_offsets_[14] = { GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(FileOptions, java_package_), GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(FileOptions, java_outer_classname_), GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(FileOptions, java_multiple_files_), - GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(FileOptions, java_generate_equals_and_hash_), GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(FileOptions, java_string_check_utf8_), GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(FileOptions, optimize_for_), GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(FileOptions, go_package_), @@ -344,14 +332,13 @@ void protobuf_AssignDesc_google_2fprotobuf_2fdescriptor_2eproto() { FileOptions_reflection_ = ::google::protobuf::internal::GeneratedMessageReflection::NewGeneratedMessageReflection( FileOptions_descriptor_, - FileOptions::default_instance_, + FileOptions::internal_default_instance(), FileOptions_offsets_, - GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(FileOptions, _has_bits_[0]), + GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(FileOptions, _has_bits_), -1, GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(FileOptions, _extensions_), sizeof(FileOptions), - GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(FileOptions, _internal_metadata_), - -1); + GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(FileOptions, _internal_metadata_)); FileOptions_OptimizeMode_descriptor_ = FileOptions_descriptor_->enum_type(0); MessageOptions_descriptor_ = file->message_type(10); static const int MessageOptions_offsets_[5] = { @@ -364,14 +351,13 @@ void protobuf_AssignDesc_google_2fprotobuf_2fdescriptor_2eproto() { MessageOptions_reflection_ = ::google::protobuf::internal::GeneratedMessageReflection::NewGeneratedMessageReflection( MessageOptions_descriptor_, - MessageOptions::default_instance_, + MessageOptions::internal_default_instance(), MessageOptions_offsets_, - GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(MessageOptions, _has_bits_[0]), + GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(MessageOptions, _has_bits_), -1, GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(MessageOptions, _extensions_), sizeof(MessageOptions), - GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(MessageOptions, _internal_metadata_), - -1); + GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(MessageOptions, _internal_metadata_)); FieldOptions_descriptor_ = file->message_type(11); static const int FieldOptions_offsets_[7] = { GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(FieldOptions, ctype_), @@ -385,14 +371,13 @@ void protobuf_AssignDesc_google_2fprotobuf_2fdescriptor_2eproto() { FieldOptions_reflection_ = ::google::protobuf::internal::GeneratedMessageReflection::NewGeneratedMessageReflection( FieldOptions_descriptor_, - FieldOptions::default_instance_, + FieldOptions::internal_default_instance(), FieldOptions_offsets_, - GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(FieldOptions, _has_bits_[0]), + GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(FieldOptions, _has_bits_), -1, GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(FieldOptions, _extensions_), sizeof(FieldOptions), - GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(FieldOptions, _internal_metadata_), - -1); + GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(FieldOptions, _internal_metadata_)); FieldOptions_CType_descriptor_ = FieldOptions_descriptor_->enum_type(0); FieldOptions_JSType_descriptor_ = FieldOptions_descriptor_->enum_type(1); OneofOptions_descriptor_ = file->message_type(12); @@ -402,14 +387,13 @@ void protobuf_AssignDesc_google_2fprotobuf_2fdescriptor_2eproto() { OneofOptions_reflection_ = ::google::protobuf::internal::GeneratedMessageReflection::NewGeneratedMessageReflection( OneofOptions_descriptor_, - OneofOptions::default_instance_, + OneofOptions::internal_default_instance(), OneofOptions_offsets_, - GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(OneofOptions, _has_bits_[0]), + GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(OneofOptions, _has_bits_), -1, GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(OneofOptions, _extensions_), sizeof(OneofOptions), - GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(OneofOptions, _internal_metadata_), - -1); + GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(OneofOptions, _internal_metadata_)); EnumOptions_descriptor_ = file->message_type(13); static const int EnumOptions_offsets_[3] = { GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(EnumOptions, allow_alias_), @@ -419,14 +403,13 @@ void protobuf_AssignDesc_google_2fprotobuf_2fdescriptor_2eproto() { EnumOptions_reflection_ = ::google::protobuf::internal::GeneratedMessageReflection::NewGeneratedMessageReflection( EnumOptions_descriptor_, - EnumOptions::default_instance_, + EnumOptions::internal_default_instance(), EnumOptions_offsets_, - GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(EnumOptions, _has_bits_[0]), + GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(EnumOptions, _has_bits_), -1, GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(EnumOptions, _extensions_), sizeof(EnumOptions), - GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(EnumOptions, _internal_metadata_), - -1); + GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(EnumOptions, _internal_metadata_)); EnumValueOptions_descriptor_ = file->message_type(14); static const int EnumValueOptions_offsets_[2] = { GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(EnumValueOptions, deprecated_), @@ -435,14 +418,13 @@ void protobuf_AssignDesc_google_2fprotobuf_2fdescriptor_2eproto() { EnumValueOptions_reflection_ = ::google::protobuf::internal::GeneratedMessageReflection::NewGeneratedMessageReflection( EnumValueOptions_descriptor_, - EnumValueOptions::default_instance_, + EnumValueOptions::internal_default_instance(), EnumValueOptions_offsets_, - GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(EnumValueOptions, _has_bits_[0]), + GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(EnumValueOptions, _has_bits_), -1, GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(EnumValueOptions, _extensions_), sizeof(EnumValueOptions), - GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(EnumValueOptions, _internal_metadata_), - -1); + GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(EnumValueOptions, _internal_metadata_)); ServiceOptions_descriptor_ = file->message_type(15); static const int ServiceOptions_offsets_[2] = { GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(ServiceOptions, deprecated_), @@ -451,14 +433,13 @@ void protobuf_AssignDesc_google_2fprotobuf_2fdescriptor_2eproto() { ServiceOptions_reflection_ = ::google::protobuf::internal::GeneratedMessageReflection::NewGeneratedMessageReflection( ServiceOptions_descriptor_, - ServiceOptions::default_instance_, + ServiceOptions::internal_default_instance(), ServiceOptions_offsets_, - GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(ServiceOptions, _has_bits_[0]), + GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(ServiceOptions, _has_bits_), -1, GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(ServiceOptions, _extensions_), sizeof(ServiceOptions), - GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(ServiceOptions, _internal_metadata_), - -1); + GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(ServiceOptions, _internal_metadata_)); MethodOptions_descriptor_ = file->message_type(16); static const int MethodOptions_offsets_[2] = { GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(MethodOptions, deprecated_), @@ -467,14 +448,13 @@ void protobuf_AssignDesc_google_2fprotobuf_2fdescriptor_2eproto() { MethodOptions_reflection_ = ::google::protobuf::internal::GeneratedMessageReflection::NewGeneratedMessageReflection( MethodOptions_descriptor_, - MethodOptions::default_instance_, + MethodOptions::internal_default_instance(), MethodOptions_offsets_, - GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(MethodOptions, _has_bits_[0]), + GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(MethodOptions, _has_bits_), -1, GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(MethodOptions, _extensions_), sizeof(MethodOptions), - GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(MethodOptions, _internal_metadata_), - -1); + GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(MethodOptions, _internal_metadata_)); UninterpretedOption_descriptor_ = file->message_type(17); static const int UninterpretedOption_offsets_[7] = { GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(UninterpretedOption, name_), @@ -488,14 +468,13 @@ void protobuf_AssignDesc_google_2fprotobuf_2fdescriptor_2eproto() { UninterpretedOption_reflection_ = ::google::protobuf::internal::GeneratedMessageReflection::NewGeneratedMessageReflection( UninterpretedOption_descriptor_, - UninterpretedOption::default_instance_, + UninterpretedOption::internal_default_instance(), UninterpretedOption_offsets_, - GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(UninterpretedOption, _has_bits_[0]), + GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(UninterpretedOption, _has_bits_), -1, -1, sizeof(UninterpretedOption), - GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(UninterpretedOption, _internal_metadata_), - -1); + GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(UninterpretedOption, _internal_metadata_)); UninterpretedOption_NamePart_descriptor_ = UninterpretedOption_descriptor_->nested_type(0); static const int UninterpretedOption_NamePart_offsets_[2] = { GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(UninterpretedOption_NamePart, name_part_), @@ -504,14 +483,13 @@ void protobuf_AssignDesc_google_2fprotobuf_2fdescriptor_2eproto() { UninterpretedOption_NamePart_reflection_ = ::google::protobuf::internal::GeneratedMessageReflection::NewGeneratedMessageReflection( UninterpretedOption_NamePart_descriptor_, - UninterpretedOption_NamePart::default_instance_, + UninterpretedOption_NamePart::internal_default_instance(), UninterpretedOption_NamePart_offsets_, - GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(UninterpretedOption_NamePart, _has_bits_[0]), + GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(UninterpretedOption_NamePart, _has_bits_), -1, -1, sizeof(UninterpretedOption_NamePart), - GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(UninterpretedOption_NamePart, _internal_metadata_), - -1); + GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(UninterpretedOption_NamePart, _internal_metadata_)); SourceCodeInfo_descriptor_ = file->message_type(18); static const int SourceCodeInfo_offsets_[1] = { GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(SourceCodeInfo, location_), @@ -519,14 +497,13 @@ void protobuf_AssignDesc_google_2fprotobuf_2fdescriptor_2eproto() { SourceCodeInfo_reflection_ = ::google::protobuf::internal::GeneratedMessageReflection::NewGeneratedMessageReflection( SourceCodeInfo_descriptor_, - SourceCodeInfo::default_instance_, + SourceCodeInfo::internal_default_instance(), SourceCodeInfo_offsets_, - GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(SourceCodeInfo, _has_bits_[0]), + GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(SourceCodeInfo, _has_bits_), -1, -1, sizeof(SourceCodeInfo), - GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(SourceCodeInfo, _internal_metadata_), - -1); + GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(SourceCodeInfo, _internal_metadata_)); SourceCodeInfo_Location_descriptor_ = SourceCodeInfo_descriptor_->nested_type(0); static const int SourceCodeInfo_Location_offsets_[5] = { GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(SourceCodeInfo_Location, path_), @@ -538,14 +515,13 @@ void protobuf_AssignDesc_google_2fprotobuf_2fdescriptor_2eproto() { SourceCodeInfo_Location_reflection_ = ::google::protobuf::internal::GeneratedMessageReflection::NewGeneratedMessageReflection( SourceCodeInfo_Location_descriptor_, - SourceCodeInfo_Location::default_instance_, + SourceCodeInfo_Location::internal_default_instance(), SourceCodeInfo_Location_offsets_, - GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(SourceCodeInfo_Location, _has_bits_[0]), + GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(SourceCodeInfo_Location, _has_bits_), -1, -1, sizeof(SourceCodeInfo_Location), - GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(SourceCodeInfo_Location, _internal_metadata_), - -1); + GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(SourceCodeInfo_Location, _internal_metadata_)); GeneratedCodeInfo_descriptor_ = file->message_type(19); static const int GeneratedCodeInfo_offsets_[1] = { GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(GeneratedCodeInfo, annotation_), @@ -553,14 +529,13 @@ void protobuf_AssignDesc_google_2fprotobuf_2fdescriptor_2eproto() { GeneratedCodeInfo_reflection_ = ::google::protobuf::internal::GeneratedMessageReflection::NewGeneratedMessageReflection( GeneratedCodeInfo_descriptor_, - GeneratedCodeInfo::default_instance_, + GeneratedCodeInfo::internal_default_instance(), GeneratedCodeInfo_offsets_, - GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(GeneratedCodeInfo, _has_bits_[0]), + GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(GeneratedCodeInfo, _has_bits_), -1, -1, sizeof(GeneratedCodeInfo), - GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(GeneratedCodeInfo, _internal_metadata_), - -1); + GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(GeneratedCodeInfo, _internal_metadata_)); GeneratedCodeInfo_Annotation_descriptor_ = GeneratedCodeInfo_descriptor_->nested_type(0); static const int GeneratedCodeInfo_Annotation_offsets_[4] = { GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(GeneratedCodeInfo_Annotation, path_), @@ -571,20 +546,19 @@ void protobuf_AssignDesc_google_2fprotobuf_2fdescriptor_2eproto() { GeneratedCodeInfo_Annotation_reflection_ = ::google::protobuf::internal::GeneratedMessageReflection::NewGeneratedMessageReflection( GeneratedCodeInfo_Annotation_descriptor_, - GeneratedCodeInfo_Annotation::default_instance_, + GeneratedCodeInfo_Annotation::internal_default_instance(), GeneratedCodeInfo_Annotation_offsets_, - GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(GeneratedCodeInfo_Annotation, _has_bits_[0]), + GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(GeneratedCodeInfo_Annotation, _has_bits_), -1, -1, sizeof(GeneratedCodeInfo_Annotation), - GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(GeneratedCodeInfo_Annotation, _internal_metadata_), - -1); + GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(GeneratedCodeInfo_Annotation, _internal_metadata_)); } namespace { GOOGLE_PROTOBUF_DECLARE_ONCE(protobuf_AssignDescriptors_once_); -inline void protobuf_AssignDescriptorsOnce() { +void protobuf_AssignDescriptorsOnce() { ::google::protobuf::GoogleOnceInit(&protobuf_AssignDescriptors_once_, &protobuf_AssignDesc_google_2fprotobuf_2fdescriptor_2eproto); } @@ -593,119 +567,164 @@ void protobuf_RegisterTypes(const ::std::string&) GOOGLE_ATTRIBUTE_COLD; void protobuf_RegisterTypes(const ::std::string&) { protobuf_AssignDescriptorsOnce(); ::google::protobuf::MessageFactory::InternalRegisterGeneratedMessage( - FileDescriptorSet_descriptor_, &FileDescriptorSet::default_instance()); + FileDescriptorSet_descriptor_, FileDescriptorSet::internal_default_instance()); ::google::protobuf::MessageFactory::InternalRegisterGeneratedMessage( - FileDescriptorProto_descriptor_, &FileDescriptorProto::default_instance()); + FileDescriptorProto_descriptor_, FileDescriptorProto::internal_default_instance()); ::google::protobuf::MessageFactory::InternalRegisterGeneratedMessage( - DescriptorProto_descriptor_, &DescriptorProto::default_instance()); + DescriptorProto_descriptor_, DescriptorProto::internal_default_instance()); ::google::protobuf::MessageFactory::InternalRegisterGeneratedMessage( - DescriptorProto_ExtensionRange_descriptor_, &DescriptorProto_ExtensionRange::default_instance()); + DescriptorProto_ExtensionRange_descriptor_, DescriptorProto_ExtensionRange::internal_default_instance()); ::google::protobuf::MessageFactory::InternalRegisterGeneratedMessage( - DescriptorProto_ReservedRange_descriptor_, &DescriptorProto_ReservedRange::default_instance()); + DescriptorProto_ReservedRange_descriptor_, DescriptorProto_ReservedRange::internal_default_instance()); ::google::protobuf::MessageFactory::InternalRegisterGeneratedMessage( - FieldDescriptorProto_descriptor_, &FieldDescriptorProto::default_instance()); + FieldDescriptorProto_descriptor_, FieldDescriptorProto::internal_default_instance()); ::google::protobuf::MessageFactory::InternalRegisterGeneratedMessage( - OneofDescriptorProto_descriptor_, &OneofDescriptorProto::default_instance()); + OneofDescriptorProto_descriptor_, OneofDescriptorProto::internal_default_instance()); ::google::protobuf::MessageFactory::InternalRegisterGeneratedMessage( - EnumDescriptorProto_descriptor_, &EnumDescriptorProto::default_instance()); + EnumDescriptorProto_descriptor_, EnumDescriptorProto::internal_default_instance()); ::google::protobuf::MessageFactory::InternalRegisterGeneratedMessage( - EnumValueDescriptorProto_descriptor_, &EnumValueDescriptorProto::default_instance()); + EnumValueDescriptorProto_descriptor_, EnumValueDescriptorProto::internal_default_instance()); ::google::protobuf::MessageFactory::InternalRegisterGeneratedMessage( - ServiceDescriptorProto_descriptor_, &ServiceDescriptorProto::default_instance()); + ServiceDescriptorProto_descriptor_, ServiceDescriptorProto::internal_default_instance()); ::google::protobuf::MessageFactory::InternalRegisterGeneratedMessage( - MethodDescriptorProto_descriptor_, &MethodDescriptorProto::default_instance()); + MethodDescriptorProto_descriptor_, MethodDescriptorProto::internal_default_instance()); ::google::protobuf::MessageFactory::InternalRegisterGeneratedMessage( - FileOptions_descriptor_, &FileOptions::default_instance()); + FileOptions_descriptor_, FileOptions::internal_default_instance()); ::google::protobuf::MessageFactory::InternalRegisterGeneratedMessage( - MessageOptions_descriptor_, &MessageOptions::default_instance()); + MessageOptions_descriptor_, MessageOptions::internal_default_instance()); ::google::protobuf::MessageFactory::InternalRegisterGeneratedMessage( - FieldOptions_descriptor_, &FieldOptions::default_instance()); + FieldOptions_descriptor_, FieldOptions::internal_default_instance()); ::google::protobuf::MessageFactory::InternalRegisterGeneratedMessage( - OneofOptions_descriptor_, &OneofOptions::default_instance()); + OneofOptions_descriptor_, OneofOptions::internal_default_instance()); ::google::protobuf::MessageFactory::InternalRegisterGeneratedMessage( - EnumOptions_descriptor_, &EnumOptions::default_instance()); + EnumOptions_descriptor_, EnumOptions::internal_default_instance()); ::google::protobuf::MessageFactory::InternalRegisterGeneratedMessage( - EnumValueOptions_descriptor_, &EnumValueOptions::default_instance()); + EnumValueOptions_descriptor_, EnumValueOptions::internal_default_instance()); ::google::protobuf::MessageFactory::InternalRegisterGeneratedMessage( - ServiceOptions_descriptor_, &ServiceOptions::default_instance()); + ServiceOptions_descriptor_, ServiceOptions::internal_default_instance()); ::google::protobuf::MessageFactory::InternalRegisterGeneratedMessage( - MethodOptions_descriptor_, &MethodOptions::default_instance()); + MethodOptions_descriptor_, MethodOptions::internal_default_instance()); ::google::protobuf::MessageFactory::InternalRegisterGeneratedMessage( - UninterpretedOption_descriptor_, &UninterpretedOption::default_instance()); + UninterpretedOption_descriptor_, UninterpretedOption::internal_default_instance()); ::google::protobuf::MessageFactory::InternalRegisterGeneratedMessage( - UninterpretedOption_NamePart_descriptor_, &UninterpretedOption_NamePart::default_instance()); + UninterpretedOption_NamePart_descriptor_, UninterpretedOption_NamePart::internal_default_instance()); ::google::protobuf::MessageFactory::InternalRegisterGeneratedMessage( - SourceCodeInfo_descriptor_, &SourceCodeInfo::default_instance()); + SourceCodeInfo_descriptor_, SourceCodeInfo::internal_default_instance()); ::google::protobuf::MessageFactory::InternalRegisterGeneratedMessage( - SourceCodeInfo_Location_descriptor_, &SourceCodeInfo_Location::default_instance()); + SourceCodeInfo_Location_descriptor_, SourceCodeInfo_Location::internal_default_instance()); ::google::protobuf::MessageFactory::InternalRegisterGeneratedMessage( - GeneratedCodeInfo_descriptor_, &GeneratedCodeInfo::default_instance()); + GeneratedCodeInfo_descriptor_, GeneratedCodeInfo::internal_default_instance()); ::google::protobuf::MessageFactory::InternalRegisterGeneratedMessage( - GeneratedCodeInfo_Annotation_descriptor_, &GeneratedCodeInfo_Annotation::default_instance()); + GeneratedCodeInfo_Annotation_descriptor_, GeneratedCodeInfo_Annotation::internal_default_instance()); } } // namespace void protobuf_ShutdownFile_google_2fprotobuf_2fdescriptor_2eproto() { - delete FileDescriptorSet::default_instance_; delete FileDescriptorSet_reflection_; - delete FileDescriptorProto::default_instance_; delete FileDescriptorProto_reflection_; - delete DescriptorProto::default_instance_; delete DescriptorProto_reflection_; - delete DescriptorProto_ExtensionRange::default_instance_; delete DescriptorProto_ExtensionRange_reflection_; - delete DescriptorProto_ReservedRange::default_instance_; delete DescriptorProto_ReservedRange_reflection_; - delete FieldDescriptorProto::default_instance_; delete FieldDescriptorProto_reflection_; - delete OneofDescriptorProto::default_instance_; delete OneofDescriptorProto_reflection_; - delete EnumDescriptorProto::default_instance_; delete EnumDescriptorProto_reflection_; - delete EnumValueDescriptorProto::default_instance_; delete EnumValueDescriptorProto_reflection_; - delete ServiceDescriptorProto::default_instance_; delete ServiceDescriptorProto_reflection_; - delete MethodDescriptorProto::default_instance_; delete MethodDescriptorProto_reflection_; - delete FileOptions::default_instance_; delete FileOptions_reflection_; - delete MessageOptions::default_instance_; delete MessageOptions_reflection_; - delete FieldOptions::default_instance_; delete FieldOptions_reflection_; - delete OneofOptions::default_instance_; delete OneofOptions_reflection_; - delete EnumOptions::default_instance_; delete EnumOptions_reflection_; - delete EnumValueOptions::default_instance_; delete EnumValueOptions_reflection_; - delete ServiceOptions::default_instance_; delete ServiceOptions_reflection_; - delete MethodOptions::default_instance_; delete MethodOptions_reflection_; - delete UninterpretedOption::default_instance_; delete UninterpretedOption_reflection_; - delete UninterpretedOption_NamePart::default_instance_; delete UninterpretedOption_NamePart_reflection_; - delete SourceCodeInfo::default_instance_; delete SourceCodeInfo_reflection_; - delete SourceCodeInfo_Location::default_instance_; delete SourceCodeInfo_Location_reflection_; - delete GeneratedCodeInfo::default_instance_; delete GeneratedCodeInfo_reflection_; - delete GeneratedCodeInfo_Annotation::default_instance_; delete GeneratedCodeInfo_Annotation_reflection_; } -void protobuf_AddDesc_google_2fprotobuf_2fdescriptor_2eproto() GOOGLE_ATTRIBUTE_COLD; -void protobuf_AddDesc_google_2fprotobuf_2fdescriptor_2eproto() { - static bool already_here = false; - if (already_here) return; - already_here = true; +void protobuf_InitDefaults_google_2fprotobuf_2fdescriptor_2eproto_impl() { + GOOGLE_PROTOBUF_VERIFY_VERSION; + + FileDescriptorSet::default_instance_.DefaultConstruct(); + ::google::protobuf::internal::GetEmptyString(); + FileDescriptorProto::default_instance_.DefaultConstruct(); + ::google::protobuf::internal::GetEmptyString(); + DescriptorProto::default_instance_.DefaultConstruct(); + DescriptorProto_ExtensionRange::default_instance_.DefaultConstruct(); + DescriptorProto_ReservedRange::default_instance_.DefaultConstruct(); + ::google::protobuf::internal::GetEmptyString(); + FieldDescriptorProto::default_instance_.DefaultConstruct(); + ::google::protobuf::internal::GetEmptyString(); + OneofDescriptorProto::default_instance_.DefaultConstruct(); + ::google::protobuf::internal::GetEmptyString(); + EnumDescriptorProto::default_instance_.DefaultConstruct(); + ::google::protobuf::internal::GetEmptyString(); + EnumValueDescriptorProto::default_instance_.DefaultConstruct(); + ::google::protobuf::internal::GetEmptyString(); + ServiceDescriptorProto::default_instance_.DefaultConstruct(); + ::google::protobuf::internal::GetEmptyString(); + MethodDescriptorProto::default_instance_.DefaultConstruct(); + ::google::protobuf::internal::GetEmptyString(); + FileOptions::default_instance_.DefaultConstruct(); + MessageOptions::default_instance_.DefaultConstruct(); + FieldOptions::default_instance_.DefaultConstruct(); + OneofOptions::default_instance_.DefaultConstruct(); + EnumOptions::default_instance_.DefaultConstruct(); + EnumValueOptions::default_instance_.DefaultConstruct(); + ServiceOptions::default_instance_.DefaultConstruct(); + MethodOptions::default_instance_.DefaultConstruct(); + ::google::protobuf::internal::GetEmptyString(); + UninterpretedOption::default_instance_.DefaultConstruct(); + ::google::protobuf::internal::GetEmptyString(); + UninterpretedOption_NamePart::default_instance_.DefaultConstruct(); + SourceCodeInfo::default_instance_.DefaultConstruct(); + ::google::protobuf::internal::GetEmptyString(); + SourceCodeInfo_Location::default_instance_.DefaultConstruct(); + GeneratedCodeInfo::default_instance_.DefaultConstruct(); + ::google::protobuf::internal::GetEmptyString(); + GeneratedCodeInfo_Annotation::default_instance_.DefaultConstruct(); + FileDescriptorSet::default_instance_.get_mutable()->InitAsDefaultInstance(); + FileDescriptorProto::default_instance_.get_mutable()->InitAsDefaultInstance(); + DescriptorProto::default_instance_.get_mutable()->InitAsDefaultInstance(); + DescriptorProto_ExtensionRange::default_instance_.get_mutable()->InitAsDefaultInstance(); + DescriptorProto_ReservedRange::default_instance_.get_mutable()->InitAsDefaultInstance(); + FieldDescriptorProto::default_instance_.get_mutable()->InitAsDefaultInstance(); + OneofDescriptorProto::default_instance_.get_mutable()->InitAsDefaultInstance(); + EnumDescriptorProto::default_instance_.get_mutable()->InitAsDefaultInstance(); + EnumValueDescriptorProto::default_instance_.get_mutable()->InitAsDefaultInstance(); + ServiceDescriptorProto::default_instance_.get_mutable()->InitAsDefaultInstance(); + MethodDescriptorProto::default_instance_.get_mutable()->InitAsDefaultInstance(); + FileOptions::default_instance_.get_mutable()->InitAsDefaultInstance(); + MessageOptions::default_instance_.get_mutable()->InitAsDefaultInstance(); + FieldOptions::default_instance_.get_mutable()->InitAsDefaultInstance(); + OneofOptions::default_instance_.get_mutable()->InitAsDefaultInstance(); + EnumOptions::default_instance_.get_mutable()->InitAsDefaultInstance(); + EnumValueOptions::default_instance_.get_mutable()->InitAsDefaultInstance(); + ServiceOptions::default_instance_.get_mutable()->InitAsDefaultInstance(); + MethodOptions::default_instance_.get_mutable()->InitAsDefaultInstance(); + UninterpretedOption::default_instance_.get_mutable()->InitAsDefaultInstance(); + UninterpretedOption_NamePart::default_instance_.get_mutable()->InitAsDefaultInstance(); + SourceCodeInfo::default_instance_.get_mutable()->InitAsDefaultInstance(); + SourceCodeInfo_Location::default_instance_.get_mutable()->InitAsDefaultInstance(); + GeneratedCodeInfo::default_instance_.get_mutable()->InitAsDefaultInstance(); + GeneratedCodeInfo_Annotation::default_instance_.get_mutable()->InitAsDefaultInstance(); +} + +GOOGLE_PROTOBUF_DECLARE_ONCE(protobuf_InitDefaults_google_2fprotobuf_2fdescriptor_2eproto_once_); +void protobuf_InitDefaults_google_2fprotobuf_2fdescriptor_2eproto() { + ::google::protobuf::GoogleOnceInit(&protobuf_InitDefaults_google_2fprotobuf_2fdescriptor_2eproto_once_, + &protobuf_InitDefaults_google_2fprotobuf_2fdescriptor_2eproto_impl); +} +void protobuf_AddDesc_google_2fprotobuf_2fdescriptor_2eproto_impl() { GOOGLE_PROTOBUF_VERIFY_VERSION; + protobuf_InitDefaults_google_2fprotobuf_2fdescriptor_2eproto(); ::google::protobuf::DescriptorPool::InternalAddGeneratedFile( "\n google/protobuf/descriptor.proto\022\017goog" "le.protobuf\"G\n\021FileDescriptorSet\0222\n\004file" @@ -772,29 +791,28 @@ void protobuf_AddDesc_google_2fprotobuf_2fdescriptor_2eproto() { "\n\013output_type\030\003 \001(\t\022/\n\007options\030\004 \001(\0132\036.g" "oogle.protobuf.MethodOptions\022\037\n\020client_s" "treaming\030\005 \001(\010:\005false\022\037\n\020server_streamin" - "g\030\006 \001(\010:\005false\"\207\005\n\013FileOptions\022\024\n\014java_p" + "g\030\006 \001(\010:\005false\"\331\004\n\013FileOptions\022\024\n\014java_p" "ackage\030\001 \001(\t\022\034\n\024java_outer_classname\030\010 \001" - "(\t\022\"\n\023java_multiple_files\030\n \001(\010:\005false\022," - "\n\035java_generate_equals_and_hash\030\024 \001(\010:\005f" - "alse\022%\n\026java_string_check_utf8\030\033 \001(\010:\005fa" - "lse\022F\n\014optimize_for\030\t \001(\0162).google.proto" - "buf.FileOptions.OptimizeMode:\005SPEED\022\022\n\ng" - "o_package\030\013 \001(\t\022\"\n\023cc_generic_services\030\020" - " \001(\010:\005false\022$\n\025java_generic_services\030\021 \001" - "(\010:\005false\022\"\n\023py_generic_services\030\022 \001(\010:\005" - "false\022\031\n\ndeprecated\030\027 \001(\010:\005false\022\037\n\020cc_e" - "nable_arenas\030\037 \001(\010:\005false\022\031\n\021objc_class_" - "prefix\030$ \001(\t\022\030\n\020csharp_namespace\030% \001(\t\022C" - "\n\024uninterpreted_option\030\347\007 \003(\0132$.google.p" - "rotobuf.UninterpretedOption\":\n\014OptimizeM" - "ode\022\t\n\005SPEED\020\001\022\r\n\tCODE_SIZE\020\002\022\020\n\014LITE_RU" - "NTIME\020\003*\t\010\350\007\020\200\200\200\200\002J\004\010&\020\'\"\346\001\n\016MessageOpti" - "ons\022&\n\027message_set_wire_format\030\001 \001(\010:\005fa" - "lse\022.\n\037no_standard_descriptor_accessor\030\002" - " \001(\010:\005false\022\031\n\ndeprecated\030\003 \001(\010:\005false\022\021" - "\n\tmap_entry\030\007 \001(\010\022C\n\024uninterpreted_optio" - "n\030\347\007 \003(\0132$.google.protobuf.Uninterpreted" - "Option*\t\010\350\007\020\200\200\200\200\002\"\230\003\n\014FieldOptions\022:\n\005ct" + "(\t\022\"\n\023java_multiple_files\030\n \001(\010:\005false\022%" + "\n\026java_string_check_utf8\030\033 \001(\010:\005false\022F\n" + "\014optimize_for\030\t \001(\0162).google.protobuf.Fi" + "leOptions.OptimizeMode:\005SPEED\022\022\n\ngo_pack" + "age\030\013 \001(\t\022\"\n\023cc_generic_services\030\020 \001(\010:\005" + "false\022$\n\025java_generic_services\030\021 \001(\010:\005fa" + "lse\022\"\n\023py_generic_services\030\022 \001(\010:\005false\022" + "\031\n\ndeprecated\030\027 \001(\010:\005false\022\037\n\020cc_enable_" + "arenas\030\037 \001(\010:\005false\022\031\n\021objc_class_prefix" + "\030$ \001(\t\022\030\n\020csharp_namespace\030% \001(\t\022C\n\024unin" + "terpreted_option\030\347\007 \003(\0132$.google.protobu" + "f.UninterpretedOption\":\n\014OptimizeMode\022\t\n" + "\005SPEED\020\001\022\r\n\tCODE_SIZE\020\002\022\020\n\014LITE_RUNTIME\020" + "\003*\t\010\350\007\020\200\200\200\200\002J\004\010&\020\'\"\354\001\n\016MessageOptions\022&\n" + "\027message_set_wire_format\030\001 \001(\010:\005false\022.\n" + "\037no_standard_descriptor_accessor\030\002 \001(\010:\005" + "false\022\031\n\ndeprecated\030\003 \001(\010:\005false\022\021\n\tmap_" + "entry\030\007 \001(\010\022C\n\024uninterpreted_option\030\347\007 \003" + "(\0132$.google.protobuf.UninterpretedOption" + "*\t\010\350\007\020\200\200\200\200\002J\004\010\010\020\t\"\236\003\n\014FieldOptions\022:\n\005ct" "ype\030\001 \001(\0162#.google.protobuf.FieldOptions" ".CType:\006STRING\022\016\n\006packed\030\002 \001(\010\022\?\n\006jstype" "\030\006 \001(\0162$.google.protobuf.FieldOptions.JS" @@ -804,97 +822,52 @@ void protobuf_AddDesc_google_2fprotobuf_2fdescriptor_2eproto() { "ogle.protobuf.UninterpretedOption\"/\n\005CTy" "pe\022\n\n\006STRING\020\000\022\010\n\004CORD\020\001\022\020\n\014STRING_PIECE" "\020\002\"5\n\006JSType\022\r\n\tJS_NORMAL\020\000\022\r\n\tJS_STRING" - "\020\001\022\r\n\tJS_NUMBER\020\002*\t\010\350\007\020\200\200\200\200\002\"^\n\014OneofOpt" - "ions\022C\n\024uninterpreted_option\030\347\007 \003(\0132$.go" - "ogle.protobuf.UninterpretedOption*\t\010\350\007\020\200" - "\200\200\200\002\"\215\001\n\013EnumOptions\022\023\n\013allow_alias\030\002 \001(" - "\010\022\031\n\ndeprecated\030\003 \001(\010:\005false\022C\n\024uninterp" - "reted_option\030\347\007 \003(\0132$.google.protobuf.Un" - "interpretedOption*\t\010\350\007\020\200\200\200\200\002\"}\n\020EnumValu" - "eOptions\022\031\n\ndeprecated\030\001 \001(\010:\005false\022C\n\024u" - "ninterpreted_option\030\347\007 \003(\0132$.google.prot" - "obuf.UninterpretedOption*\t\010\350\007\020\200\200\200\200\002\"{\n\016S" - "erviceOptions\022\031\n\ndeprecated\030! \001(\010:\005false" - "\022C\n\024uninterpreted_option\030\347\007 \003(\0132$.google" - ".protobuf.UninterpretedOption*\t\010\350\007\020\200\200\200\200\002" - "\"z\n\rMethodOptions\022\031\n\ndeprecated\030! \001(\010:\005f" - "alse\022C\n\024uninterpreted_option\030\347\007 \003(\0132$.go" - "ogle.protobuf.UninterpretedOption*\t\010\350\007\020\200" - "\200\200\200\002\"\236\002\n\023UninterpretedOption\022;\n\004name\030\002 \003" - "(\0132-.google.protobuf.UninterpretedOption" - ".NamePart\022\030\n\020identifier_value\030\003 \001(\t\022\032\n\022p" - "ositive_int_value\030\004 \001(\004\022\032\n\022negative_int_" - "value\030\005 \001(\003\022\024\n\014double_value\030\006 \001(\001\022\024\n\014str" - "ing_value\030\007 \001(\014\022\027\n\017aggregate_value\030\010 \001(\t" - "\0323\n\010NamePart\022\021\n\tname_part\030\001 \002(\t\022\024\n\014is_ex" - "tension\030\002 \002(\010\"\325\001\n\016SourceCodeInfo\022:\n\010loca" - "tion\030\001 \003(\0132(.google.protobuf.SourceCodeI" - "nfo.Location\032\206\001\n\010Location\022\020\n\004path\030\001 \003(\005B" - "\002\020\001\022\020\n\004span\030\002 \003(\005B\002\020\001\022\030\n\020leading_comment" - "s\030\003 \001(\t\022\031\n\021trailing_comments\030\004 \001(\t\022!\n\031le" - "ading_detached_comments\030\006 \003(\t\"\247\001\n\021Genera" - "tedCodeInfo\022A\n\nannotation\030\001 \003(\0132-.google" - ".protobuf.GeneratedCodeInfo.Annotation\032O" - "\n\nAnnotation\022\020\n\004path\030\001 \003(\005B\002\020\001\022\023\n\013source" - "_file\030\002 \001(\t\022\r\n\005begin\030\003 \001(\005\022\013\n\003end\030\004 \001(\005B" - "[\n\023com.google.protobufB\020DescriptorProtos" - "H\001Z\ndescriptor\240\001\001\242\002\003GPB\252\002\032Google.Protobu" - "f.Reflection", 5292); + "\020\001\022\r\n\tJS_NUMBER\020\002*\t\010\350\007\020\200\200\200\200\002J\004\010\004\020\005\"^\n\014On" + "eofOptions\022C\n\024uninterpreted_option\030\347\007 \003(" + "\0132$.google.protobuf.UninterpretedOption*" + "\t\010\350\007\020\200\200\200\200\002\"\215\001\n\013EnumOptions\022\023\n\013allow_alia" + "s\030\002 \001(\010\022\031\n\ndeprecated\030\003 \001(\010:\005false\022C\n\024un" + "interpreted_option\030\347\007 \003(\0132$.google.proto" + "buf.UninterpretedOption*\t\010\350\007\020\200\200\200\200\002\"}\n\020En" + "umValueOptions\022\031\n\ndeprecated\030\001 \001(\010:\005fals" + "e\022C\n\024uninterpreted_option\030\347\007 \003(\0132$.googl" + "e.protobuf.UninterpretedOption*\t\010\350\007\020\200\200\200\200" + "\002\"{\n\016ServiceOptions\022\031\n\ndeprecated\030! \001(\010:" + "\005false\022C\n\024uninterpreted_option\030\347\007 \003(\0132$." + "google.protobuf.UninterpretedOption*\t\010\350\007" + "\020\200\200\200\200\002\"z\n\rMethodOptions\022\031\n\ndeprecated\030! " + "\001(\010:\005false\022C\n\024uninterpreted_option\030\347\007 \003(" + "\0132$.google.protobuf.UninterpretedOption*" + "\t\010\350\007\020\200\200\200\200\002\"\236\002\n\023UninterpretedOption\022;\n\004na" + "me\030\002 \003(\0132-.google.protobuf.Uninterpreted" + "Option.NamePart\022\030\n\020identifier_value\030\003 \001(" + "\t\022\032\n\022positive_int_value\030\004 \001(\004\022\032\n\022negativ" + "e_int_value\030\005 \001(\003\022\024\n\014double_value\030\006 \001(\001\022" + "\024\n\014string_value\030\007 \001(\014\022\027\n\017aggregate_value" + "\030\010 \001(\t\0323\n\010NamePart\022\021\n\tname_part\030\001 \002(\t\022\024\n" + "\014is_extension\030\002 \002(\010\"\325\001\n\016SourceCodeInfo\022:" + "\n\010location\030\001 \003(\0132(.google.protobuf.Sourc" + "eCodeInfo.Location\032\206\001\n\010Location\022\020\n\004path\030" + "\001 \003(\005B\002\020\001\022\020\n\004span\030\002 \003(\005B\002\020\001\022\030\n\020leading_c" + "omments\030\003 \001(\t\022\031\n\021trailing_comments\030\004 \001(\t" + "\022!\n\031leading_detached_comments\030\006 \003(\t\"\247\001\n\021" + "GeneratedCodeInfo\022A\n\nannotation\030\001 \003(\0132-." + "google.protobuf.GeneratedCodeInfo.Annota" + "tion\032O\n\nAnnotation\022\020\n\004path\030\001 \003(\005B\002\020\001\022\023\n\013" + "source_file\030\002 \001(\t\022\r\n\005begin\030\003 \001(\005\022\013\n\003end\030" + "\004 \001(\005BX\n\023com.google.protobufB\020Descriptor" + "ProtosH\001Z\ndescriptor\242\002\003GPB\252\002\032Google.Prot" + "obuf.Reflection", 5255); ::google::protobuf::MessageFactory::InternalRegisterGeneratedFile( "google/protobuf/descriptor.proto", &protobuf_RegisterTypes); - FileDescriptorSet::default_instance_ = new FileDescriptorSet(); - FileDescriptorProto::default_instance_ = new FileDescriptorProto(); - DescriptorProto::default_instance_ = new DescriptorProto(); - DescriptorProto_ExtensionRange::default_instance_ = new DescriptorProto_ExtensionRange(); - DescriptorProto_ReservedRange::default_instance_ = new DescriptorProto_ReservedRange(); - FieldDescriptorProto::default_instance_ = new FieldDescriptorProto(); - OneofDescriptorProto::default_instance_ = new OneofDescriptorProto(); - EnumDescriptorProto::default_instance_ = new EnumDescriptorProto(); - EnumValueDescriptorProto::default_instance_ = new EnumValueDescriptorProto(); - ServiceDescriptorProto::default_instance_ = new ServiceDescriptorProto(); - MethodDescriptorProto::default_instance_ = new MethodDescriptorProto(); - FileOptions::default_instance_ = new FileOptions(); - MessageOptions::default_instance_ = new MessageOptions(); - FieldOptions::default_instance_ = new FieldOptions(); - OneofOptions::default_instance_ = new OneofOptions(); - EnumOptions::default_instance_ = new EnumOptions(); - EnumValueOptions::default_instance_ = new EnumValueOptions(); - ServiceOptions::default_instance_ = new ServiceOptions(); - MethodOptions::default_instance_ = new MethodOptions(); - UninterpretedOption::default_instance_ = new UninterpretedOption(); - UninterpretedOption_NamePart::default_instance_ = new UninterpretedOption_NamePart(); - SourceCodeInfo::default_instance_ = new SourceCodeInfo(); - SourceCodeInfo_Location::default_instance_ = new SourceCodeInfo_Location(); - GeneratedCodeInfo::default_instance_ = new GeneratedCodeInfo(); - GeneratedCodeInfo_Annotation::default_instance_ = new GeneratedCodeInfo_Annotation(); - FileDescriptorSet::default_instance_->InitAsDefaultInstance(); - FileDescriptorProto::default_instance_->InitAsDefaultInstance(); - DescriptorProto::default_instance_->InitAsDefaultInstance(); - DescriptorProto_ExtensionRange::default_instance_->InitAsDefaultInstance(); - DescriptorProto_ReservedRange::default_instance_->InitAsDefaultInstance(); - FieldDescriptorProto::default_instance_->InitAsDefaultInstance(); - OneofDescriptorProto::default_instance_->InitAsDefaultInstance(); - EnumDescriptorProto::default_instance_->InitAsDefaultInstance(); - EnumValueDescriptorProto::default_instance_->InitAsDefaultInstance(); - ServiceDescriptorProto::default_instance_->InitAsDefaultInstance(); - MethodDescriptorProto::default_instance_->InitAsDefaultInstance(); - FileOptions::default_instance_->InitAsDefaultInstance(); - MessageOptions::default_instance_->InitAsDefaultInstance(); - FieldOptions::default_instance_->InitAsDefaultInstance(); - OneofOptions::default_instance_->InitAsDefaultInstance(); - EnumOptions::default_instance_->InitAsDefaultInstance(); - EnumValueOptions::default_instance_->InitAsDefaultInstance(); - ServiceOptions::default_instance_->InitAsDefaultInstance(); - MethodOptions::default_instance_->InitAsDefaultInstance(); - UninterpretedOption::default_instance_->InitAsDefaultInstance(); - UninterpretedOption_NamePart::default_instance_->InitAsDefaultInstance(); - SourceCodeInfo::default_instance_->InitAsDefaultInstance(); - SourceCodeInfo_Location::default_instance_->InitAsDefaultInstance(); - GeneratedCodeInfo::default_instance_->InitAsDefaultInstance(); - GeneratedCodeInfo_Annotation::default_instance_->InitAsDefaultInstance(); ::google::protobuf::internal::OnShutdown(&protobuf_ShutdownFile_google_2fprotobuf_2fdescriptor_2eproto); } +GOOGLE_PROTOBUF_DECLARE_ONCE(protobuf_AddDesc_google_2fprotobuf_2fdescriptor_2eproto_once_); +void protobuf_AddDesc_google_2fprotobuf_2fdescriptor_2eproto() { + ::google::protobuf::GoogleOnceInit(&protobuf_AddDesc_google_2fprotobuf_2fdescriptor_2eproto_once_, + &protobuf_AddDesc_google_2fprotobuf_2fdescriptor_2eproto_impl); +} // Force AddDescriptors() to be called at static initialization time. struct StaticDescriptorInitializer_google_2fprotobuf_2fdescriptor_2eproto { StaticDescriptorInitializer_google_2fprotobuf_2fdescriptor_2eproto() { @@ -902,6 +875,16 @@ struct StaticDescriptorInitializer_google_2fprotobuf_2fdescriptor_2eproto { } } static_descriptor_initializer_google_2fprotobuf_2fdescriptor_2eproto_; +namespace { + +static void MergeFromFail(int line) GOOGLE_ATTRIBUTE_COLD GOOGLE_ATTRIBUTE_NORETURN; +static void MergeFromFail(int line) { + ::google::protobuf::internal::MergeFromFail(__FILE__, line); +} + +} // namespace + + // =================================================================== #if !defined(_MSC_VER) || _MSC_VER >= 1900 @@ -910,6 +893,7 @@ const int FileDescriptorSet::kFileFieldNumber; FileDescriptorSet::FileDescriptorSet() : ::google::protobuf::Message(), _internal_metadata_(NULL) { + if (this != internal_default_instance()) protobuf_InitDefaults_google_2fprotobuf_2fdescriptor_2eproto(); SharedCtor(); // @@protoc_insertion_point(constructor:google.protobuf.FileDescriptorSet) } @@ -921,13 +905,12 @@ FileDescriptorSet::FileDescriptorSet(const FileDescriptorSet& from) : ::google::protobuf::Message(), _internal_metadata_(NULL) { SharedCtor(); - MergeFrom(from); + UnsafeMergeFrom(from); // @@protoc_insertion_point(copy_constructor:google.protobuf.FileDescriptorSet) } void FileDescriptorSet::SharedCtor() { _cached_size_ = 0; - ::memset(_has_bits_, 0, sizeof(_has_bits_)); } FileDescriptorSet::~FileDescriptorSet() { @@ -936,8 +919,6 @@ FileDescriptorSet::~FileDescriptorSet() { } void FileDescriptorSet::SharedDtor() { - if (this != default_instance_) { - } } void FileDescriptorSet::SetCachedSize(int size) const { @@ -951,11 +932,11 @@ const ::google::protobuf::Descriptor* FileDescriptorSet::descriptor() { } const FileDescriptorSet& FileDescriptorSet::default_instance() { - if (default_instance_ == NULL) protobuf_AddDesc_google_2fprotobuf_2fdescriptor_2eproto(); - return *default_instance_; + protobuf_InitDefaults_google_2fprotobuf_2fdescriptor_2eproto(); + return *internal_default_instance(); } -FileDescriptorSet* FileDescriptorSet::default_instance_ = NULL; +::google::protobuf::internal::ExplicitlyConstructed FileDescriptorSet::default_instance_; FileDescriptorSet* FileDescriptorSet::New(::google::protobuf::Arena* arena) const { FileDescriptorSet* n = new FileDescriptorSet; @@ -968,7 +949,7 @@ FileDescriptorSet* FileDescriptorSet::New(::google::protobuf::Arena* arena) cons void FileDescriptorSet::Clear() { // @@protoc_insertion_point(message_clear_start:google.protobuf.FileDescriptorSet) file_.Clear(); - ::memset(_has_bits_, 0, sizeof(_has_bits_)); + _has_bits_.Clear(); if (_internal_metadata_.have_unknown_fields()) { mutable_unknown_fields()->Clear(); } @@ -1057,16 +1038,19 @@ void FileDescriptorSet::SerializeWithCachedSizes( return target; } -int FileDescriptorSet::ByteSize() const { +size_t FileDescriptorSet::ByteSizeLong() const { // @@protoc_insertion_point(message_byte_size_start:google.protobuf.FileDescriptorSet) - int total_size = 0; + size_t total_size = 0; // repeated .google.protobuf.FileDescriptorProto file = 1; - total_size += 1 * this->file_size(); - for (int i = 0; i < this->file_size(); i++) { - total_size += - ::google::protobuf::internal::WireFormatLite::MessageSizeNoVirtual( - this->file(i)); + { + unsigned int count = this->file_size(); + total_size += 1UL * count; + for (unsigned int i = 0; i < count; i++) { + total_size += + ::google::protobuf::internal::WireFormatLite::MessageSizeNoVirtual( + this->file(i)); + } } if (_internal_metadata_.have_unknown_fields()) { @@ -1074,18 +1058,17 @@ int FileDescriptorSet::ByteSize() const { ::google::protobuf::internal::WireFormat::ComputeUnknownFieldsSize( unknown_fields()); } + int cached_size = ::google::protobuf::internal::ToCachedSize(total_size); GOOGLE_SAFE_CONCURRENT_WRITES_BEGIN(); - _cached_size_ = total_size; + _cached_size_ = cached_size; GOOGLE_SAFE_CONCURRENT_WRITES_END(); return total_size; } void FileDescriptorSet::MergeFrom(const ::google::protobuf::Message& from) { // @@protoc_insertion_point(generalized_merge_from_start:google.protobuf.FileDescriptorSet) - if (GOOGLE_PREDICT_FALSE(&from == this)) { - ::google::protobuf::internal::MergeFromFail(__FILE__, __LINE__); - } - const FileDescriptorSet* source = + if (GOOGLE_PREDICT_FALSE(&from == this)) MergeFromFail(__LINE__); + const FileDescriptorSet* source = ::google::protobuf::internal::DynamicCastToGenerated( &from); if (source == NULL) { @@ -1093,18 +1076,25 @@ void FileDescriptorSet::MergeFrom(const ::google::protobuf::Message& from) { ::google::protobuf::internal::ReflectionOps::Merge(from, this); } else { // @@protoc_insertion_point(generalized_merge_from_cast_success:google.protobuf.FileDescriptorSet) - MergeFrom(*source); + UnsafeMergeFrom(*source); } } void FileDescriptorSet::MergeFrom(const FileDescriptorSet& from) { // @@protoc_insertion_point(class_specific_merge_from_start:google.protobuf.FileDescriptorSet) - if (GOOGLE_PREDICT_FALSE(&from == this)) { - ::google::protobuf::internal::MergeFromFail(__FILE__, __LINE__); + if (GOOGLE_PREDICT_TRUE(&from != this)) { + UnsafeMergeFrom(from); + } else { + MergeFromFail(__LINE__); } +} + +void FileDescriptorSet::UnsafeMergeFrom(const FileDescriptorSet& from) { + GOOGLE_DCHECK(&from != this); file_.MergeFrom(from.file_); if (from._internal_metadata_.have_unknown_fields()) { - mutable_unknown_fields()->MergeFrom(from.unknown_fields()); + ::google::protobuf::UnknownFieldSet::MergeToInternalMetdata( + from.unknown_fields(), &_internal_metadata_); } } @@ -1119,7 +1109,7 @@ void FileDescriptorSet::CopyFrom(const FileDescriptorSet& from) { // @@protoc_insertion_point(class_specific_copy_from_start:google.protobuf.FileDescriptorSet) if (&from == this) return; Clear(); - MergeFrom(from); + UnsafeMergeFrom(from); } bool FileDescriptorSet::IsInitialized() const { @@ -1201,32 +1191,33 @@ const int FileDescriptorProto::kSyntaxFieldNumber; FileDescriptorProto::FileDescriptorProto() : ::google::protobuf::Message(), _internal_metadata_(NULL) { + if (this != internal_default_instance()) protobuf_InitDefaults_google_2fprotobuf_2fdescriptor_2eproto(); SharedCtor(); // @@protoc_insertion_point(constructor:google.protobuf.FileDescriptorProto) } void FileDescriptorProto::InitAsDefaultInstance() { - options_ = const_cast< ::google::protobuf::FileOptions*>(&::google::protobuf::FileOptions::default_instance()); - source_code_info_ = const_cast< ::google::protobuf::SourceCodeInfo*>(&::google::protobuf::SourceCodeInfo::default_instance()); + options_ = const_cast< ::google::protobuf::FileOptions*>( + ::google::protobuf::FileOptions::internal_default_instance()); + source_code_info_ = const_cast< ::google::protobuf::SourceCodeInfo*>( + ::google::protobuf::SourceCodeInfo::internal_default_instance()); } FileDescriptorProto::FileDescriptorProto(const FileDescriptorProto& from) : ::google::protobuf::Message(), _internal_metadata_(NULL) { SharedCtor(); - MergeFrom(from); + UnsafeMergeFrom(from); // @@protoc_insertion_point(copy_constructor:google.protobuf.FileDescriptorProto) } void FileDescriptorProto::SharedCtor() { - ::google::protobuf::internal::GetEmptyString(); _cached_size_ = 0; name_.UnsafeSetDefault(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); package_.UnsafeSetDefault(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); + syntax_.UnsafeSetDefault(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); options_ = NULL; source_code_info_ = NULL; - syntax_.UnsafeSetDefault(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); - ::memset(_has_bits_, 0, sizeof(_has_bits_)); } FileDescriptorProto::~FileDescriptorProto() { @@ -1238,10 +1229,8 @@ void FileDescriptorProto::SharedDtor() { name_.DestroyNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); package_.DestroyNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); syntax_.DestroyNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); - if (this != default_instance_) { - delete options_; - delete source_code_info_; - } + delete options_; + delete source_code_info_; } void FileDescriptorProto::SetCachedSize(int size) const { @@ -1255,11 +1244,11 @@ const ::google::protobuf::Descriptor* FileDescriptorProto::descriptor() { } const FileDescriptorProto& FileDescriptorProto::default_instance() { - if (default_instance_ == NULL) protobuf_AddDesc_google_2fprotobuf_2fdescriptor_2eproto(); - return *default_instance_; + protobuf_InitDefaults_google_2fprotobuf_2fdescriptor_2eproto(); + return *internal_default_instance(); } -FileDescriptorProto* FileDescriptorProto::default_instance_ = NULL; +::google::protobuf::internal::ExplicitlyConstructed FileDescriptorProto::default_instance_; FileDescriptorProto* FileDescriptorProto::New(::google::protobuf::Arena* arena) const { FileDescriptorProto* n = new FileDescriptorProto; @@ -1297,7 +1286,7 @@ void FileDescriptorProto::Clear() { enum_type_.Clear(); service_.Clear(); extension_.Clear(); - ::memset(_has_bits_, 0, sizeof(_has_bits_)); + _has_bits_.Clear(); if (_internal_metadata_.have_unknown_fields()) { mutable_unknown_fields()->Clear(); } @@ -1740,9 +1729,9 @@ void FileDescriptorProto::SerializeWithCachedSizes( return target; } -int FileDescriptorProto::ByteSize() const { +size_t FileDescriptorProto::ByteSizeLong() const { // @@protoc_insertion_point(message_byte_size_start:google.protobuf.FileDescriptorProto) - int total_size = 0; + size_t total_size = 0; if (_has_bits_[0 / 32] & 3u) { // optional string name = 1; @@ -1784,7 +1773,8 @@ int FileDescriptorProto::ByteSize() const { } // repeated string dependency = 3; - total_size += 1 * this->dependency_size(); + total_size += 1 * + ::google::protobuf::internal::FromIntSize(this->dependency_size()); for (int i = 0; i < this->dependency_size(); i++) { total_size += ::google::protobuf::internal::WireFormatLite::StringSize( this->dependency(i)); @@ -1792,54 +1782,72 @@ int FileDescriptorProto::ByteSize() const { // repeated int32 public_dependency = 10; { - int data_size = 0; - for (int i = 0; i < this->public_dependency_size(); i++) { + size_t data_size = 0; + unsigned int count = this->public_dependency_size(); + for (unsigned int i = 0; i < count; i++) { data_size += ::google::protobuf::internal::WireFormatLite:: Int32Size(this->public_dependency(i)); } - total_size += 1 * this->public_dependency_size() + data_size; + total_size += 1 * + ::google::protobuf::internal::FromIntSize(this->public_dependency_size()); + total_size += data_size; } // repeated int32 weak_dependency = 11; { - int data_size = 0; - for (int i = 0; i < this->weak_dependency_size(); i++) { + size_t data_size = 0; + unsigned int count = this->weak_dependency_size(); + for (unsigned int i = 0; i < count; i++) { data_size += ::google::protobuf::internal::WireFormatLite:: Int32Size(this->weak_dependency(i)); } - total_size += 1 * this->weak_dependency_size() + data_size; + total_size += 1 * + ::google::protobuf::internal::FromIntSize(this->weak_dependency_size()); + total_size += data_size; } // repeated .google.protobuf.DescriptorProto message_type = 4; - total_size += 1 * this->message_type_size(); - for (int i = 0; i < this->message_type_size(); i++) { - total_size += - ::google::protobuf::internal::WireFormatLite::MessageSizeNoVirtual( - this->message_type(i)); + { + unsigned int count = this->message_type_size(); + total_size += 1UL * count; + for (unsigned int i = 0; i < count; i++) { + total_size += + ::google::protobuf::internal::WireFormatLite::MessageSizeNoVirtual( + this->message_type(i)); + } } // repeated .google.protobuf.EnumDescriptorProto enum_type = 5; - total_size += 1 * this->enum_type_size(); - for (int i = 0; i < this->enum_type_size(); i++) { - total_size += - ::google::protobuf::internal::WireFormatLite::MessageSizeNoVirtual( - this->enum_type(i)); + { + unsigned int count = this->enum_type_size(); + total_size += 1UL * count; + for (unsigned int i = 0; i < count; i++) { + total_size += + ::google::protobuf::internal::WireFormatLite::MessageSizeNoVirtual( + this->enum_type(i)); + } } // repeated .google.protobuf.ServiceDescriptorProto service = 6; - total_size += 1 * this->service_size(); - for (int i = 0; i < this->service_size(); i++) { - total_size += - ::google::protobuf::internal::WireFormatLite::MessageSizeNoVirtual( - this->service(i)); + { + unsigned int count = this->service_size(); + total_size += 1UL * count; + for (unsigned int i = 0; i < count; i++) { + total_size += + ::google::protobuf::internal::WireFormatLite::MessageSizeNoVirtual( + this->service(i)); + } } // repeated .google.protobuf.FieldDescriptorProto extension = 7; - total_size += 1 * this->extension_size(); - for (int i = 0; i < this->extension_size(); i++) { - total_size += - ::google::protobuf::internal::WireFormatLite::MessageSizeNoVirtual( - this->extension(i)); + { + unsigned int count = this->extension_size(); + total_size += 1UL * count; + for (unsigned int i = 0; i < count; i++) { + total_size += + ::google::protobuf::internal::WireFormatLite::MessageSizeNoVirtual( + this->extension(i)); + } } if (_internal_metadata_.have_unknown_fields()) { @@ -1847,18 +1855,17 @@ int FileDescriptorProto::ByteSize() const { ::google::protobuf::internal::WireFormat::ComputeUnknownFieldsSize( unknown_fields()); } + int cached_size = ::google::protobuf::internal::ToCachedSize(total_size); GOOGLE_SAFE_CONCURRENT_WRITES_BEGIN(); - _cached_size_ = total_size; + _cached_size_ = cached_size; GOOGLE_SAFE_CONCURRENT_WRITES_END(); return total_size; } void FileDescriptorProto::MergeFrom(const ::google::protobuf::Message& from) { // @@protoc_insertion_point(generalized_merge_from_start:google.protobuf.FileDescriptorProto) - if (GOOGLE_PREDICT_FALSE(&from == this)) { - ::google::protobuf::internal::MergeFromFail(__FILE__, __LINE__); - } - const FileDescriptorProto* source = + if (GOOGLE_PREDICT_FALSE(&from == this)) MergeFromFail(__LINE__); + const FileDescriptorProto* source = ::google::protobuf::internal::DynamicCastToGenerated( &from); if (source == NULL) { @@ -1866,18 +1873,24 @@ void FileDescriptorProto::MergeFrom(const ::google::protobuf::Message& from) { ::google::protobuf::internal::ReflectionOps::Merge(from, this); } else { // @@protoc_insertion_point(generalized_merge_from_cast_success:google.protobuf.FileDescriptorProto) - MergeFrom(*source); + UnsafeMergeFrom(*source); } } void FileDescriptorProto::MergeFrom(const FileDescriptorProto& from) { // @@protoc_insertion_point(class_specific_merge_from_start:google.protobuf.FileDescriptorProto) - if (GOOGLE_PREDICT_FALSE(&from == this)) { - ::google::protobuf::internal::MergeFromFail(__FILE__, __LINE__); + if (GOOGLE_PREDICT_TRUE(&from != this)) { + UnsafeMergeFrom(from); + } else { + MergeFromFail(__LINE__); } - dependency_.MergeFrom(from.dependency_); - public_dependency_.MergeFrom(from.public_dependency_); - weak_dependency_.MergeFrom(from.weak_dependency_); +} + +void FileDescriptorProto::UnsafeMergeFrom(const FileDescriptorProto& from) { + GOOGLE_DCHECK(&from != this); + dependency_.UnsafeMergeFrom(from.dependency_); + public_dependency_.UnsafeMergeFrom(from.public_dependency_); + weak_dependency_.UnsafeMergeFrom(from.weak_dependency_); message_type_.MergeFrom(from.message_type_); enum_type_.MergeFrom(from.enum_type_); service_.MergeFrom(from.service_); @@ -1905,7 +1918,8 @@ void FileDescriptorProto::MergeFrom(const FileDescriptorProto& from) { } } if (from._internal_metadata_.have_unknown_fields()) { - mutable_unknown_fields()->MergeFrom(from.unknown_fields()); + ::google::protobuf::UnknownFieldSet::MergeToInternalMetdata( + from.unknown_fields(), &_internal_metadata_); } } @@ -1920,7 +1934,7 @@ void FileDescriptorProto::CopyFrom(const FileDescriptorProto& from) { // @@protoc_insertion_point(class_specific_copy_from_start:google.protobuf.FileDescriptorProto) if (&from == this) return; Clear(); - MergeFrom(from); + UnsafeMergeFrom(from); } bool FileDescriptorProto::IsInitialized() const { @@ -1982,37 +1996,37 @@ void FileDescriptorProto::clear_name() { name_.ClearToEmptyNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); clear_has_name(); } - const ::std::string& FileDescriptorProto::name() const { +const ::std::string& FileDescriptorProto::name() const { // @@protoc_insertion_point(field_get:google.protobuf.FileDescriptorProto.name) return name_.GetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); } - void FileDescriptorProto::set_name(const ::std::string& value) { +void FileDescriptorProto::set_name(const ::std::string& value) { set_has_name(); name_.SetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), value); // @@protoc_insertion_point(field_set:google.protobuf.FileDescriptorProto.name) } - void FileDescriptorProto::set_name(const char* value) { +void FileDescriptorProto::set_name(const char* value) { set_has_name(); name_.SetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), ::std::string(value)); // @@protoc_insertion_point(field_set_char:google.protobuf.FileDescriptorProto.name) } - void FileDescriptorProto::set_name(const char* value, size_t size) { +void FileDescriptorProto::set_name(const char* value, size_t size) { set_has_name(); name_.SetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), ::std::string(reinterpret_cast(value), size)); // @@protoc_insertion_point(field_set_pointer:google.protobuf.FileDescriptorProto.name) } - ::std::string* FileDescriptorProto::mutable_name() { +::std::string* FileDescriptorProto::mutable_name() { set_has_name(); // @@protoc_insertion_point(field_mutable:google.protobuf.FileDescriptorProto.name) return name_.MutableNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); } - ::std::string* FileDescriptorProto::release_name() { +::std::string* FileDescriptorProto::release_name() { // @@protoc_insertion_point(field_release:google.protobuf.FileDescriptorProto.name) clear_has_name(); return name_.ReleaseNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); } - void FileDescriptorProto::set_allocated_name(::std::string* name) { +void FileDescriptorProto::set_allocated_name(::std::string* name) { if (name != NULL) { set_has_name(); } else { @@ -2036,37 +2050,37 @@ void FileDescriptorProto::clear_package() { package_.ClearToEmptyNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); clear_has_package(); } - const ::std::string& FileDescriptorProto::package() const { +const ::std::string& FileDescriptorProto::package() const { // @@protoc_insertion_point(field_get:google.protobuf.FileDescriptorProto.package) return package_.GetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); } - void FileDescriptorProto::set_package(const ::std::string& value) { +void FileDescriptorProto::set_package(const ::std::string& value) { set_has_package(); package_.SetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), value); // @@protoc_insertion_point(field_set:google.protobuf.FileDescriptorProto.package) } - void FileDescriptorProto::set_package(const char* value) { +void FileDescriptorProto::set_package(const char* value) { set_has_package(); package_.SetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), ::std::string(value)); // @@protoc_insertion_point(field_set_char:google.protobuf.FileDescriptorProto.package) } - void FileDescriptorProto::set_package(const char* value, size_t size) { +void FileDescriptorProto::set_package(const char* value, size_t size) { set_has_package(); package_.SetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), ::std::string(reinterpret_cast(value), size)); // @@protoc_insertion_point(field_set_pointer:google.protobuf.FileDescriptorProto.package) } - ::std::string* FileDescriptorProto::mutable_package() { +::std::string* FileDescriptorProto::mutable_package() { set_has_package(); // @@protoc_insertion_point(field_mutable:google.protobuf.FileDescriptorProto.package) return package_.MutableNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); } - ::std::string* FileDescriptorProto::release_package() { +::std::string* FileDescriptorProto::release_package() { // @@protoc_insertion_point(field_release:google.protobuf.FileDescriptorProto.package) clear_has_package(); return package_.ReleaseNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); } - void FileDescriptorProto::set_allocated_package(::std::string* package) { +void FileDescriptorProto::set_allocated_package(::std::string* package) { if (package != NULL) { set_has_package(); } else { @@ -2083,49 +2097,49 @@ int FileDescriptorProto::dependency_size() const { void FileDescriptorProto::clear_dependency() { dependency_.Clear(); } - const ::std::string& FileDescriptorProto::dependency(int index) const { +const ::std::string& FileDescriptorProto::dependency(int index) const { // @@protoc_insertion_point(field_get:google.protobuf.FileDescriptorProto.dependency) return dependency_.Get(index); } - ::std::string* FileDescriptorProto::mutable_dependency(int index) { +::std::string* FileDescriptorProto::mutable_dependency(int index) { // @@protoc_insertion_point(field_mutable:google.protobuf.FileDescriptorProto.dependency) return dependency_.Mutable(index); } - void FileDescriptorProto::set_dependency(int index, const ::std::string& value) { +void FileDescriptorProto::set_dependency(int index, const ::std::string& value) { // @@protoc_insertion_point(field_set:google.protobuf.FileDescriptorProto.dependency) dependency_.Mutable(index)->assign(value); } - void FileDescriptorProto::set_dependency(int index, const char* value) { +void FileDescriptorProto::set_dependency(int index, const char* value) { dependency_.Mutable(index)->assign(value); // @@protoc_insertion_point(field_set_char:google.protobuf.FileDescriptorProto.dependency) } - void FileDescriptorProto::set_dependency(int index, const char* value, size_t size) { +void FileDescriptorProto::set_dependency(int index, const char* value, size_t size) { dependency_.Mutable(index)->assign( reinterpret_cast(value), size); // @@protoc_insertion_point(field_set_pointer:google.protobuf.FileDescriptorProto.dependency) } - ::std::string* FileDescriptorProto::add_dependency() { +::std::string* FileDescriptorProto::add_dependency() { // @@protoc_insertion_point(field_add_mutable:google.protobuf.FileDescriptorProto.dependency) return dependency_.Add(); } - void FileDescriptorProto::add_dependency(const ::std::string& value) { +void FileDescriptorProto::add_dependency(const ::std::string& value) { dependency_.Add()->assign(value); // @@protoc_insertion_point(field_add:google.protobuf.FileDescriptorProto.dependency) } - void FileDescriptorProto::add_dependency(const char* value) { +void FileDescriptorProto::add_dependency(const char* value) { dependency_.Add()->assign(value); // @@protoc_insertion_point(field_add_char:google.protobuf.FileDescriptorProto.dependency) } - void FileDescriptorProto::add_dependency(const char* value, size_t size) { +void FileDescriptorProto::add_dependency(const char* value, size_t size) { dependency_.Add()->assign(reinterpret_cast(value), size); // @@protoc_insertion_point(field_add_pointer:google.protobuf.FileDescriptorProto.dependency) } - const ::google::protobuf::RepeatedPtrField< ::std::string>& +const ::google::protobuf::RepeatedPtrField< ::std::string>& FileDescriptorProto::dependency() const { // @@protoc_insertion_point(field_list:google.protobuf.FileDescriptorProto.dependency) return dependency_; } - ::google::protobuf::RepeatedPtrField< ::std::string>* +::google::protobuf::RepeatedPtrField< ::std::string>* FileDescriptorProto::mutable_dependency() { // @@protoc_insertion_point(field_mutable_list:google.protobuf.FileDescriptorProto.dependency) return &dependency_; @@ -2138,24 +2152,24 @@ int FileDescriptorProto::public_dependency_size() const { void FileDescriptorProto::clear_public_dependency() { public_dependency_.Clear(); } - ::google::protobuf::int32 FileDescriptorProto::public_dependency(int index) const { +::google::protobuf::int32 FileDescriptorProto::public_dependency(int index) const { // @@protoc_insertion_point(field_get:google.protobuf.FileDescriptorProto.public_dependency) return public_dependency_.Get(index); } - void FileDescriptorProto::set_public_dependency(int index, ::google::protobuf::int32 value) { +void FileDescriptorProto::set_public_dependency(int index, ::google::protobuf::int32 value) { public_dependency_.Set(index, value); // @@protoc_insertion_point(field_set:google.protobuf.FileDescriptorProto.public_dependency) } - void FileDescriptorProto::add_public_dependency(::google::protobuf::int32 value) { +void FileDescriptorProto::add_public_dependency(::google::protobuf::int32 value) { public_dependency_.Add(value); // @@protoc_insertion_point(field_add:google.protobuf.FileDescriptorProto.public_dependency) } - const ::google::protobuf::RepeatedField< ::google::protobuf::int32 >& +const ::google::protobuf::RepeatedField< ::google::protobuf::int32 >& FileDescriptorProto::public_dependency() const { // @@protoc_insertion_point(field_list:google.protobuf.FileDescriptorProto.public_dependency) return public_dependency_; } - ::google::protobuf::RepeatedField< ::google::protobuf::int32 >* +::google::protobuf::RepeatedField< ::google::protobuf::int32 >* FileDescriptorProto::mutable_public_dependency() { // @@protoc_insertion_point(field_mutable_list:google.protobuf.FileDescriptorProto.public_dependency) return &public_dependency_; @@ -2168,24 +2182,24 @@ int FileDescriptorProto::weak_dependency_size() const { void FileDescriptorProto::clear_weak_dependency() { weak_dependency_.Clear(); } - ::google::protobuf::int32 FileDescriptorProto::weak_dependency(int index) const { +::google::protobuf::int32 FileDescriptorProto::weak_dependency(int index) const { // @@protoc_insertion_point(field_get:google.protobuf.FileDescriptorProto.weak_dependency) return weak_dependency_.Get(index); } - void FileDescriptorProto::set_weak_dependency(int index, ::google::protobuf::int32 value) { +void FileDescriptorProto::set_weak_dependency(int index, ::google::protobuf::int32 value) { weak_dependency_.Set(index, value); // @@protoc_insertion_point(field_set:google.protobuf.FileDescriptorProto.weak_dependency) } - void FileDescriptorProto::add_weak_dependency(::google::protobuf::int32 value) { +void FileDescriptorProto::add_weak_dependency(::google::protobuf::int32 value) { weak_dependency_.Add(value); // @@protoc_insertion_point(field_add:google.protobuf.FileDescriptorProto.weak_dependency) } - const ::google::protobuf::RepeatedField< ::google::protobuf::int32 >& +const ::google::protobuf::RepeatedField< ::google::protobuf::int32 >& FileDescriptorProto::weak_dependency() const { // @@protoc_insertion_point(field_list:google.protobuf.FileDescriptorProto.weak_dependency) return weak_dependency_; } - ::google::protobuf::RepeatedField< ::google::protobuf::int32 >* +::google::protobuf::RepeatedField< ::google::protobuf::int32 >* FileDescriptorProto::mutable_weak_dependency() { // @@protoc_insertion_point(field_mutable_list:google.protobuf.FileDescriptorProto.weak_dependency) return &weak_dependency_; @@ -2327,7 +2341,8 @@ void FileDescriptorProto::clear_options() { } const ::google::protobuf::FileOptions& FileDescriptorProto::options() const { // @@protoc_insertion_point(field_get:google.protobuf.FileDescriptorProto.options) - return options_ != NULL ? *options_ : *default_instance_->options_; + return options_ != NULL ? *options_ + : *::google::protobuf::FileOptions::internal_default_instance(); } ::google::protobuf::FileOptions* FileDescriptorProto::mutable_options() { set_has_options(); @@ -2371,7 +2386,8 @@ void FileDescriptorProto::clear_source_code_info() { } const ::google::protobuf::SourceCodeInfo& FileDescriptorProto::source_code_info() const { // @@protoc_insertion_point(field_get:google.protobuf.FileDescriptorProto.source_code_info) - return source_code_info_ != NULL ? *source_code_info_ : *default_instance_->source_code_info_; + return source_code_info_ != NULL ? *source_code_info_ + : *::google::protobuf::SourceCodeInfo::internal_default_instance(); } ::google::protobuf::SourceCodeInfo* FileDescriptorProto::mutable_source_code_info() { set_has_source_code_info(); @@ -2413,37 +2429,37 @@ void FileDescriptorProto::clear_syntax() { syntax_.ClearToEmptyNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); clear_has_syntax(); } - const ::std::string& FileDescriptorProto::syntax() const { +const ::std::string& FileDescriptorProto::syntax() const { // @@protoc_insertion_point(field_get:google.protobuf.FileDescriptorProto.syntax) return syntax_.GetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); } - void FileDescriptorProto::set_syntax(const ::std::string& value) { +void FileDescriptorProto::set_syntax(const ::std::string& value) { set_has_syntax(); syntax_.SetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), value); // @@protoc_insertion_point(field_set:google.protobuf.FileDescriptorProto.syntax) } - void FileDescriptorProto::set_syntax(const char* value) { +void FileDescriptorProto::set_syntax(const char* value) { set_has_syntax(); syntax_.SetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), ::std::string(value)); // @@protoc_insertion_point(field_set_char:google.protobuf.FileDescriptorProto.syntax) } - void FileDescriptorProto::set_syntax(const char* value, size_t size) { +void FileDescriptorProto::set_syntax(const char* value, size_t size) { set_has_syntax(); syntax_.SetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), ::std::string(reinterpret_cast(value), size)); // @@protoc_insertion_point(field_set_pointer:google.protobuf.FileDescriptorProto.syntax) } - ::std::string* FileDescriptorProto::mutable_syntax() { +::std::string* FileDescriptorProto::mutable_syntax() { set_has_syntax(); // @@protoc_insertion_point(field_mutable:google.protobuf.FileDescriptorProto.syntax) return syntax_.MutableNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); } - ::std::string* FileDescriptorProto::release_syntax() { +::std::string* FileDescriptorProto::release_syntax() { // @@protoc_insertion_point(field_release:google.protobuf.FileDescriptorProto.syntax) clear_has_syntax(); return syntax_.ReleaseNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); } - void FileDescriptorProto::set_allocated_syntax(::std::string* syntax) { +void FileDescriptorProto::set_allocated_syntax(::std::string* syntax) { if (syntax != NULL) { set_has_syntax(); } else { @@ -2464,6 +2480,7 @@ const int DescriptorProto_ExtensionRange::kEndFieldNumber; DescriptorProto_ExtensionRange::DescriptorProto_ExtensionRange() : ::google::protobuf::Message(), _internal_metadata_(NULL) { + if (this != internal_default_instance()) protobuf_InitDefaults_google_2fprotobuf_2fdescriptor_2eproto(); SharedCtor(); // @@protoc_insertion_point(constructor:google.protobuf.DescriptorProto.ExtensionRange) } @@ -2475,15 +2492,14 @@ DescriptorProto_ExtensionRange::DescriptorProto_ExtensionRange(const DescriptorP : ::google::protobuf::Message(), _internal_metadata_(NULL) { SharedCtor(); - MergeFrom(from); + UnsafeMergeFrom(from); // @@protoc_insertion_point(copy_constructor:google.protobuf.DescriptorProto.ExtensionRange) } void DescriptorProto_ExtensionRange::SharedCtor() { _cached_size_ = 0; - start_ = 0; - end_ = 0; - ::memset(_has_bits_, 0, sizeof(_has_bits_)); + ::memset(&start_, 0, reinterpret_cast(&end_) - + reinterpret_cast(&start_) + sizeof(end_)); } DescriptorProto_ExtensionRange::~DescriptorProto_ExtensionRange() { @@ -2492,8 +2508,6 @@ DescriptorProto_ExtensionRange::~DescriptorProto_ExtensionRange() { } void DescriptorProto_ExtensionRange::SharedDtor() { - if (this != default_instance_) { - } } void DescriptorProto_ExtensionRange::SetCachedSize(int size) const { @@ -2507,11 +2521,11 @@ const ::google::protobuf::Descriptor* DescriptorProto_ExtensionRange::descriptor } const DescriptorProto_ExtensionRange& DescriptorProto_ExtensionRange::default_instance() { - if (default_instance_ == NULL) protobuf_AddDesc_google_2fprotobuf_2fdescriptor_2eproto(); - return *default_instance_; + protobuf_InitDefaults_google_2fprotobuf_2fdescriptor_2eproto(); + return *internal_default_instance(); } -DescriptorProto_ExtensionRange* DescriptorProto_ExtensionRange::default_instance_ = NULL; +::google::protobuf::internal::ExplicitlyConstructed DescriptorProto_ExtensionRange::default_instance_; DescriptorProto_ExtensionRange* DescriptorProto_ExtensionRange::New(::google::protobuf::Arena* arena) const { DescriptorProto_ExtensionRange* n = new DescriptorProto_ExtensionRange; @@ -2544,7 +2558,7 @@ void DescriptorProto_ExtensionRange::Clear() { #undef ZR_HELPER_ #undef ZR_ - ::memset(_has_bits_, 0, sizeof(_has_bits_)); + _has_bits_.Clear(); if (_internal_metadata_.have_unknown_fields()) { mutable_unknown_fields()->Clear(); } @@ -2563,10 +2577,10 @@ bool DescriptorProto_ExtensionRange::MergePartialFromCodedStream( // optional int32 start = 1; case 1: { if (tag == 8) { + set_has_start(); DO_((::google::protobuf::internal::WireFormatLite::ReadPrimitive< ::google::protobuf::int32, ::google::protobuf::internal::WireFormatLite::TYPE_INT32>( input, &start_))); - set_has_start(); } else { goto handle_unusual; } @@ -2578,10 +2592,10 @@ bool DescriptorProto_ExtensionRange::MergePartialFromCodedStream( case 2: { if (tag == 16) { parse_end: + set_has_end(); DO_((::google::protobuf::internal::WireFormatLite::ReadPrimitive< ::google::protobuf::int32, ::google::protobuf::internal::WireFormatLite::TYPE_INT32>( input, &end_))); - set_has_end(); } else { goto handle_unusual; } @@ -2653,9 +2667,9 @@ void DescriptorProto_ExtensionRange::SerializeWithCachedSizes( return target; } -int DescriptorProto_ExtensionRange::ByteSize() const { +size_t DescriptorProto_ExtensionRange::ByteSizeLong() const { // @@protoc_insertion_point(message_byte_size_start:google.protobuf.DescriptorProto.ExtensionRange) - int total_size = 0; + size_t total_size = 0; if (_has_bits_[0 / 32] & 3u) { // optional int32 start = 1; @@ -2678,18 +2692,17 @@ int DescriptorProto_ExtensionRange::ByteSize() const { ::google::protobuf::internal::WireFormat::ComputeUnknownFieldsSize( unknown_fields()); } + int cached_size = ::google::protobuf::internal::ToCachedSize(total_size); GOOGLE_SAFE_CONCURRENT_WRITES_BEGIN(); - _cached_size_ = total_size; + _cached_size_ = cached_size; GOOGLE_SAFE_CONCURRENT_WRITES_END(); return total_size; } void DescriptorProto_ExtensionRange::MergeFrom(const ::google::protobuf::Message& from) { // @@protoc_insertion_point(generalized_merge_from_start:google.protobuf.DescriptorProto.ExtensionRange) - if (GOOGLE_PREDICT_FALSE(&from == this)) { - ::google::protobuf::internal::MergeFromFail(__FILE__, __LINE__); - } - const DescriptorProto_ExtensionRange* source = + if (GOOGLE_PREDICT_FALSE(&from == this)) MergeFromFail(__LINE__); + const DescriptorProto_ExtensionRange* source = ::google::protobuf::internal::DynamicCastToGenerated( &from); if (source == NULL) { @@ -2697,15 +2710,21 @@ void DescriptorProto_ExtensionRange::MergeFrom(const ::google::protobuf::Message ::google::protobuf::internal::ReflectionOps::Merge(from, this); } else { // @@protoc_insertion_point(generalized_merge_from_cast_success:google.protobuf.DescriptorProto.ExtensionRange) - MergeFrom(*source); + UnsafeMergeFrom(*source); } } void DescriptorProto_ExtensionRange::MergeFrom(const DescriptorProto_ExtensionRange& from) { // @@protoc_insertion_point(class_specific_merge_from_start:google.protobuf.DescriptorProto.ExtensionRange) - if (GOOGLE_PREDICT_FALSE(&from == this)) { - ::google::protobuf::internal::MergeFromFail(__FILE__, __LINE__); + if (GOOGLE_PREDICT_TRUE(&from != this)) { + UnsafeMergeFrom(from); + } else { + MergeFromFail(__LINE__); } +} + +void DescriptorProto_ExtensionRange::UnsafeMergeFrom(const DescriptorProto_ExtensionRange& from) { + GOOGLE_DCHECK(&from != this); if (from._has_bits_[0 / 32] & (0xffu << (0 % 32))) { if (from.has_start()) { set_start(from.start()); @@ -2715,7 +2734,8 @@ void DescriptorProto_ExtensionRange::MergeFrom(const DescriptorProto_ExtensionRa } } if (from._internal_metadata_.have_unknown_fields()) { - mutable_unknown_fields()->MergeFrom(from.unknown_fields()); + ::google::protobuf::UnknownFieldSet::MergeToInternalMetdata( + from.unknown_fields(), &_internal_metadata_); } } @@ -2730,7 +2750,7 @@ void DescriptorProto_ExtensionRange::CopyFrom(const DescriptorProto_ExtensionRan // @@protoc_insertion_point(class_specific_copy_from_start:google.protobuf.DescriptorProto.ExtensionRange) if (&from == this) return; Clear(); - MergeFrom(from); + UnsafeMergeFrom(from); } bool DescriptorProto_ExtensionRange::IsInitialized() const { @@ -2768,6 +2788,7 @@ const int DescriptorProto_ReservedRange::kEndFieldNumber; DescriptorProto_ReservedRange::DescriptorProto_ReservedRange() : ::google::protobuf::Message(), _internal_metadata_(NULL) { + if (this != internal_default_instance()) protobuf_InitDefaults_google_2fprotobuf_2fdescriptor_2eproto(); SharedCtor(); // @@protoc_insertion_point(constructor:google.protobuf.DescriptorProto.ReservedRange) } @@ -2779,15 +2800,14 @@ DescriptorProto_ReservedRange::DescriptorProto_ReservedRange(const DescriptorPro : ::google::protobuf::Message(), _internal_metadata_(NULL) { SharedCtor(); - MergeFrom(from); + UnsafeMergeFrom(from); // @@protoc_insertion_point(copy_constructor:google.protobuf.DescriptorProto.ReservedRange) } void DescriptorProto_ReservedRange::SharedCtor() { _cached_size_ = 0; - start_ = 0; - end_ = 0; - ::memset(_has_bits_, 0, sizeof(_has_bits_)); + ::memset(&start_, 0, reinterpret_cast(&end_) - + reinterpret_cast(&start_) + sizeof(end_)); } DescriptorProto_ReservedRange::~DescriptorProto_ReservedRange() { @@ -2796,8 +2816,6 @@ DescriptorProto_ReservedRange::~DescriptorProto_ReservedRange() { } void DescriptorProto_ReservedRange::SharedDtor() { - if (this != default_instance_) { - } } void DescriptorProto_ReservedRange::SetCachedSize(int size) const { @@ -2811,11 +2829,11 @@ const ::google::protobuf::Descriptor* DescriptorProto_ReservedRange::descriptor( } const DescriptorProto_ReservedRange& DescriptorProto_ReservedRange::default_instance() { - if (default_instance_ == NULL) protobuf_AddDesc_google_2fprotobuf_2fdescriptor_2eproto(); - return *default_instance_; + protobuf_InitDefaults_google_2fprotobuf_2fdescriptor_2eproto(); + return *internal_default_instance(); } -DescriptorProto_ReservedRange* DescriptorProto_ReservedRange::default_instance_ = NULL; +::google::protobuf::internal::ExplicitlyConstructed DescriptorProto_ReservedRange::default_instance_; DescriptorProto_ReservedRange* DescriptorProto_ReservedRange::New(::google::protobuf::Arena* arena) const { DescriptorProto_ReservedRange* n = new DescriptorProto_ReservedRange; @@ -2848,7 +2866,7 @@ void DescriptorProto_ReservedRange::Clear() { #undef ZR_HELPER_ #undef ZR_ - ::memset(_has_bits_, 0, sizeof(_has_bits_)); + _has_bits_.Clear(); if (_internal_metadata_.have_unknown_fields()) { mutable_unknown_fields()->Clear(); } @@ -2867,10 +2885,10 @@ bool DescriptorProto_ReservedRange::MergePartialFromCodedStream( // optional int32 start = 1; case 1: { if (tag == 8) { + set_has_start(); DO_((::google::protobuf::internal::WireFormatLite::ReadPrimitive< ::google::protobuf::int32, ::google::protobuf::internal::WireFormatLite::TYPE_INT32>( input, &start_))); - set_has_start(); } else { goto handle_unusual; } @@ -2882,10 +2900,10 @@ bool DescriptorProto_ReservedRange::MergePartialFromCodedStream( case 2: { if (tag == 16) { parse_end: + set_has_end(); DO_((::google::protobuf::internal::WireFormatLite::ReadPrimitive< ::google::protobuf::int32, ::google::protobuf::internal::WireFormatLite::TYPE_INT32>( input, &end_))); - set_has_end(); } else { goto handle_unusual; } @@ -2957,9 +2975,9 @@ void DescriptorProto_ReservedRange::SerializeWithCachedSizes( return target; } -int DescriptorProto_ReservedRange::ByteSize() const { +size_t DescriptorProto_ReservedRange::ByteSizeLong() const { // @@protoc_insertion_point(message_byte_size_start:google.protobuf.DescriptorProto.ReservedRange) - int total_size = 0; + size_t total_size = 0; if (_has_bits_[0 / 32] & 3u) { // optional int32 start = 1; @@ -2982,18 +3000,17 @@ int DescriptorProto_ReservedRange::ByteSize() const { ::google::protobuf::internal::WireFormat::ComputeUnknownFieldsSize( unknown_fields()); } + int cached_size = ::google::protobuf::internal::ToCachedSize(total_size); GOOGLE_SAFE_CONCURRENT_WRITES_BEGIN(); - _cached_size_ = total_size; + _cached_size_ = cached_size; GOOGLE_SAFE_CONCURRENT_WRITES_END(); return total_size; } void DescriptorProto_ReservedRange::MergeFrom(const ::google::protobuf::Message& from) { // @@protoc_insertion_point(generalized_merge_from_start:google.protobuf.DescriptorProto.ReservedRange) - if (GOOGLE_PREDICT_FALSE(&from == this)) { - ::google::protobuf::internal::MergeFromFail(__FILE__, __LINE__); - } - const DescriptorProto_ReservedRange* source = + if (GOOGLE_PREDICT_FALSE(&from == this)) MergeFromFail(__LINE__); + const DescriptorProto_ReservedRange* source = ::google::protobuf::internal::DynamicCastToGenerated( &from); if (source == NULL) { @@ -3001,15 +3018,21 @@ void DescriptorProto_ReservedRange::MergeFrom(const ::google::protobuf::Message& ::google::protobuf::internal::ReflectionOps::Merge(from, this); } else { // @@protoc_insertion_point(generalized_merge_from_cast_success:google.protobuf.DescriptorProto.ReservedRange) - MergeFrom(*source); + UnsafeMergeFrom(*source); } } void DescriptorProto_ReservedRange::MergeFrom(const DescriptorProto_ReservedRange& from) { // @@protoc_insertion_point(class_specific_merge_from_start:google.protobuf.DescriptorProto.ReservedRange) - if (GOOGLE_PREDICT_FALSE(&from == this)) { - ::google::protobuf::internal::MergeFromFail(__FILE__, __LINE__); + if (GOOGLE_PREDICT_TRUE(&from != this)) { + UnsafeMergeFrom(from); + } else { + MergeFromFail(__LINE__); } +} + +void DescriptorProto_ReservedRange::UnsafeMergeFrom(const DescriptorProto_ReservedRange& from) { + GOOGLE_DCHECK(&from != this); if (from._has_bits_[0 / 32] & (0xffu << (0 % 32))) { if (from.has_start()) { set_start(from.start()); @@ -3019,7 +3042,8 @@ void DescriptorProto_ReservedRange::MergeFrom(const DescriptorProto_ReservedRang } } if (from._internal_metadata_.have_unknown_fields()) { - mutable_unknown_fields()->MergeFrom(from.unknown_fields()); + ::google::protobuf::UnknownFieldSet::MergeToInternalMetdata( + from.unknown_fields(), &_internal_metadata_); } } @@ -3034,7 +3058,7 @@ void DescriptorProto_ReservedRange::CopyFrom(const DescriptorProto_ReservedRange // @@protoc_insertion_point(class_specific_copy_from_start:google.protobuf.DescriptorProto.ReservedRange) if (&from == this) return; Clear(); - MergeFrom(from); + UnsafeMergeFrom(from); } bool DescriptorProto_ReservedRange::IsInitialized() const { @@ -3080,28 +3104,28 @@ const int DescriptorProto::kReservedNameFieldNumber; DescriptorProto::DescriptorProto() : ::google::protobuf::Message(), _internal_metadata_(NULL) { + if (this != internal_default_instance()) protobuf_InitDefaults_google_2fprotobuf_2fdescriptor_2eproto(); SharedCtor(); // @@protoc_insertion_point(constructor:google.protobuf.DescriptorProto) } void DescriptorProto::InitAsDefaultInstance() { - options_ = const_cast< ::google::protobuf::MessageOptions*>(&::google::protobuf::MessageOptions::default_instance()); + options_ = const_cast< ::google::protobuf::MessageOptions*>( + ::google::protobuf::MessageOptions::internal_default_instance()); } DescriptorProto::DescriptorProto(const DescriptorProto& from) : ::google::protobuf::Message(), _internal_metadata_(NULL) { SharedCtor(); - MergeFrom(from); + UnsafeMergeFrom(from); // @@protoc_insertion_point(copy_constructor:google.protobuf.DescriptorProto) } void DescriptorProto::SharedCtor() { - ::google::protobuf::internal::GetEmptyString(); _cached_size_ = 0; name_.UnsafeSetDefault(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); options_ = NULL; - ::memset(_has_bits_, 0, sizeof(_has_bits_)); } DescriptorProto::~DescriptorProto() { @@ -3111,9 +3135,7 @@ DescriptorProto::~DescriptorProto() { void DescriptorProto::SharedDtor() { name_.DestroyNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); - if (this != default_instance_) { - delete options_; - } + delete options_; } void DescriptorProto::SetCachedSize(int size) const { @@ -3127,11 +3149,11 @@ const ::google::protobuf::Descriptor* DescriptorProto::descriptor() { } const DescriptorProto& DescriptorProto::default_instance() { - if (default_instance_ == NULL) protobuf_AddDesc_google_2fprotobuf_2fdescriptor_2eproto(); - return *default_instance_; + protobuf_InitDefaults_google_2fprotobuf_2fdescriptor_2eproto(); + return *internal_default_instance(); } -DescriptorProto* DescriptorProto::default_instance_ = NULL; +::google::protobuf::internal::ExplicitlyConstructed DescriptorProto::default_instance_; DescriptorProto* DescriptorProto::New(::google::protobuf::Arena* arena) const { DescriptorProto* n = new DescriptorProto; @@ -3159,7 +3181,7 @@ void DescriptorProto::Clear() { oneof_decl_.Clear(); reserved_range_.Clear(); reserved_name_.Clear(); - ::memset(_has_bits_, 0, sizeof(_has_bits_)); + _has_bits_.Clear(); if (_internal_metadata_.have_unknown_fields()) { mutable_unknown_fields()->Clear(); } @@ -3526,9 +3548,9 @@ void DescriptorProto::SerializeWithCachedSizes( return target; } -int DescriptorProto::ByteSize() const { +size_t DescriptorProto::ByteSizeLong() const { // @@protoc_insertion_point(message_byte_size_start:google.protobuf.DescriptorProto) - int total_size = 0; + size_t total_size = 0; if (_has_bits_[0 / 32] & 129u) { // optional string name = 1; @@ -3547,63 +3569,85 @@ int DescriptorProto::ByteSize() const { } // repeated .google.protobuf.FieldDescriptorProto field = 2; - total_size += 1 * this->field_size(); - for (int i = 0; i < this->field_size(); i++) { - total_size += - ::google::protobuf::internal::WireFormatLite::MessageSizeNoVirtual( - this->field(i)); + { + unsigned int count = this->field_size(); + total_size += 1UL * count; + for (unsigned int i = 0; i < count; i++) { + total_size += + ::google::protobuf::internal::WireFormatLite::MessageSizeNoVirtual( + this->field(i)); + } } // repeated .google.protobuf.FieldDescriptorProto extension = 6; - total_size += 1 * this->extension_size(); - for (int i = 0; i < this->extension_size(); i++) { - total_size += - ::google::protobuf::internal::WireFormatLite::MessageSizeNoVirtual( - this->extension(i)); + { + unsigned int count = this->extension_size(); + total_size += 1UL * count; + for (unsigned int i = 0; i < count; i++) { + total_size += + ::google::protobuf::internal::WireFormatLite::MessageSizeNoVirtual( + this->extension(i)); + } } // repeated .google.protobuf.DescriptorProto nested_type = 3; - total_size += 1 * this->nested_type_size(); - for (int i = 0; i < this->nested_type_size(); i++) { - total_size += - ::google::protobuf::internal::WireFormatLite::MessageSizeNoVirtual( - this->nested_type(i)); + { + unsigned int count = this->nested_type_size(); + total_size += 1UL * count; + for (unsigned int i = 0; i < count; i++) { + total_size += + ::google::protobuf::internal::WireFormatLite::MessageSizeNoVirtual( + this->nested_type(i)); + } } // repeated .google.protobuf.EnumDescriptorProto enum_type = 4; - total_size += 1 * this->enum_type_size(); - for (int i = 0; i < this->enum_type_size(); i++) { - total_size += - ::google::protobuf::internal::WireFormatLite::MessageSizeNoVirtual( - this->enum_type(i)); + { + unsigned int count = this->enum_type_size(); + total_size += 1UL * count; + for (unsigned int i = 0; i < count; i++) { + total_size += + ::google::protobuf::internal::WireFormatLite::MessageSizeNoVirtual( + this->enum_type(i)); + } } // repeated .google.protobuf.DescriptorProto.ExtensionRange extension_range = 5; - total_size += 1 * this->extension_range_size(); - for (int i = 0; i < this->extension_range_size(); i++) { - total_size += - ::google::protobuf::internal::WireFormatLite::MessageSizeNoVirtual( - this->extension_range(i)); + { + unsigned int count = this->extension_range_size(); + total_size += 1UL * count; + for (unsigned int i = 0; i < count; i++) { + total_size += + ::google::protobuf::internal::WireFormatLite::MessageSizeNoVirtual( + this->extension_range(i)); + } } // repeated .google.protobuf.OneofDescriptorProto oneof_decl = 8; - total_size += 1 * this->oneof_decl_size(); - for (int i = 0; i < this->oneof_decl_size(); i++) { - total_size += - ::google::protobuf::internal::WireFormatLite::MessageSizeNoVirtual( - this->oneof_decl(i)); + { + unsigned int count = this->oneof_decl_size(); + total_size += 1UL * count; + for (unsigned int i = 0; i < count; i++) { + total_size += + ::google::protobuf::internal::WireFormatLite::MessageSizeNoVirtual( + this->oneof_decl(i)); + } } // repeated .google.protobuf.DescriptorProto.ReservedRange reserved_range = 9; - total_size += 1 * this->reserved_range_size(); - for (int i = 0; i < this->reserved_range_size(); i++) { - total_size += - ::google::protobuf::internal::WireFormatLite::MessageSizeNoVirtual( - this->reserved_range(i)); + { + unsigned int count = this->reserved_range_size(); + total_size += 1UL * count; + for (unsigned int i = 0; i < count; i++) { + total_size += + ::google::protobuf::internal::WireFormatLite::MessageSizeNoVirtual( + this->reserved_range(i)); + } } // repeated string reserved_name = 10; - total_size += 1 * this->reserved_name_size(); + total_size += 1 * + ::google::protobuf::internal::FromIntSize(this->reserved_name_size()); for (int i = 0; i < this->reserved_name_size(); i++) { total_size += ::google::protobuf::internal::WireFormatLite::StringSize( this->reserved_name(i)); @@ -3614,18 +3658,17 @@ int DescriptorProto::ByteSize() const { ::google::protobuf::internal::WireFormat::ComputeUnknownFieldsSize( unknown_fields()); } + int cached_size = ::google::protobuf::internal::ToCachedSize(total_size); GOOGLE_SAFE_CONCURRENT_WRITES_BEGIN(); - _cached_size_ = total_size; + _cached_size_ = cached_size; GOOGLE_SAFE_CONCURRENT_WRITES_END(); return total_size; } void DescriptorProto::MergeFrom(const ::google::protobuf::Message& from) { // @@protoc_insertion_point(generalized_merge_from_start:google.protobuf.DescriptorProto) - if (GOOGLE_PREDICT_FALSE(&from == this)) { - ::google::protobuf::internal::MergeFromFail(__FILE__, __LINE__); - } - const DescriptorProto* source = + if (GOOGLE_PREDICT_FALSE(&from == this)) MergeFromFail(__LINE__); + const DescriptorProto* source = ::google::protobuf::internal::DynamicCastToGenerated( &from); if (source == NULL) { @@ -3633,15 +3676,21 @@ void DescriptorProto::MergeFrom(const ::google::protobuf::Message& from) { ::google::protobuf::internal::ReflectionOps::Merge(from, this); } else { // @@protoc_insertion_point(generalized_merge_from_cast_success:google.protobuf.DescriptorProto) - MergeFrom(*source); + UnsafeMergeFrom(*source); } } void DescriptorProto::MergeFrom(const DescriptorProto& from) { // @@protoc_insertion_point(class_specific_merge_from_start:google.protobuf.DescriptorProto) - if (GOOGLE_PREDICT_FALSE(&from == this)) { - ::google::protobuf::internal::MergeFromFail(__FILE__, __LINE__); + if (GOOGLE_PREDICT_TRUE(&from != this)) { + UnsafeMergeFrom(from); + } else { + MergeFromFail(__LINE__); } +} + +void DescriptorProto::UnsafeMergeFrom(const DescriptorProto& from) { + GOOGLE_DCHECK(&from != this); field_.MergeFrom(from.field_); extension_.MergeFrom(from.extension_); nested_type_.MergeFrom(from.nested_type_); @@ -3649,7 +3698,7 @@ void DescriptorProto::MergeFrom(const DescriptorProto& from) { extension_range_.MergeFrom(from.extension_range_); oneof_decl_.MergeFrom(from.oneof_decl_); reserved_range_.MergeFrom(from.reserved_range_); - reserved_name_.MergeFrom(from.reserved_name_); + reserved_name_.UnsafeMergeFrom(from.reserved_name_); if (from._has_bits_[0 / 32] & (0xffu << (0 % 32))) { if (from.has_name()) { set_has_name(); @@ -3660,7 +3709,8 @@ void DescriptorProto::MergeFrom(const DescriptorProto& from) { } } if (from._internal_metadata_.have_unknown_fields()) { - mutable_unknown_fields()->MergeFrom(from.unknown_fields()); + ::google::protobuf::UnknownFieldSet::MergeToInternalMetdata( + from.unknown_fields(), &_internal_metadata_); } } @@ -3675,7 +3725,7 @@ void DescriptorProto::CopyFrom(const DescriptorProto& from) { // @@protoc_insertion_point(class_specific_copy_from_start:google.protobuf.DescriptorProto) if (&from == this) return; Clear(); - MergeFrom(from); + UnsafeMergeFrom(from); } bool DescriptorProto::IsInitialized() const { @@ -3736,11 +3786,11 @@ void DescriptorProto_ExtensionRange::clear_start() { start_ = 0; clear_has_start(); } - ::google::protobuf::int32 DescriptorProto_ExtensionRange::start() const { +::google::protobuf::int32 DescriptorProto_ExtensionRange::start() const { // @@protoc_insertion_point(field_get:google.protobuf.DescriptorProto.ExtensionRange.start) return start_; } - void DescriptorProto_ExtensionRange::set_start(::google::protobuf::int32 value) { +void DescriptorProto_ExtensionRange::set_start(::google::protobuf::int32 value) { set_has_start(); start_ = value; // @@protoc_insertion_point(field_set:google.protobuf.DescriptorProto.ExtensionRange.start) @@ -3760,11 +3810,11 @@ void DescriptorProto_ExtensionRange::clear_end() { end_ = 0; clear_has_end(); } - ::google::protobuf::int32 DescriptorProto_ExtensionRange::end() const { +::google::protobuf::int32 DescriptorProto_ExtensionRange::end() const { // @@protoc_insertion_point(field_get:google.protobuf.DescriptorProto.ExtensionRange.end) return end_; } - void DescriptorProto_ExtensionRange::set_end(::google::protobuf::int32 value) { +void DescriptorProto_ExtensionRange::set_end(::google::protobuf::int32 value) { set_has_end(); end_ = value; // @@protoc_insertion_point(field_set:google.protobuf.DescriptorProto.ExtensionRange.end) @@ -3788,11 +3838,11 @@ void DescriptorProto_ReservedRange::clear_start() { start_ = 0; clear_has_start(); } - ::google::protobuf::int32 DescriptorProto_ReservedRange::start() const { +::google::protobuf::int32 DescriptorProto_ReservedRange::start() const { // @@protoc_insertion_point(field_get:google.protobuf.DescriptorProto.ReservedRange.start) return start_; } - void DescriptorProto_ReservedRange::set_start(::google::protobuf::int32 value) { +void DescriptorProto_ReservedRange::set_start(::google::protobuf::int32 value) { set_has_start(); start_ = value; // @@protoc_insertion_point(field_set:google.protobuf.DescriptorProto.ReservedRange.start) @@ -3812,11 +3862,11 @@ void DescriptorProto_ReservedRange::clear_end() { end_ = 0; clear_has_end(); } - ::google::protobuf::int32 DescriptorProto_ReservedRange::end() const { +::google::protobuf::int32 DescriptorProto_ReservedRange::end() const { // @@protoc_insertion_point(field_get:google.protobuf.DescriptorProto.ReservedRange.end) return end_; } - void DescriptorProto_ReservedRange::set_end(::google::protobuf::int32 value) { +void DescriptorProto_ReservedRange::set_end(::google::protobuf::int32 value) { set_has_end(); end_ = value; // @@protoc_insertion_point(field_set:google.protobuf.DescriptorProto.ReservedRange.end) @@ -3840,37 +3890,37 @@ void DescriptorProto::clear_name() { name_.ClearToEmptyNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); clear_has_name(); } - const ::std::string& DescriptorProto::name() const { +const ::std::string& DescriptorProto::name() const { // @@protoc_insertion_point(field_get:google.protobuf.DescriptorProto.name) return name_.GetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); } - void DescriptorProto::set_name(const ::std::string& value) { +void DescriptorProto::set_name(const ::std::string& value) { set_has_name(); name_.SetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), value); // @@protoc_insertion_point(field_set:google.protobuf.DescriptorProto.name) } - void DescriptorProto::set_name(const char* value) { +void DescriptorProto::set_name(const char* value) { set_has_name(); name_.SetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), ::std::string(value)); // @@protoc_insertion_point(field_set_char:google.protobuf.DescriptorProto.name) } - void DescriptorProto::set_name(const char* value, size_t size) { +void DescriptorProto::set_name(const char* value, size_t size) { set_has_name(); name_.SetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), ::std::string(reinterpret_cast(value), size)); // @@protoc_insertion_point(field_set_pointer:google.protobuf.DescriptorProto.name) } - ::std::string* DescriptorProto::mutable_name() { +::std::string* DescriptorProto::mutable_name() { set_has_name(); // @@protoc_insertion_point(field_mutable:google.protobuf.DescriptorProto.name) return name_.MutableNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); } - ::std::string* DescriptorProto::release_name() { +::std::string* DescriptorProto::release_name() { // @@protoc_insertion_point(field_release:google.protobuf.DescriptorProto.name) clear_has_name(); return name_.ReleaseNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); } - void DescriptorProto::set_allocated_name(::std::string* name) { +void DescriptorProto::set_allocated_name(::std::string* name) { if (name != NULL) { set_has_name(); } else { @@ -4076,7 +4126,8 @@ void DescriptorProto::clear_options() { } const ::google::protobuf::MessageOptions& DescriptorProto::options() const { // @@protoc_insertion_point(field_get:google.protobuf.DescriptorProto.options) - return options_ != NULL ? *options_ : *default_instance_->options_; + return options_ != NULL ? *options_ + : *::google::protobuf::MessageOptions::internal_default_instance(); } ::google::protobuf::MessageOptions* DescriptorProto::mutable_options() { set_has_options(); @@ -4141,49 +4192,49 @@ int DescriptorProto::reserved_name_size() const { void DescriptorProto::clear_reserved_name() { reserved_name_.Clear(); } - const ::std::string& DescriptorProto::reserved_name(int index) const { +const ::std::string& DescriptorProto::reserved_name(int index) const { // @@protoc_insertion_point(field_get:google.protobuf.DescriptorProto.reserved_name) return reserved_name_.Get(index); } - ::std::string* DescriptorProto::mutable_reserved_name(int index) { +::std::string* DescriptorProto::mutable_reserved_name(int index) { // @@protoc_insertion_point(field_mutable:google.protobuf.DescriptorProto.reserved_name) return reserved_name_.Mutable(index); } - void DescriptorProto::set_reserved_name(int index, const ::std::string& value) { +void DescriptorProto::set_reserved_name(int index, const ::std::string& value) { // @@protoc_insertion_point(field_set:google.protobuf.DescriptorProto.reserved_name) reserved_name_.Mutable(index)->assign(value); } - void DescriptorProto::set_reserved_name(int index, const char* value) { +void DescriptorProto::set_reserved_name(int index, const char* value) { reserved_name_.Mutable(index)->assign(value); // @@protoc_insertion_point(field_set_char:google.protobuf.DescriptorProto.reserved_name) } - void DescriptorProto::set_reserved_name(int index, const char* value, size_t size) { +void DescriptorProto::set_reserved_name(int index, const char* value, size_t size) { reserved_name_.Mutable(index)->assign( reinterpret_cast(value), size); // @@protoc_insertion_point(field_set_pointer:google.protobuf.DescriptorProto.reserved_name) } - ::std::string* DescriptorProto::add_reserved_name() { +::std::string* DescriptorProto::add_reserved_name() { // @@protoc_insertion_point(field_add_mutable:google.protobuf.DescriptorProto.reserved_name) return reserved_name_.Add(); } - void DescriptorProto::add_reserved_name(const ::std::string& value) { +void DescriptorProto::add_reserved_name(const ::std::string& value) { reserved_name_.Add()->assign(value); // @@protoc_insertion_point(field_add:google.protobuf.DescriptorProto.reserved_name) } - void DescriptorProto::add_reserved_name(const char* value) { +void DescriptorProto::add_reserved_name(const char* value) { reserved_name_.Add()->assign(value); // @@protoc_insertion_point(field_add_char:google.protobuf.DescriptorProto.reserved_name) } - void DescriptorProto::add_reserved_name(const char* value, size_t size) { +void DescriptorProto::add_reserved_name(const char* value, size_t size) { reserved_name_.Add()->assign(reinterpret_cast(value), size); // @@protoc_insertion_point(field_add_pointer:google.protobuf.DescriptorProto.reserved_name) } - const ::google::protobuf::RepeatedPtrField< ::std::string>& +const ::google::protobuf::RepeatedPtrField< ::std::string>& DescriptorProto::reserved_name() const { // @@protoc_insertion_point(field_list:google.protobuf.DescriptorProto.reserved_name) return reserved_name_; } - ::google::protobuf::RepeatedPtrField< ::std::string>* +::google::protobuf::RepeatedPtrField< ::std::string>* DescriptorProto::mutable_reserved_name() { // @@protoc_insertion_point(field_mutable_list:google.protobuf.DescriptorProto.reserved_name) return &reserved_name_; @@ -4198,7 +4249,7 @@ const ::google::protobuf::EnumDescriptor* FieldDescriptorProto_Type_descriptor() return FieldDescriptorProto_Type_descriptor_; } bool FieldDescriptorProto_Type_IsValid(int value) { - switch(value) { + switch (value) { case 1: case 2: case 3: @@ -4251,7 +4302,7 @@ const ::google::protobuf::EnumDescriptor* FieldDescriptorProto_Label_descriptor( return FieldDescriptorProto_Label_descriptor_; } bool FieldDescriptorProto_Label_IsValid(int value) { - switch(value) { + switch (value) { case 1: case 2: case 3: @@ -4284,36 +4335,36 @@ const int FieldDescriptorProto::kOptionsFieldNumber; FieldDescriptorProto::FieldDescriptorProto() : ::google::protobuf::Message(), _internal_metadata_(NULL) { + if (this != internal_default_instance()) protobuf_InitDefaults_google_2fprotobuf_2fdescriptor_2eproto(); SharedCtor(); // @@protoc_insertion_point(constructor:google.protobuf.FieldDescriptorProto) } void FieldDescriptorProto::InitAsDefaultInstance() { - options_ = const_cast< ::google::protobuf::FieldOptions*>(&::google::protobuf::FieldOptions::default_instance()); + options_ = const_cast< ::google::protobuf::FieldOptions*>( + ::google::protobuf::FieldOptions::internal_default_instance()); } FieldDescriptorProto::FieldDescriptorProto(const FieldDescriptorProto& from) : ::google::protobuf::Message(), _internal_metadata_(NULL) { SharedCtor(); - MergeFrom(from); + UnsafeMergeFrom(from); // @@protoc_insertion_point(copy_constructor:google.protobuf.FieldDescriptorProto) } void FieldDescriptorProto::SharedCtor() { - ::google::protobuf::internal::GetEmptyString(); _cached_size_ = 0; name_.UnsafeSetDefault(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); - number_ = 0; - label_ = 1; - type_ = 1; type_name_.UnsafeSetDefault(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); extendee_.UnsafeSetDefault(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); default_value_.UnsafeSetDefault(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); - oneof_index_ = 0; json_name_.UnsafeSetDefault(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); options_ = NULL; - ::memset(_has_bits_, 0, sizeof(_has_bits_)); + ::memset(&number_, 0, reinterpret_cast(&oneof_index_) - + reinterpret_cast(&number_) + sizeof(oneof_index_)); + label_ = 1; + type_ = 1; } FieldDescriptorProto::~FieldDescriptorProto() { @@ -4327,9 +4378,7 @@ void FieldDescriptorProto::SharedDtor() { extendee_.DestroyNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); default_value_.DestroyNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); json_name_.DestroyNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); - if (this != default_instance_) { - delete options_; - } + delete options_; } void FieldDescriptorProto::SetCachedSize(int size) const { @@ -4343,11 +4392,11 @@ const ::google::protobuf::Descriptor* FieldDescriptorProto::descriptor() { } const FieldDescriptorProto& FieldDescriptorProto::default_instance() { - if (default_instance_ == NULL) protobuf_AddDesc_google_2fprotobuf_2fdescriptor_2eproto(); - return *default_instance_; + protobuf_InitDefaults_google_2fprotobuf_2fdescriptor_2eproto(); + return *internal_default_instance(); } -FieldDescriptorProto* FieldDescriptorProto::default_instance_ = NULL; +::google::protobuf::internal::ExplicitlyConstructed FieldDescriptorProto::default_instance_; FieldDescriptorProto* FieldDescriptorProto::New(::google::protobuf::Arena* arena) const { FieldDescriptorProto* n = new FieldDescriptorProto; @@ -4359,11 +4408,27 @@ FieldDescriptorProto* FieldDescriptorProto::New(::google::protobuf::Arena* arena void FieldDescriptorProto::Clear() { // @@protoc_insertion_point(message_clear_start:google.protobuf.FieldDescriptorProto) +#if defined(__clang__) +#define ZR_HELPER_(f) \ + _Pragma("clang diagnostic push") \ + _Pragma("clang diagnostic ignored \"-Winvalid-offsetof\"") \ + __builtin_offsetof(FieldDescriptorProto, f) \ + _Pragma("clang diagnostic pop") +#else +#define ZR_HELPER_(f) reinterpret_cast(\ + &reinterpret_cast(16)->f) +#endif + +#define ZR_(first, last) do {\ + ::memset(&(first), 0,\ + ZR_HELPER_(last) - ZR_HELPER_(first) + sizeof(last));\ +} while (0) + if (_has_bits_[0 / 32] & 255u) { + ZR_(number_, oneof_index_); if (has_name()) { name_.ClearToEmptyNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); } - number_ = 0; label_ = 1; type_ = 1; if (has_type_name()) { @@ -4375,7 +4440,6 @@ void FieldDescriptorProto::Clear() { if (has_default_value()) { default_value_.ClearToEmptyNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); } - oneof_index_ = 0; } if (_has_bits_[8 / 32] & 768u) { if (has_json_name()) { @@ -4385,7 +4449,11 @@ void FieldDescriptorProto::Clear() { if (options_ != NULL) options_->::google::protobuf::FieldOptions::Clear(); } } - ::memset(_has_bits_, 0, sizeof(_has_bits_)); + +#undef ZR_HELPER_ +#undef ZR_ + + _has_bits_.Clear(); if (_internal_metadata_.have_unknown_fields()) { mutable_unknown_fields()->Clear(); } @@ -4438,10 +4506,10 @@ bool FieldDescriptorProto::MergePartialFromCodedStream( case 3: { if (tag == 24) { parse_number: + set_has_number(); DO_((::google::protobuf::internal::WireFormatLite::ReadPrimitive< ::google::protobuf::int32, ::google::protobuf::internal::WireFormatLite::TYPE_INT32>( input, &number_))); - set_has_number(); } else { goto handle_unusual; } @@ -4540,10 +4608,10 @@ bool FieldDescriptorProto::MergePartialFromCodedStream( case 9: { if (tag == 72) { parse_oneof_index: + set_has_oneof_index(); DO_((::google::protobuf::internal::WireFormatLite::ReadPrimitive< ::google::protobuf::int32, ::google::protobuf::internal::WireFormatLite::TYPE_INT32>( input, &oneof_index_))); - set_has_oneof_index(); } else { goto handle_unusual; } @@ -4774,9 +4842,9 @@ void FieldDescriptorProto::SerializeWithCachedSizes( return target; } -int FieldDescriptorProto::ByteSize() const { +size_t FieldDescriptorProto::ByteSizeLong() const { // @@protoc_insertion_point(message_byte_size_start:google.protobuf.FieldDescriptorProto) - int total_size = 0; + size_t total_size = 0; if (_has_bits_[0 / 32] & 255u) { // optional string name = 1; @@ -4855,18 +4923,17 @@ int FieldDescriptorProto::ByteSize() const { ::google::protobuf::internal::WireFormat::ComputeUnknownFieldsSize( unknown_fields()); } + int cached_size = ::google::protobuf::internal::ToCachedSize(total_size); GOOGLE_SAFE_CONCURRENT_WRITES_BEGIN(); - _cached_size_ = total_size; + _cached_size_ = cached_size; GOOGLE_SAFE_CONCURRENT_WRITES_END(); return total_size; } void FieldDescriptorProto::MergeFrom(const ::google::protobuf::Message& from) { // @@protoc_insertion_point(generalized_merge_from_start:google.protobuf.FieldDescriptorProto) - if (GOOGLE_PREDICT_FALSE(&from == this)) { - ::google::protobuf::internal::MergeFromFail(__FILE__, __LINE__); - } - const FieldDescriptorProto* source = + if (GOOGLE_PREDICT_FALSE(&from == this)) MergeFromFail(__LINE__); + const FieldDescriptorProto* source = ::google::protobuf::internal::DynamicCastToGenerated( &from); if (source == NULL) { @@ -4874,15 +4941,21 @@ void FieldDescriptorProto::MergeFrom(const ::google::protobuf::Message& from) { ::google::protobuf::internal::ReflectionOps::Merge(from, this); } else { // @@protoc_insertion_point(generalized_merge_from_cast_success:google.protobuf.FieldDescriptorProto) - MergeFrom(*source); + UnsafeMergeFrom(*source); } } void FieldDescriptorProto::MergeFrom(const FieldDescriptorProto& from) { // @@protoc_insertion_point(class_specific_merge_from_start:google.protobuf.FieldDescriptorProto) - if (GOOGLE_PREDICT_FALSE(&from == this)) { - ::google::protobuf::internal::MergeFromFail(__FILE__, __LINE__); + if (GOOGLE_PREDICT_TRUE(&from != this)) { + UnsafeMergeFrom(from); + } else { + MergeFromFail(__LINE__); } +} + +void FieldDescriptorProto::UnsafeMergeFrom(const FieldDescriptorProto& from) { + GOOGLE_DCHECK(&from != this); if (from._has_bits_[0 / 32] & (0xffu << (0 % 32))) { if (from.has_name()) { set_has_name(); @@ -4923,7 +4996,8 @@ void FieldDescriptorProto::MergeFrom(const FieldDescriptorProto& from) { } } if (from._internal_metadata_.have_unknown_fields()) { - mutable_unknown_fields()->MergeFrom(from.unknown_fields()); + ::google::protobuf::UnknownFieldSet::MergeToInternalMetdata( + from.unknown_fields(), &_internal_metadata_); } } @@ -4938,7 +5012,7 @@ void FieldDescriptorProto::CopyFrom(const FieldDescriptorProto& from) { // @@protoc_insertion_point(class_specific_copy_from_start:google.protobuf.FieldDescriptorProto) if (&from == this) return; Clear(); - MergeFrom(from); + UnsafeMergeFrom(from); } bool FieldDescriptorProto::IsInitialized() const { @@ -4994,37 +5068,37 @@ void FieldDescriptorProto::clear_name() { name_.ClearToEmptyNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); clear_has_name(); } - const ::std::string& FieldDescriptorProto::name() const { +const ::std::string& FieldDescriptorProto::name() const { // @@protoc_insertion_point(field_get:google.protobuf.FieldDescriptorProto.name) return name_.GetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); } - void FieldDescriptorProto::set_name(const ::std::string& value) { +void FieldDescriptorProto::set_name(const ::std::string& value) { set_has_name(); name_.SetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), value); // @@protoc_insertion_point(field_set:google.protobuf.FieldDescriptorProto.name) } - void FieldDescriptorProto::set_name(const char* value) { +void FieldDescriptorProto::set_name(const char* value) { set_has_name(); name_.SetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), ::std::string(value)); // @@protoc_insertion_point(field_set_char:google.protobuf.FieldDescriptorProto.name) } - void FieldDescriptorProto::set_name(const char* value, size_t size) { +void FieldDescriptorProto::set_name(const char* value, size_t size) { set_has_name(); name_.SetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), ::std::string(reinterpret_cast(value), size)); // @@protoc_insertion_point(field_set_pointer:google.protobuf.FieldDescriptorProto.name) } - ::std::string* FieldDescriptorProto::mutable_name() { +::std::string* FieldDescriptorProto::mutable_name() { set_has_name(); // @@protoc_insertion_point(field_mutable:google.protobuf.FieldDescriptorProto.name) return name_.MutableNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); } - ::std::string* FieldDescriptorProto::release_name() { +::std::string* FieldDescriptorProto::release_name() { // @@protoc_insertion_point(field_release:google.protobuf.FieldDescriptorProto.name) clear_has_name(); return name_.ReleaseNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); } - void FieldDescriptorProto::set_allocated_name(::std::string* name) { +void FieldDescriptorProto::set_allocated_name(::std::string* name) { if (name != NULL) { set_has_name(); } else { @@ -5048,11 +5122,11 @@ void FieldDescriptorProto::clear_number() { number_ = 0; clear_has_number(); } - ::google::protobuf::int32 FieldDescriptorProto::number() const { +::google::protobuf::int32 FieldDescriptorProto::number() const { // @@protoc_insertion_point(field_get:google.protobuf.FieldDescriptorProto.number) return number_; } - void FieldDescriptorProto::set_number(::google::protobuf::int32 value) { +void FieldDescriptorProto::set_number(::google::protobuf::int32 value) { set_has_number(); number_ = value; // @@protoc_insertion_point(field_set:google.protobuf.FieldDescriptorProto.number) @@ -5072,11 +5146,11 @@ void FieldDescriptorProto::clear_label() { label_ = 1; clear_has_label(); } - ::google::protobuf::FieldDescriptorProto_Label FieldDescriptorProto::label() const { +::google::protobuf::FieldDescriptorProto_Label FieldDescriptorProto::label() const { // @@protoc_insertion_point(field_get:google.protobuf.FieldDescriptorProto.label) return static_cast< ::google::protobuf::FieldDescriptorProto_Label >(label_); } - void FieldDescriptorProto::set_label(::google::protobuf::FieldDescriptorProto_Label value) { +void FieldDescriptorProto::set_label(::google::protobuf::FieldDescriptorProto_Label value) { assert(::google::protobuf::FieldDescriptorProto_Label_IsValid(value)); set_has_label(); label_ = value; @@ -5097,11 +5171,11 @@ void FieldDescriptorProto::clear_type() { type_ = 1; clear_has_type(); } - ::google::protobuf::FieldDescriptorProto_Type FieldDescriptorProto::type() const { +::google::protobuf::FieldDescriptorProto_Type FieldDescriptorProto::type() const { // @@protoc_insertion_point(field_get:google.protobuf.FieldDescriptorProto.type) return static_cast< ::google::protobuf::FieldDescriptorProto_Type >(type_); } - void FieldDescriptorProto::set_type(::google::protobuf::FieldDescriptorProto_Type value) { +void FieldDescriptorProto::set_type(::google::protobuf::FieldDescriptorProto_Type value) { assert(::google::protobuf::FieldDescriptorProto_Type_IsValid(value)); set_has_type(); type_ = value; @@ -5122,37 +5196,37 @@ void FieldDescriptorProto::clear_type_name() { type_name_.ClearToEmptyNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); clear_has_type_name(); } - const ::std::string& FieldDescriptorProto::type_name() const { +const ::std::string& FieldDescriptorProto::type_name() const { // @@protoc_insertion_point(field_get:google.protobuf.FieldDescriptorProto.type_name) return type_name_.GetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); } - void FieldDescriptorProto::set_type_name(const ::std::string& value) { +void FieldDescriptorProto::set_type_name(const ::std::string& value) { set_has_type_name(); type_name_.SetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), value); // @@protoc_insertion_point(field_set:google.protobuf.FieldDescriptorProto.type_name) } - void FieldDescriptorProto::set_type_name(const char* value) { +void FieldDescriptorProto::set_type_name(const char* value) { set_has_type_name(); type_name_.SetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), ::std::string(value)); // @@protoc_insertion_point(field_set_char:google.protobuf.FieldDescriptorProto.type_name) } - void FieldDescriptorProto::set_type_name(const char* value, size_t size) { +void FieldDescriptorProto::set_type_name(const char* value, size_t size) { set_has_type_name(); type_name_.SetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), ::std::string(reinterpret_cast(value), size)); // @@protoc_insertion_point(field_set_pointer:google.protobuf.FieldDescriptorProto.type_name) } - ::std::string* FieldDescriptorProto::mutable_type_name() { +::std::string* FieldDescriptorProto::mutable_type_name() { set_has_type_name(); // @@protoc_insertion_point(field_mutable:google.protobuf.FieldDescriptorProto.type_name) return type_name_.MutableNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); } - ::std::string* FieldDescriptorProto::release_type_name() { +::std::string* FieldDescriptorProto::release_type_name() { // @@protoc_insertion_point(field_release:google.protobuf.FieldDescriptorProto.type_name) clear_has_type_name(); return type_name_.ReleaseNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); } - void FieldDescriptorProto::set_allocated_type_name(::std::string* type_name) { +void FieldDescriptorProto::set_allocated_type_name(::std::string* type_name) { if (type_name != NULL) { set_has_type_name(); } else { @@ -5176,37 +5250,37 @@ void FieldDescriptorProto::clear_extendee() { extendee_.ClearToEmptyNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); clear_has_extendee(); } - const ::std::string& FieldDescriptorProto::extendee() const { +const ::std::string& FieldDescriptorProto::extendee() const { // @@protoc_insertion_point(field_get:google.protobuf.FieldDescriptorProto.extendee) return extendee_.GetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); } - void FieldDescriptorProto::set_extendee(const ::std::string& value) { +void FieldDescriptorProto::set_extendee(const ::std::string& value) { set_has_extendee(); extendee_.SetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), value); // @@protoc_insertion_point(field_set:google.protobuf.FieldDescriptorProto.extendee) } - void FieldDescriptorProto::set_extendee(const char* value) { +void FieldDescriptorProto::set_extendee(const char* value) { set_has_extendee(); extendee_.SetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), ::std::string(value)); // @@protoc_insertion_point(field_set_char:google.protobuf.FieldDescriptorProto.extendee) } - void FieldDescriptorProto::set_extendee(const char* value, size_t size) { +void FieldDescriptorProto::set_extendee(const char* value, size_t size) { set_has_extendee(); extendee_.SetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), ::std::string(reinterpret_cast(value), size)); // @@protoc_insertion_point(field_set_pointer:google.protobuf.FieldDescriptorProto.extendee) } - ::std::string* FieldDescriptorProto::mutable_extendee() { +::std::string* FieldDescriptorProto::mutable_extendee() { set_has_extendee(); // @@protoc_insertion_point(field_mutable:google.protobuf.FieldDescriptorProto.extendee) return extendee_.MutableNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); } - ::std::string* FieldDescriptorProto::release_extendee() { +::std::string* FieldDescriptorProto::release_extendee() { // @@protoc_insertion_point(field_release:google.protobuf.FieldDescriptorProto.extendee) clear_has_extendee(); return extendee_.ReleaseNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); } - void FieldDescriptorProto::set_allocated_extendee(::std::string* extendee) { +void FieldDescriptorProto::set_allocated_extendee(::std::string* extendee) { if (extendee != NULL) { set_has_extendee(); } else { @@ -5230,37 +5304,37 @@ void FieldDescriptorProto::clear_default_value() { default_value_.ClearToEmptyNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); clear_has_default_value(); } - const ::std::string& FieldDescriptorProto::default_value() const { +const ::std::string& FieldDescriptorProto::default_value() const { // @@protoc_insertion_point(field_get:google.protobuf.FieldDescriptorProto.default_value) return default_value_.GetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); } - void FieldDescriptorProto::set_default_value(const ::std::string& value) { +void FieldDescriptorProto::set_default_value(const ::std::string& value) { set_has_default_value(); default_value_.SetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), value); // @@protoc_insertion_point(field_set:google.protobuf.FieldDescriptorProto.default_value) } - void FieldDescriptorProto::set_default_value(const char* value) { +void FieldDescriptorProto::set_default_value(const char* value) { set_has_default_value(); default_value_.SetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), ::std::string(value)); // @@protoc_insertion_point(field_set_char:google.protobuf.FieldDescriptorProto.default_value) } - void FieldDescriptorProto::set_default_value(const char* value, size_t size) { +void FieldDescriptorProto::set_default_value(const char* value, size_t size) { set_has_default_value(); default_value_.SetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), ::std::string(reinterpret_cast(value), size)); // @@protoc_insertion_point(field_set_pointer:google.protobuf.FieldDescriptorProto.default_value) } - ::std::string* FieldDescriptorProto::mutable_default_value() { +::std::string* FieldDescriptorProto::mutable_default_value() { set_has_default_value(); // @@protoc_insertion_point(field_mutable:google.protobuf.FieldDescriptorProto.default_value) return default_value_.MutableNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); } - ::std::string* FieldDescriptorProto::release_default_value() { +::std::string* FieldDescriptorProto::release_default_value() { // @@protoc_insertion_point(field_release:google.protobuf.FieldDescriptorProto.default_value) clear_has_default_value(); return default_value_.ReleaseNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); } - void FieldDescriptorProto::set_allocated_default_value(::std::string* default_value) { +void FieldDescriptorProto::set_allocated_default_value(::std::string* default_value) { if (default_value != NULL) { set_has_default_value(); } else { @@ -5284,11 +5358,11 @@ void FieldDescriptorProto::clear_oneof_index() { oneof_index_ = 0; clear_has_oneof_index(); } - ::google::protobuf::int32 FieldDescriptorProto::oneof_index() const { +::google::protobuf::int32 FieldDescriptorProto::oneof_index() const { // @@protoc_insertion_point(field_get:google.protobuf.FieldDescriptorProto.oneof_index) return oneof_index_; } - void FieldDescriptorProto::set_oneof_index(::google::protobuf::int32 value) { +void FieldDescriptorProto::set_oneof_index(::google::protobuf::int32 value) { set_has_oneof_index(); oneof_index_ = value; // @@protoc_insertion_point(field_set:google.protobuf.FieldDescriptorProto.oneof_index) @@ -5308,37 +5382,37 @@ void FieldDescriptorProto::clear_json_name() { json_name_.ClearToEmptyNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); clear_has_json_name(); } - const ::std::string& FieldDescriptorProto::json_name() const { +const ::std::string& FieldDescriptorProto::json_name() const { // @@protoc_insertion_point(field_get:google.protobuf.FieldDescriptorProto.json_name) return json_name_.GetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); } - void FieldDescriptorProto::set_json_name(const ::std::string& value) { +void FieldDescriptorProto::set_json_name(const ::std::string& value) { set_has_json_name(); json_name_.SetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), value); // @@protoc_insertion_point(field_set:google.protobuf.FieldDescriptorProto.json_name) } - void FieldDescriptorProto::set_json_name(const char* value) { +void FieldDescriptorProto::set_json_name(const char* value) { set_has_json_name(); json_name_.SetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), ::std::string(value)); // @@protoc_insertion_point(field_set_char:google.protobuf.FieldDescriptorProto.json_name) } - void FieldDescriptorProto::set_json_name(const char* value, size_t size) { +void FieldDescriptorProto::set_json_name(const char* value, size_t size) { set_has_json_name(); json_name_.SetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), ::std::string(reinterpret_cast(value), size)); // @@protoc_insertion_point(field_set_pointer:google.protobuf.FieldDescriptorProto.json_name) } - ::std::string* FieldDescriptorProto::mutable_json_name() { +::std::string* FieldDescriptorProto::mutable_json_name() { set_has_json_name(); // @@protoc_insertion_point(field_mutable:google.protobuf.FieldDescriptorProto.json_name) return json_name_.MutableNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); } - ::std::string* FieldDescriptorProto::release_json_name() { +::std::string* FieldDescriptorProto::release_json_name() { // @@protoc_insertion_point(field_release:google.protobuf.FieldDescriptorProto.json_name) clear_has_json_name(); return json_name_.ReleaseNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); } - void FieldDescriptorProto::set_allocated_json_name(::std::string* json_name) { +void FieldDescriptorProto::set_allocated_json_name(::std::string* json_name) { if (json_name != NULL) { set_has_json_name(); } else { @@ -5364,7 +5438,8 @@ void FieldDescriptorProto::clear_options() { } const ::google::protobuf::FieldOptions& FieldDescriptorProto::options() const { // @@protoc_insertion_point(field_get:google.protobuf.FieldDescriptorProto.options) - return options_ != NULL ? *options_ : *default_instance_->options_; + return options_ != NULL ? *options_ + : *::google::protobuf::FieldOptions::internal_default_instance(); } ::google::protobuf::FieldOptions* FieldDescriptorProto::mutable_options() { set_has_options(); @@ -5403,28 +5478,28 @@ const int OneofDescriptorProto::kOptionsFieldNumber; OneofDescriptorProto::OneofDescriptorProto() : ::google::protobuf::Message(), _internal_metadata_(NULL) { + if (this != internal_default_instance()) protobuf_InitDefaults_google_2fprotobuf_2fdescriptor_2eproto(); SharedCtor(); // @@protoc_insertion_point(constructor:google.protobuf.OneofDescriptorProto) } void OneofDescriptorProto::InitAsDefaultInstance() { - options_ = const_cast< ::google::protobuf::OneofOptions*>(&::google::protobuf::OneofOptions::default_instance()); + options_ = const_cast< ::google::protobuf::OneofOptions*>( + ::google::protobuf::OneofOptions::internal_default_instance()); } OneofDescriptorProto::OneofDescriptorProto(const OneofDescriptorProto& from) : ::google::protobuf::Message(), _internal_metadata_(NULL) { SharedCtor(); - MergeFrom(from); + UnsafeMergeFrom(from); // @@protoc_insertion_point(copy_constructor:google.protobuf.OneofDescriptorProto) } void OneofDescriptorProto::SharedCtor() { - ::google::protobuf::internal::GetEmptyString(); _cached_size_ = 0; name_.UnsafeSetDefault(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); options_ = NULL; - ::memset(_has_bits_, 0, sizeof(_has_bits_)); } OneofDescriptorProto::~OneofDescriptorProto() { @@ -5434,9 +5509,7 @@ OneofDescriptorProto::~OneofDescriptorProto() { void OneofDescriptorProto::SharedDtor() { name_.DestroyNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); - if (this != default_instance_) { - delete options_; - } + delete options_; } void OneofDescriptorProto::SetCachedSize(int size) const { @@ -5450,11 +5523,11 @@ const ::google::protobuf::Descriptor* OneofDescriptorProto::descriptor() { } const OneofDescriptorProto& OneofDescriptorProto::default_instance() { - if (default_instance_ == NULL) protobuf_AddDesc_google_2fprotobuf_2fdescriptor_2eproto(); - return *default_instance_; + protobuf_InitDefaults_google_2fprotobuf_2fdescriptor_2eproto(); + return *internal_default_instance(); } -OneofDescriptorProto* OneofDescriptorProto::default_instance_ = NULL; +::google::protobuf::internal::ExplicitlyConstructed OneofDescriptorProto::default_instance_; OneofDescriptorProto* OneofDescriptorProto::New(::google::protobuf::Arena* arena) const { OneofDescriptorProto* n = new OneofDescriptorProto; @@ -5474,7 +5547,7 @@ void OneofDescriptorProto::Clear() { if (options_ != NULL) options_->::google::protobuf::OneofOptions::Clear(); } } - ::memset(_has_bits_, 0, sizeof(_has_bits_)); + _has_bits_.Clear(); if (_internal_metadata_.have_unknown_fields()) { mutable_unknown_fields()->Clear(); } @@ -5597,9 +5670,9 @@ void OneofDescriptorProto::SerializeWithCachedSizes( return target; } -int OneofDescriptorProto::ByteSize() const { +size_t OneofDescriptorProto::ByteSizeLong() const { // @@protoc_insertion_point(message_byte_size_start:google.protobuf.OneofDescriptorProto) - int total_size = 0; + size_t total_size = 0; if (_has_bits_[0 / 32] & 3u) { // optional string name = 1; @@ -5622,18 +5695,17 @@ int OneofDescriptorProto::ByteSize() const { ::google::protobuf::internal::WireFormat::ComputeUnknownFieldsSize( unknown_fields()); } + int cached_size = ::google::protobuf::internal::ToCachedSize(total_size); GOOGLE_SAFE_CONCURRENT_WRITES_BEGIN(); - _cached_size_ = total_size; + _cached_size_ = cached_size; GOOGLE_SAFE_CONCURRENT_WRITES_END(); return total_size; } void OneofDescriptorProto::MergeFrom(const ::google::protobuf::Message& from) { // @@protoc_insertion_point(generalized_merge_from_start:google.protobuf.OneofDescriptorProto) - if (GOOGLE_PREDICT_FALSE(&from == this)) { - ::google::protobuf::internal::MergeFromFail(__FILE__, __LINE__); - } - const OneofDescriptorProto* source = + if (GOOGLE_PREDICT_FALSE(&from == this)) MergeFromFail(__LINE__); + const OneofDescriptorProto* source = ::google::protobuf::internal::DynamicCastToGenerated( &from); if (source == NULL) { @@ -5641,15 +5713,21 @@ void OneofDescriptorProto::MergeFrom(const ::google::protobuf::Message& from) { ::google::protobuf::internal::ReflectionOps::Merge(from, this); } else { // @@protoc_insertion_point(generalized_merge_from_cast_success:google.protobuf.OneofDescriptorProto) - MergeFrom(*source); + UnsafeMergeFrom(*source); } } void OneofDescriptorProto::MergeFrom(const OneofDescriptorProto& from) { // @@protoc_insertion_point(class_specific_merge_from_start:google.protobuf.OneofDescriptorProto) - if (GOOGLE_PREDICT_FALSE(&from == this)) { - ::google::protobuf::internal::MergeFromFail(__FILE__, __LINE__); + if (GOOGLE_PREDICT_TRUE(&from != this)) { + UnsafeMergeFrom(from); + } else { + MergeFromFail(__LINE__); } +} + +void OneofDescriptorProto::UnsafeMergeFrom(const OneofDescriptorProto& from) { + GOOGLE_DCHECK(&from != this); if (from._has_bits_[0 / 32] & (0xffu << (0 % 32))) { if (from.has_name()) { set_has_name(); @@ -5660,7 +5738,8 @@ void OneofDescriptorProto::MergeFrom(const OneofDescriptorProto& from) { } } if (from._internal_metadata_.have_unknown_fields()) { - mutable_unknown_fields()->MergeFrom(from.unknown_fields()); + ::google::protobuf::UnknownFieldSet::MergeToInternalMetdata( + from.unknown_fields(), &_internal_metadata_); } } @@ -5675,7 +5754,7 @@ void OneofDescriptorProto::CopyFrom(const OneofDescriptorProto& from) { // @@protoc_insertion_point(class_specific_copy_from_start:google.protobuf.OneofDescriptorProto) if (&from == this) return; Clear(); - MergeFrom(from); + UnsafeMergeFrom(from); } bool OneofDescriptorProto::IsInitialized() const { @@ -5723,37 +5802,37 @@ void OneofDescriptorProto::clear_name() { name_.ClearToEmptyNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); clear_has_name(); } - const ::std::string& OneofDescriptorProto::name() const { +const ::std::string& OneofDescriptorProto::name() const { // @@protoc_insertion_point(field_get:google.protobuf.OneofDescriptorProto.name) return name_.GetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); } - void OneofDescriptorProto::set_name(const ::std::string& value) { +void OneofDescriptorProto::set_name(const ::std::string& value) { set_has_name(); name_.SetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), value); // @@protoc_insertion_point(field_set:google.protobuf.OneofDescriptorProto.name) } - void OneofDescriptorProto::set_name(const char* value) { +void OneofDescriptorProto::set_name(const char* value) { set_has_name(); name_.SetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), ::std::string(value)); // @@protoc_insertion_point(field_set_char:google.protobuf.OneofDescriptorProto.name) } - void OneofDescriptorProto::set_name(const char* value, size_t size) { +void OneofDescriptorProto::set_name(const char* value, size_t size) { set_has_name(); name_.SetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), ::std::string(reinterpret_cast(value), size)); // @@protoc_insertion_point(field_set_pointer:google.protobuf.OneofDescriptorProto.name) } - ::std::string* OneofDescriptorProto::mutable_name() { +::std::string* OneofDescriptorProto::mutable_name() { set_has_name(); // @@protoc_insertion_point(field_mutable:google.protobuf.OneofDescriptorProto.name) return name_.MutableNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); } - ::std::string* OneofDescriptorProto::release_name() { +::std::string* OneofDescriptorProto::release_name() { // @@protoc_insertion_point(field_release:google.protobuf.OneofDescriptorProto.name) clear_has_name(); return name_.ReleaseNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); } - void OneofDescriptorProto::set_allocated_name(::std::string* name) { +void OneofDescriptorProto::set_allocated_name(::std::string* name) { if (name != NULL) { set_has_name(); } else { @@ -5779,7 +5858,8 @@ void OneofDescriptorProto::clear_options() { } const ::google::protobuf::OneofOptions& OneofDescriptorProto::options() const { // @@protoc_insertion_point(field_get:google.protobuf.OneofDescriptorProto.options) - return options_ != NULL ? *options_ : *default_instance_->options_; + return options_ != NULL ? *options_ + : *::google::protobuf::OneofOptions::internal_default_instance(); } ::google::protobuf::OneofOptions* OneofDescriptorProto::mutable_options() { set_has_options(); @@ -5819,28 +5899,28 @@ const int EnumDescriptorProto::kOptionsFieldNumber; EnumDescriptorProto::EnumDescriptorProto() : ::google::protobuf::Message(), _internal_metadata_(NULL) { + if (this != internal_default_instance()) protobuf_InitDefaults_google_2fprotobuf_2fdescriptor_2eproto(); SharedCtor(); // @@protoc_insertion_point(constructor:google.protobuf.EnumDescriptorProto) } void EnumDescriptorProto::InitAsDefaultInstance() { - options_ = const_cast< ::google::protobuf::EnumOptions*>(&::google::protobuf::EnumOptions::default_instance()); + options_ = const_cast< ::google::protobuf::EnumOptions*>( + ::google::protobuf::EnumOptions::internal_default_instance()); } EnumDescriptorProto::EnumDescriptorProto(const EnumDescriptorProto& from) : ::google::protobuf::Message(), _internal_metadata_(NULL) { SharedCtor(); - MergeFrom(from); + UnsafeMergeFrom(from); // @@protoc_insertion_point(copy_constructor:google.protobuf.EnumDescriptorProto) } void EnumDescriptorProto::SharedCtor() { - ::google::protobuf::internal::GetEmptyString(); _cached_size_ = 0; name_.UnsafeSetDefault(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); options_ = NULL; - ::memset(_has_bits_, 0, sizeof(_has_bits_)); } EnumDescriptorProto::~EnumDescriptorProto() { @@ -5850,9 +5930,7 @@ EnumDescriptorProto::~EnumDescriptorProto() { void EnumDescriptorProto::SharedDtor() { name_.DestroyNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); - if (this != default_instance_) { - delete options_; - } + delete options_; } void EnumDescriptorProto::SetCachedSize(int size) const { @@ -5866,11 +5944,11 @@ const ::google::protobuf::Descriptor* EnumDescriptorProto::descriptor() { } const EnumDescriptorProto& EnumDescriptorProto::default_instance() { - if (default_instance_ == NULL) protobuf_AddDesc_google_2fprotobuf_2fdescriptor_2eproto(); - return *default_instance_; + protobuf_InitDefaults_google_2fprotobuf_2fdescriptor_2eproto(); + return *internal_default_instance(); } -EnumDescriptorProto* EnumDescriptorProto::default_instance_ = NULL; +::google::protobuf::internal::ExplicitlyConstructed EnumDescriptorProto::default_instance_; EnumDescriptorProto* EnumDescriptorProto::New(::google::protobuf::Arena* arena) const { EnumDescriptorProto* n = new EnumDescriptorProto; @@ -5891,7 +5969,7 @@ void EnumDescriptorProto::Clear() { } } value_.Clear(); - ::memset(_has_bits_, 0, sizeof(_has_bits_)); + _has_bits_.Clear(); if (_internal_metadata_.have_unknown_fields()) { mutable_unknown_fields()->Clear(); } @@ -6044,9 +6122,9 @@ void EnumDescriptorProto::SerializeWithCachedSizes( return target; } -int EnumDescriptorProto::ByteSize() const { +size_t EnumDescriptorProto::ByteSizeLong() const { // @@protoc_insertion_point(message_byte_size_start:google.protobuf.EnumDescriptorProto) - int total_size = 0; + size_t total_size = 0; if (_has_bits_[0 / 32] & 5u) { // optional string name = 1; @@ -6065,11 +6143,14 @@ int EnumDescriptorProto::ByteSize() const { } // repeated .google.protobuf.EnumValueDescriptorProto value = 2; - total_size += 1 * this->value_size(); - for (int i = 0; i < this->value_size(); i++) { - total_size += - ::google::protobuf::internal::WireFormatLite::MessageSizeNoVirtual( - this->value(i)); + { + unsigned int count = this->value_size(); + total_size += 1UL * count; + for (unsigned int i = 0; i < count; i++) { + total_size += + ::google::protobuf::internal::WireFormatLite::MessageSizeNoVirtual( + this->value(i)); + } } if (_internal_metadata_.have_unknown_fields()) { @@ -6077,18 +6158,17 @@ int EnumDescriptorProto::ByteSize() const { ::google::protobuf::internal::WireFormat::ComputeUnknownFieldsSize( unknown_fields()); } + int cached_size = ::google::protobuf::internal::ToCachedSize(total_size); GOOGLE_SAFE_CONCURRENT_WRITES_BEGIN(); - _cached_size_ = total_size; + _cached_size_ = cached_size; GOOGLE_SAFE_CONCURRENT_WRITES_END(); return total_size; } void EnumDescriptorProto::MergeFrom(const ::google::protobuf::Message& from) { // @@protoc_insertion_point(generalized_merge_from_start:google.protobuf.EnumDescriptorProto) - if (GOOGLE_PREDICT_FALSE(&from == this)) { - ::google::protobuf::internal::MergeFromFail(__FILE__, __LINE__); - } - const EnumDescriptorProto* source = + if (GOOGLE_PREDICT_FALSE(&from == this)) MergeFromFail(__LINE__); + const EnumDescriptorProto* source = ::google::protobuf::internal::DynamicCastToGenerated( &from); if (source == NULL) { @@ -6096,15 +6176,21 @@ void EnumDescriptorProto::MergeFrom(const ::google::protobuf::Message& from) { ::google::protobuf::internal::ReflectionOps::Merge(from, this); } else { // @@protoc_insertion_point(generalized_merge_from_cast_success:google.protobuf.EnumDescriptorProto) - MergeFrom(*source); + UnsafeMergeFrom(*source); } } void EnumDescriptorProto::MergeFrom(const EnumDescriptorProto& from) { // @@protoc_insertion_point(class_specific_merge_from_start:google.protobuf.EnumDescriptorProto) - if (GOOGLE_PREDICT_FALSE(&from == this)) { - ::google::protobuf::internal::MergeFromFail(__FILE__, __LINE__); + if (GOOGLE_PREDICT_TRUE(&from != this)) { + UnsafeMergeFrom(from); + } else { + MergeFromFail(__LINE__); } +} + +void EnumDescriptorProto::UnsafeMergeFrom(const EnumDescriptorProto& from) { + GOOGLE_DCHECK(&from != this); value_.MergeFrom(from.value_); if (from._has_bits_[0 / 32] & (0xffu << (0 % 32))) { if (from.has_name()) { @@ -6116,7 +6202,8 @@ void EnumDescriptorProto::MergeFrom(const EnumDescriptorProto& from) { } } if (from._internal_metadata_.have_unknown_fields()) { - mutable_unknown_fields()->MergeFrom(from.unknown_fields()); + ::google::protobuf::UnknownFieldSet::MergeToInternalMetdata( + from.unknown_fields(), &_internal_metadata_); } } @@ -6131,7 +6218,7 @@ void EnumDescriptorProto::CopyFrom(const EnumDescriptorProto& from) { // @@protoc_insertion_point(class_specific_copy_from_start:google.protobuf.EnumDescriptorProto) if (&from == this) return; Clear(); - MergeFrom(from); + UnsafeMergeFrom(from); } bool EnumDescriptorProto::IsInitialized() const { @@ -6181,37 +6268,37 @@ void EnumDescriptorProto::clear_name() { name_.ClearToEmptyNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); clear_has_name(); } - const ::std::string& EnumDescriptorProto::name() const { +const ::std::string& EnumDescriptorProto::name() const { // @@protoc_insertion_point(field_get:google.protobuf.EnumDescriptorProto.name) return name_.GetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); } - void EnumDescriptorProto::set_name(const ::std::string& value) { +void EnumDescriptorProto::set_name(const ::std::string& value) { set_has_name(); name_.SetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), value); // @@protoc_insertion_point(field_set:google.protobuf.EnumDescriptorProto.name) } - void EnumDescriptorProto::set_name(const char* value) { +void EnumDescriptorProto::set_name(const char* value) { set_has_name(); name_.SetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), ::std::string(value)); // @@protoc_insertion_point(field_set_char:google.protobuf.EnumDescriptorProto.name) } - void EnumDescriptorProto::set_name(const char* value, size_t size) { +void EnumDescriptorProto::set_name(const char* value, size_t size) { set_has_name(); name_.SetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), ::std::string(reinterpret_cast(value), size)); // @@protoc_insertion_point(field_set_pointer:google.protobuf.EnumDescriptorProto.name) } - ::std::string* EnumDescriptorProto::mutable_name() { +::std::string* EnumDescriptorProto::mutable_name() { set_has_name(); // @@protoc_insertion_point(field_mutable:google.protobuf.EnumDescriptorProto.name) return name_.MutableNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); } - ::std::string* EnumDescriptorProto::release_name() { +::std::string* EnumDescriptorProto::release_name() { // @@protoc_insertion_point(field_release:google.protobuf.EnumDescriptorProto.name) clear_has_name(); return name_.ReleaseNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); } - void EnumDescriptorProto::set_allocated_name(::std::string* name) { +void EnumDescriptorProto::set_allocated_name(::std::string* name) { if (name != NULL) { set_has_name(); } else { @@ -6267,7 +6354,8 @@ void EnumDescriptorProto::clear_options() { } const ::google::protobuf::EnumOptions& EnumDescriptorProto::options() const { // @@protoc_insertion_point(field_get:google.protobuf.EnumDescriptorProto.options) - return options_ != NULL ? *options_ : *default_instance_->options_; + return options_ != NULL ? *options_ + : *::google::protobuf::EnumOptions::internal_default_instance(); } ::google::protobuf::EnumOptions* EnumDescriptorProto::mutable_options() { set_has_options(); @@ -6307,29 +6395,29 @@ const int EnumValueDescriptorProto::kOptionsFieldNumber; EnumValueDescriptorProto::EnumValueDescriptorProto() : ::google::protobuf::Message(), _internal_metadata_(NULL) { + if (this != internal_default_instance()) protobuf_InitDefaults_google_2fprotobuf_2fdescriptor_2eproto(); SharedCtor(); // @@protoc_insertion_point(constructor:google.protobuf.EnumValueDescriptorProto) } void EnumValueDescriptorProto::InitAsDefaultInstance() { - options_ = const_cast< ::google::protobuf::EnumValueOptions*>(&::google::protobuf::EnumValueOptions::default_instance()); + options_ = const_cast< ::google::protobuf::EnumValueOptions*>( + ::google::protobuf::EnumValueOptions::internal_default_instance()); } EnumValueDescriptorProto::EnumValueDescriptorProto(const EnumValueDescriptorProto& from) : ::google::protobuf::Message(), _internal_metadata_(NULL) { SharedCtor(); - MergeFrom(from); + UnsafeMergeFrom(from); // @@protoc_insertion_point(copy_constructor:google.protobuf.EnumValueDescriptorProto) } void EnumValueDescriptorProto::SharedCtor() { - ::google::protobuf::internal::GetEmptyString(); _cached_size_ = 0; name_.UnsafeSetDefault(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); - number_ = 0; options_ = NULL; - ::memset(_has_bits_, 0, sizeof(_has_bits_)); + number_ = 0; } EnumValueDescriptorProto::~EnumValueDescriptorProto() { @@ -6339,9 +6427,7 @@ EnumValueDescriptorProto::~EnumValueDescriptorProto() { void EnumValueDescriptorProto::SharedDtor() { name_.DestroyNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); - if (this != default_instance_) { - delete options_; - } + delete options_; } void EnumValueDescriptorProto::SetCachedSize(int size) const { @@ -6355,11 +6441,11 @@ const ::google::protobuf::Descriptor* EnumValueDescriptorProto::descriptor() { } const EnumValueDescriptorProto& EnumValueDescriptorProto::default_instance() { - if (default_instance_ == NULL) protobuf_AddDesc_google_2fprotobuf_2fdescriptor_2eproto(); - return *default_instance_; + protobuf_InitDefaults_google_2fprotobuf_2fdescriptor_2eproto(); + return *internal_default_instance(); } -EnumValueDescriptorProto* EnumValueDescriptorProto::default_instance_ = NULL; +::google::protobuf::internal::ExplicitlyConstructed EnumValueDescriptorProto::default_instance_; EnumValueDescriptorProto* EnumValueDescriptorProto::New(::google::protobuf::Arena* arena) const { EnumValueDescriptorProto* n = new EnumValueDescriptorProto; @@ -6380,7 +6466,7 @@ void EnumValueDescriptorProto::Clear() { if (options_ != NULL) options_->::google::protobuf::EnumValueOptions::Clear(); } } - ::memset(_has_bits_, 0, sizeof(_has_bits_)); + _has_bits_.Clear(); if (_internal_metadata_.have_unknown_fields()) { mutable_unknown_fields()->Clear(); } @@ -6416,10 +6502,10 @@ bool EnumValueDescriptorProto::MergePartialFromCodedStream( case 2: { if (tag == 16) { parse_number: + set_has_number(); DO_((::google::protobuf::internal::WireFormatLite::ReadPrimitive< ::google::protobuf::int32, ::google::protobuf::internal::WireFormatLite::TYPE_INT32>( input, &number_))); - set_has_number(); } else { goto handle_unusual; } @@ -6528,9 +6614,9 @@ void EnumValueDescriptorProto::SerializeWithCachedSizes( return target; } -int EnumValueDescriptorProto::ByteSize() const { +size_t EnumValueDescriptorProto::ByteSizeLong() const { // @@protoc_insertion_point(message_byte_size_start:google.protobuf.EnumValueDescriptorProto) - int total_size = 0; + size_t total_size = 0; if (_has_bits_[0 / 32] & 7u) { // optional string name = 1; @@ -6560,18 +6646,17 @@ int EnumValueDescriptorProto::ByteSize() const { ::google::protobuf::internal::WireFormat::ComputeUnknownFieldsSize( unknown_fields()); } + int cached_size = ::google::protobuf::internal::ToCachedSize(total_size); GOOGLE_SAFE_CONCURRENT_WRITES_BEGIN(); - _cached_size_ = total_size; + _cached_size_ = cached_size; GOOGLE_SAFE_CONCURRENT_WRITES_END(); return total_size; } void EnumValueDescriptorProto::MergeFrom(const ::google::protobuf::Message& from) { // @@protoc_insertion_point(generalized_merge_from_start:google.protobuf.EnumValueDescriptorProto) - if (GOOGLE_PREDICT_FALSE(&from == this)) { - ::google::protobuf::internal::MergeFromFail(__FILE__, __LINE__); - } - const EnumValueDescriptorProto* source = + if (GOOGLE_PREDICT_FALSE(&from == this)) MergeFromFail(__LINE__); + const EnumValueDescriptorProto* source = ::google::protobuf::internal::DynamicCastToGenerated( &from); if (source == NULL) { @@ -6579,15 +6664,21 @@ void EnumValueDescriptorProto::MergeFrom(const ::google::protobuf::Message& from ::google::protobuf::internal::ReflectionOps::Merge(from, this); } else { // @@protoc_insertion_point(generalized_merge_from_cast_success:google.protobuf.EnumValueDescriptorProto) - MergeFrom(*source); + UnsafeMergeFrom(*source); } } void EnumValueDescriptorProto::MergeFrom(const EnumValueDescriptorProto& from) { // @@protoc_insertion_point(class_specific_merge_from_start:google.protobuf.EnumValueDescriptorProto) - if (GOOGLE_PREDICT_FALSE(&from == this)) { - ::google::protobuf::internal::MergeFromFail(__FILE__, __LINE__); + if (GOOGLE_PREDICT_TRUE(&from != this)) { + UnsafeMergeFrom(from); + } else { + MergeFromFail(__LINE__); } +} + +void EnumValueDescriptorProto::UnsafeMergeFrom(const EnumValueDescriptorProto& from) { + GOOGLE_DCHECK(&from != this); if (from._has_bits_[0 / 32] & (0xffu << (0 % 32))) { if (from.has_name()) { set_has_name(); @@ -6601,7 +6692,8 @@ void EnumValueDescriptorProto::MergeFrom(const EnumValueDescriptorProto& from) { } } if (from._internal_metadata_.have_unknown_fields()) { - mutable_unknown_fields()->MergeFrom(from.unknown_fields()); + ::google::protobuf::UnknownFieldSet::MergeToInternalMetdata( + from.unknown_fields(), &_internal_metadata_); } } @@ -6616,7 +6708,7 @@ void EnumValueDescriptorProto::CopyFrom(const EnumValueDescriptorProto& from) { // @@protoc_insertion_point(class_specific_copy_from_start:google.protobuf.EnumValueDescriptorProto) if (&from == this) return; Clear(); - MergeFrom(from); + UnsafeMergeFrom(from); } bool EnumValueDescriptorProto::IsInitialized() const { @@ -6665,37 +6757,37 @@ void EnumValueDescriptorProto::clear_name() { name_.ClearToEmptyNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); clear_has_name(); } - const ::std::string& EnumValueDescriptorProto::name() const { +const ::std::string& EnumValueDescriptorProto::name() const { // @@protoc_insertion_point(field_get:google.protobuf.EnumValueDescriptorProto.name) return name_.GetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); } - void EnumValueDescriptorProto::set_name(const ::std::string& value) { +void EnumValueDescriptorProto::set_name(const ::std::string& value) { set_has_name(); name_.SetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), value); // @@protoc_insertion_point(field_set:google.protobuf.EnumValueDescriptorProto.name) } - void EnumValueDescriptorProto::set_name(const char* value) { +void EnumValueDescriptorProto::set_name(const char* value) { set_has_name(); name_.SetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), ::std::string(value)); // @@protoc_insertion_point(field_set_char:google.protobuf.EnumValueDescriptorProto.name) } - void EnumValueDescriptorProto::set_name(const char* value, size_t size) { +void EnumValueDescriptorProto::set_name(const char* value, size_t size) { set_has_name(); name_.SetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), ::std::string(reinterpret_cast(value), size)); // @@protoc_insertion_point(field_set_pointer:google.protobuf.EnumValueDescriptorProto.name) } - ::std::string* EnumValueDescriptorProto::mutable_name() { +::std::string* EnumValueDescriptorProto::mutable_name() { set_has_name(); // @@protoc_insertion_point(field_mutable:google.protobuf.EnumValueDescriptorProto.name) return name_.MutableNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); } - ::std::string* EnumValueDescriptorProto::release_name() { +::std::string* EnumValueDescriptorProto::release_name() { // @@protoc_insertion_point(field_release:google.protobuf.EnumValueDescriptorProto.name) clear_has_name(); return name_.ReleaseNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); } - void EnumValueDescriptorProto::set_allocated_name(::std::string* name) { +void EnumValueDescriptorProto::set_allocated_name(::std::string* name) { if (name != NULL) { set_has_name(); } else { @@ -6719,11 +6811,11 @@ void EnumValueDescriptorProto::clear_number() { number_ = 0; clear_has_number(); } - ::google::protobuf::int32 EnumValueDescriptorProto::number() const { +::google::protobuf::int32 EnumValueDescriptorProto::number() const { // @@protoc_insertion_point(field_get:google.protobuf.EnumValueDescriptorProto.number) return number_; } - void EnumValueDescriptorProto::set_number(::google::protobuf::int32 value) { +void EnumValueDescriptorProto::set_number(::google::protobuf::int32 value) { set_has_number(); number_ = value; // @@protoc_insertion_point(field_set:google.protobuf.EnumValueDescriptorProto.number) @@ -6745,7 +6837,8 @@ void EnumValueDescriptorProto::clear_options() { } const ::google::protobuf::EnumValueOptions& EnumValueDescriptorProto::options() const { // @@protoc_insertion_point(field_get:google.protobuf.EnumValueDescriptorProto.options) - return options_ != NULL ? *options_ : *default_instance_->options_; + return options_ != NULL ? *options_ + : *::google::protobuf::EnumValueOptions::internal_default_instance(); } ::google::protobuf::EnumValueOptions* EnumValueDescriptorProto::mutable_options() { set_has_options(); @@ -6785,28 +6878,28 @@ const int ServiceDescriptorProto::kOptionsFieldNumber; ServiceDescriptorProto::ServiceDescriptorProto() : ::google::protobuf::Message(), _internal_metadata_(NULL) { + if (this != internal_default_instance()) protobuf_InitDefaults_google_2fprotobuf_2fdescriptor_2eproto(); SharedCtor(); // @@protoc_insertion_point(constructor:google.protobuf.ServiceDescriptorProto) } void ServiceDescriptorProto::InitAsDefaultInstance() { - options_ = const_cast< ::google::protobuf::ServiceOptions*>(&::google::protobuf::ServiceOptions::default_instance()); + options_ = const_cast< ::google::protobuf::ServiceOptions*>( + ::google::protobuf::ServiceOptions::internal_default_instance()); } ServiceDescriptorProto::ServiceDescriptorProto(const ServiceDescriptorProto& from) : ::google::protobuf::Message(), _internal_metadata_(NULL) { SharedCtor(); - MergeFrom(from); + UnsafeMergeFrom(from); // @@protoc_insertion_point(copy_constructor:google.protobuf.ServiceDescriptorProto) } void ServiceDescriptorProto::SharedCtor() { - ::google::protobuf::internal::GetEmptyString(); _cached_size_ = 0; name_.UnsafeSetDefault(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); options_ = NULL; - ::memset(_has_bits_, 0, sizeof(_has_bits_)); } ServiceDescriptorProto::~ServiceDescriptorProto() { @@ -6816,9 +6909,7 @@ ServiceDescriptorProto::~ServiceDescriptorProto() { void ServiceDescriptorProto::SharedDtor() { name_.DestroyNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); - if (this != default_instance_) { - delete options_; - } + delete options_; } void ServiceDescriptorProto::SetCachedSize(int size) const { @@ -6832,11 +6923,11 @@ const ::google::protobuf::Descriptor* ServiceDescriptorProto::descriptor() { } const ServiceDescriptorProto& ServiceDescriptorProto::default_instance() { - if (default_instance_ == NULL) protobuf_AddDesc_google_2fprotobuf_2fdescriptor_2eproto(); - return *default_instance_; + protobuf_InitDefaults_google_2fprotobuf_2fdescriptor_2eproto(); + return *internal_default_instance(); } -ServiceDescriptorProto* ServiceDescriptorProto::default_instance_ = NULL; +::google::protobuf::internal::ExplicitlyConstructed ServiceDescriptorProto::default_instance_; ServiceDescriptorProto* ServiceDescriptorProto::New(::google::protobuf::Arena* arena) const { ServiceDescriptorProto* n = new ServiceDescriptorProto; @@ -6857,7 +6948,7 @@ void ServiceDescriptorProto::Clear() { } } method_.Clear(); - ::memset(_has_bits_, 0, sizeof(_has_bits_)); + _has_bits_.Clear(); if (_internal_metadata_.have_unknown_fields()) { mutable_unknown_fields()->Clear(); } @@ -7010,9 +7101,9 @@ void ServiceDescriptorProto::SerializeWithCachedSizes( return target; } -int ServiceDescriptorProto::ByteSize() const { +size_t ServiceDescriptorProto::ByteSizeLong() const { // @@protoc_insertion_point(message_byte_size_start:google.protobuf.ServiceDescriptorProto) - int total_size = 0; + size_t total_size = 0; if (_has_bits_[0 / 32] & 5u) { // optional string name = 1; @@ -7031,11 +7122,14 @@ int ServiceDescriptorProto::ByteSize() const { } // repeated .google.protobuf.MethodDescriptorProto method = 2; - total_size += 1 * this->method_size(); - for (int i = 0; i < this->method_size(); i++) { - total_size += - ::google::protobuf::internal::WireFormatLite::MessageSizeNoVirtual( - this->method(i)); + { + unsigned int count = this->method_size(); + total_size += 1UL * count; + for (unsigned int i = 0; i < count; i++) { + total_size += + ::google::protobuf::internal::WireFormatLite::MessageSizeNoVirtual( + this->method(i)); + } } if (_internal_metadata_.have_unknown_fields()) { @@ -7043,18 +7137,17 @@ int ServiceDescriptorProto::ByteSize() const { ::google::protobuf::internal::WireFormat::ComputeUnknownFieldsSize( unknown_fields()); } + int cached_size = ::google::protobuf::internal::ToCachedSize(total_size); GOOGLE_SAFE_CONCURRENT_WRITES_BEGIN(); - _cached_size_ = total_size; + _cached_size_ = cached_size; GOOGLE_SAFE_CONCURRENT_WRITES_END(); return total_size; } void ServiceDescriptorProto::MergeFrom(const ::google::protobuf::Message& from) { // @@protoc_insertion_point(generalized_merge_from_start:google.protobuf.ServiceDescriptorProto) - if (GOOGLE_PREDICT_FALSE(&from == this)) { - ::google::protobuf::internal::MergeFromFail(__FILE__, __LINE__); - } - const ServiceDescriptorProto* source = + if (GOOGLE_PREDICT_FALSE(&from == this)) MergeFromFail(__LINE__); + const ServiceDescriptorProto* source = ::google::protobuf::internal::DynamicCastToGenerated( &from); if (source == NULL) { @@ -7062,15 +7155,21 @@ void ServiceDescriptorProto::MergeFrom(const ::google::protobuf::Message& from) ::google::protobuf::internal::ReflectionOps::Merge(from, this); } else { // @@protoc_insertion_point(generalized_merge_from_cast_success:google.protobuf.ServiceDescriptorProto) - MergeFrom(*source); + UnsafeMergeFrom(*source); } } void ServiceDescriptorProto::MergeFrom(const ServiceDescriptorProto& from) { // @@protoc_insertion_point(class_specific_merge_from_start:google.protobuf.ServiceDescriptorProto) - if (GOOGLE_PREDICT_FALSE(&from == this)) { - ::google::protobuf::internal::MergeFromFail(__FILE__, __LINE__); + if (GOOGLE_PREDICT_TRUE(&from != this)) { + UnsafeMergeFrom(from); + } else { + MergeFromFail(__LINE__); } +} + +void ServiceDescriptorProto::UnsafeMergeFrom(const ServiceDescriptorProto& from) { + GOOGLE_DCHECK(&from != this); method_.MergeFrom(from.method_); if (from._has_bits_[0 / 32] & (0xffu << (0 % 32))) { if (from.has_name()) { @@ -7082,7 +7181,8 @@ void ServiceDescriptorProto::MergeFrom(const ServiceDescriptorProto& from) { } } if (from._internal_metadata_.have_unknown_fields()) { - mutable_unknown_fields()->MergeFrom(from.unknown_fields()); + ::google::protobuf::UnknownFieldSet::MergeToInternalMetdata( + from.unknown_fields(), &_internal_metadata_); } } @@ -7097,7 +7197,7 @@ void ServiceDescriptorProto::CopyFrom(const ServiceDescriptorProto& from) { // @@protoc_insertion_point(class_specific_copy_from_start:google.protobuf.ServiceDescriptorProto) if (&from == this) return; Clear(); - MergeFrom(from); + UnsafeMergeFrom(from); } bool ServiceDescriptorProto::IsInitialized() const { @@ -7147,37 +7247,37 @@ void ServiceDescriptorProto::clear_name() { name_.ClearToEmptyNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); clear_has_name(); } - const ::std::string& ServiceDescriptorProto::name() const { +const ::std::string& ServiceDescriptorProto::name() const { // @@protoc_insertion_point(field_get:google.protobuf.ServiceDescriptorProto.name) return name_.GetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); } - void ServiceDescriptorProto::set_name(const ::std::string& value) { +void ServiceDescriptorProto::set_name(const ::std::string& value) { set_has_name(); name_.SetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), value); // @@protoc_insertion_point(field_set:google.protobuf.ServiceDescriptorProto.name) } - void ServiceDescriptorProto::set_name(const char* value) { +void ServiceDescriptorProto::set_name(const char* value) { set_has_name(); name_.SetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), ::std::string(value)); // @@protoc_insertion_point(field_set_char:google.protobuf.ServiceDescriptorProto.name) } - void ServiceDescriptorProto::set_name(const char* value, size_t size) { +void ServiceDescriptorProto::set_name(const char* value, size_t size) { set_has_name(); name_.SetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), ::std::string(reinterpret_cast(value), size)); // @@protoc_insertion_point(field_set_pointer:google.protobuf.ServiceDescriptorProto.name) } - ::std::string* ServiceDescriptorProto::mutable_name() { +::std::string* ServiceDescriptorProto::mutable_name() { set_has_name(); // @@protoc_insertion_point(field_mutable:google.protobuf.ServiceDescriptorProto.name) return name_.MutableNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); } - ::std::string* ServiceDescriptorProto::release_name() { +::std::string* ServiceDescriptorProto::release_name() { // @@protoc_insertion_point(field_release:google.protobuf.ServiceDescriptorProto.name) clear_has_name(); return name_.ReleaseNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); } - void ServiceDescriptorProto::set_allocated_name(::std::string* name) { +void ServiceDescriptorProto::set_allocated_name(::std::string* name) { if (name != NULL) { set_has_name(); } else { @@ -7233,7 +7333,8 @@ void ServiceDescriptorProto::clear_options() { } const ::google::protobuf::ServiceOptions& ServiceDescriptorProto::options() const { // @@protoc_insertion_point(field_get:google.protobuf.ServiceDescriptorProto.options) - return options_ != NULL ? *options_ : *default_instance_->options_; + return options_ != NULL ? *options_ + : *::google::protobuf::ServiceOptions::internal_default_instance(); } ::google::protobuf::ServiceOptions* ServiceDescriptorProto::mutable_options() { set_has_options(); @@ -7276,32 +7377,32 @@ const int MethodDescriptorProto::kServerStreamingFieldNumber; MethodDescriptorProto::MethodDescriptorProto() : ::google::protobuf::Message(), _internal_metadata_(NULL) { + if (this != internal_default_instance()) protobuf_InitDefaults_google_2fprotobuf_2fdescriptor_2eproto(); SharedCtor(); // @@protoc_insertion_point(constructor:google.protobuf.MethodDescriptorProto) } void MethodDescriptorProto::InitAsDefaultInstance() { - options_ = const_cast< ::google::protobuf::MethodOptions*>(&::google::protobuf::MethodOptions::default_instance()); + options_ = const_cast< ::google::protobuf::MethodOptions*>( + ::google::protobuf::MethodOptions::internal_default_instance()); } MethodDescriptorProto::MethodDescriptorProto(const MethodDescriptorProto& from) : ::google::protobuf::Message(), _internal_metadata_(NULL) { SharedCtor(); - MergeFrom(from); + UnsafeMergeFrom(from); // @@protoc_insertion_point(copy_constructor:google.protobuf.MethodDescriptorProto) } void MethodDescriptorProto::SharedCtor() { - ::google::protobuf::internal::GetEmptyString(); _cached_size_ = 0; name_.UnsafeSetDefault(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); input_type_.UnsafeSetDefault(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); output_type_.UnsafeSetDefault(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); options_ = NULL; - client_streaming_ = false; - server_streaming_ = false; - ::memset(_has_bits_, 0, sizeof(_has_bits_)); + ::memset(&client_streaming_, 0, reinterpret_cast(&server_streaming_) - + reinterpret_cast(&client_streaming_) + sizeof(server_streaming_)); } MethodDescriptorProto::~MethodDescriptorProto() { @@ -7313,9 +7414,7 @@ void MethodDescriptorProto::SharedDtor() { name_.DestroyNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); input_type_.DestroyNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); output_type_.DestroyNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); - if (this != default_instance_) { - delete options_; - } + delete options_; } void MethodDescriptorProto::SetCachedSize(int size) const { @@ -7329,11 +7428,11 @@ const ::google::protobuf::Descriptor* MethodDescriptorProto::descriptor() { } const MethodDescriptorProto& MethodDescriptorProto::default_instance() { - if (default_instance_ == NULL) protobuf_AddDesc_google_2fprotobuf_2fdescriptor_2eproto(); - return *default_instance_; + protobuf_InitDefaults_google_2fprotobuf_2fdescriptor_2eproto(); + return *internal_default_instance(); } -MethodDescriptorProto* MethodDescriptorProto::default_instance_ = NULL; +::google::protobuf::internal::ExplicitlyConstructed MethodDescriptorProto::default_instance_; MethodDescriptorProto* MethodDescriptorProto::New(::google::protobuf::Arena* arena) const { MethodDescriptorProto* n = new MethodDescriptorProto; @@ -7380,7 +7479,7 @@ void MethodDescriptorProto::Clear() { #undef ZR_HELPER_ #undef ZR_ - ::memset(_has_bits_, 0, sizeof(_has_bits_)); + _has_bits_.Clear(); if (_internal_metadata_.have_unknown_fields()) { mutable_unknown_fields()->Clear(); } @@ -7463,10 +7562,10 @@ bool MethodDescriptorProto::MergePartialFromCodedStream( case 5: { if (tag == 40) { parse_client_streaming: + set_has_client_streaming(); DO_((::google::protobuf::internal::WireFormatLite::ReadPrimitive< bool, ::google::protobuf::internal::WireFormatLite::TYPE_BOOL>( input, &client_streaming_))); - set_has_client_streaming(); } else { goto handle_unusual; } @@ -7478,10 +7577,10 @@ bool MethodDescriptorProto::MergePartialFromCodedStream( case 6: { if (tag == 48) { parse_server_streaming: + set_has_server_streaming(); DO_((::google::protobuf::internal::WireFormatLite::ReadPrimitive< bool, ::google::protobuf::internal::WireFormatLite::TYPE_BOOL>( input, &server_streaming_))); - set_has_server_streaming(); } else { goto handle_unusual; } @@ -7629,9 +7728,9 @@ void MethodDescriptorProto::SerializeWithCachedSizes( return target; } -int MethodDescriptorProto::ByteSize() const { +size_t MethodDescriptorProto::ByteSizeLong() const { // @@protoc_insertion_point(message_byte_size_start:google.protobuf.MethodDescriptorProto) - int total_size = 0; + size_t total_size = 0; if (_has_bits_[0 / 32] & 63u) { // optional string name = 1; @@ -7678,18 +7777,17 @@ int MethodDescriptorProto::ByteSize() const { ::google::protobuf::internal::WireFormat::ComputeUnknownFieldsSize( unknown_fields()); } + int cached_size = ::google::protobuf::internal::ToCachedSize(total_size); GOOGLE_SAFE_CONCURRENT_WRITES_BEGIN(); - _cached_size_ = total_size; + _cached_size_ = cached_size; GOOGLE_SAFE_CONCURRENT_WRITES_END(); return total_size; } void MethodDescriptorProto::MergeFrom(const ::google::protobuf::Message& from) { // @@protoc_insertion_point(generalized_merge_from_start:google.protobuf.MethodDescriptorProto) - if (GOOGLE_PREDICT_FALSE(&from == this)) { - ::google::protobuf::internal::MergeFromFail(__FILE__, __LINE__); - } - const MethodDescriptorProto* source = + if (GOOGLE_PREDICT_FALSE(&from == this)) MergeFromFail(__LINE__); + const MethodDescriptorProto* source = ::google::protobuf::internal::DynamicCastToGenerated( &from); if (source == NULL) { @@ -7697,15 +7795,21 @@ void MethodDescriptorProto::MergeFrom(const ::google::protobuf::Message& from) { ::google::protobuf::internal::ReflectionOps::Merge(from, this); } else { // @@protoc_insertion_point(generalized_merge_from_cast_success:google.protobuf.MethodDescriptorProto) - MergeFrom(*source); + UnsafeMergeFrom(*source); } } void MethodDescriptorProto::MergeFrom(const MethodDescriptorProto& from) { // @@protoc_insertion_point(class_specific_merge_from_start:google.protobuf.MethodDescriptorProto) - if (GOOGLE_PREDICT_FALSE(&from == this)) { - ::google::protobuf::internal::MergeFromFail(__FILE__, __LINE__); + if (GOOGLE_PREDICT_TRUE(&from != this)) { + UnsafeMergeFrom(from); + } else { + MergeFromFail(__LINE__); } +} + +void MethodDescriptorProto::UnsafeMergeFrom(const MethodDescriptorProto& from) { + GOOGLE_DCHECK(&from != this); if (from._has_bits_[0 / 32] & (0xffu << (0 % 32))) { if (from.has_name()) { set_has_name(); @@ -7730,7 +7834,8 @@ void MethodDescriptorProto::MergeFrom(const MethodDescriptorProto& from) { } } if (from._internal_metadata_.have_unknown_fields()) { - mutable_unknown_fields()->MergeFrom(from.unknown_fields()); + ::google::protobuf::UnknownFieldSet::MergeToInternalMetdata( + from.unknown_fields(), &_internal_metadata_); } } @@ -7745,7 +7850,7 @@ void MethodDescriptorProto::CopyFrom(const MethodDescriptorProto& from) { // @@protoc_insertion_point(class_specific_copy_from_start:google.protobuf.MethodDescriptorProto) if (&from == this) return; Clear(); - MergeFrom(from); + UnsafeMergeFrom(from); } bool MethodDescriptorProto::IsInitialized() const { @@ -7797,37 +7902,37 @@ void MethodDescriptorProto::clear_name() { name_.ClearToEmptyNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); clear_has_name(); } - const ::std::string& MethodDescriptorProto::name() const { +const ::std::string& MethodDescriptorProto::name() const { // @@protoc_insertion_point(field_get:google.protobuf.MethodDescriptorProto.name) return name_.GetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); } - void MethodDescriptorProto::set_name(const ::std::string& value) { +void MethodDescriptorProto::set_name(const ::std::string& value) { set_has_name(); name_.SetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), value); // @@protoc_insertion_point(field_set:google.protobuf.MethodDescriptorProto.name) } - void MethodDescriptorProto::set_name(const char* value) { +void MethodDescriptorProto::set_name(const char* value) { set_has_name(); name_.SetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), ::std::string(value)); // @@protoc_insertion_point(field_set_char:google.protobuf.MethodDescriptorProto.name) } - void MethodDescriptorProto::set_name(const char* value, size_t size) { +void MethodDescriptorProto::set_name(const char* value, size_t size) { set_has_name(); name_.SetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), ::std::string(reinterpret_cast(value), size)); // @@protoc_insertion_point(field_set_pointer:google.protobuf.MethodDescriptorProto.name) } - ::std::string* MethodDescriptorProto::mutable_name() { +::std::string* MethodDescriptorProto::mutable_name() { set_has_name(); // @@protoc_insertion_point(field_mutable:google.protobuf.MethodDescriptorProto.name) return name_.MutableNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); } - ::std::string* MethodDescriptorProto::release_name() { +::std::string* MethodDescriptorProto::release_name() { // @@protoc_insertion_point(field_release:google.protobuf.MethodDescriptorProto.name) clear_has_name(); return name_.ReleaseNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); } - void MethodDescriptorProto::set_allocated_name(::std::string* name) { +void MethodDescriptorProto::set_allocated_name(::std::string* name) { if (name != NULL) { set_has_name(); } else { @@ -7851,37 +7956,37 @@ void MethodDescriptorProto::clear_input_type() { input_type_.ClearToEmptyNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); clear_has_input_type(); } - const ::std::string& MethodDescriptorProto::input_type() const { +const ::std::string& MethodDescriptorProto::input_type() const { // @@protoc_insertion_point(field_get:google.protobuf.MethodDescriptorProto.input_type) return input_type_.GetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); } - void MethodDescriptorProto::set_input_type(const ::std::string& value) { +void MethodDescriptorProto::set_input_type(const ::std::string& value) { set_has_input_type(); input_type_.SetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), value); // @@protoc_insertion_point(field_set:google.protobuf.MethodDescriptorProto.input_type) } - void MethodDescriptorProto::set_input_type(const char* value) { +void MethodDescriptorProto::set_input_type(const char* value) { set_has_input_type(); input_type_.SetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), ::std::string(value)); // @@protoc_insertion_point(field_set_char:google.protobuf.MethodDescriptorProto.input_type) } - void MethodDescriptorProto::set_input_type(const char* value, size_t size) { +void MethodDescriptorProto::set_input_type(const char* value, size_t size) { set_has_input_type(); input_type_.SetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), ::std::string(reinterpret_cast(value), size)); // @@protoc_insertion_point(field_set_pointer:google.protobuf.MethodDescriptorProto.input_type) } - ::std::string* MethodDescriptorProto::mutable_input_type() { +::std::string* MethodDescriptorProto::mutable_input_type() { set_has_input_type(); // @@protoc_insertion_point(field_mutable:google.protobuf.MethodDescriptorProto.input_type) return input_type_.MutableNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); } - ::std::string* MethodDescriptorProto::release_input_type() { +::std::string* MethodDescriptorProto::release_input_type() { // @@protoc_insertion_point(field_release:google.protobuf.MethodDescriptorProto.input_type) clear_has_input_type(); return input_type_.ReleaseNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); } - void MethodDescriptorProto::set_allocated_input_type(::std::string* input_type) { +void MethodDescriptorProto::set_allocated_input_type(::std::string* input_type) { if (input_type != NULL) { set_has_input_type(); } else { @@ -7905,37 +8010,37 @@ void MethodDescriptorProto::clear_output_type() { output_type_.ClearToEmptyNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); clear_has_output_type(); } - const ::std::string& MethodDescriptorProto::output_type() const { +const ::std::string& MethodDescriptorProto::output_type() const { // @@protoc_insertion_point(field_get:google.protobuf.MethodDescriptorProto.output_type) return output_type_.GetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); } - void MethodDescriptorProto::set_output_type(const ::std::string& value) { +void MethodDescriptorProto::set_output_type(const ::std::string& value) { set_has_output_type(); output_type_.SetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), value); // @@protoc_insertion_point(field_set:google.protobuf.MethodDescriptorProto.output_type) } - void MethodDescriptorProto::set_output_type(const char* value) { +void MethodDescriptorProto::set_output_type(const char* value) { set_has_output_type(); output_type_.SetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), ::std::string(value)); // @@protoc_insertion_point(field_set_char:google.protobuf.MethodDescriptorProto.output_type) } - void MethodDescriptorProto::set_output_type(const char* value, size_t size) { +void MethodDescriptorProto::set_output_type(const char* value, size_t size) { set_has_output_type(); output_type_.SetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), ::std::string(reinterpret_cast(value), size)); // @@protoc_insertion_point(field_set_pointer:google.protobuf.MethodDescriptorProto.output_type) } - ::std::string* MethodDescriptorProto::mutable_output_type() { +::std::string* MethodDescriptorProto::mutable_output_type() { set_has_output_type(); // @@protoc_insertion_point(field_mutable:google.protobuf.MethodDescriptorProto.output_type) return output_type_.MutableNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); } - ::std::string* MethodDescriptorProto::release_output_type() { +::std::string* MethodDescriptorProto::release_output_type() { // @@protoc_insertion_point(field_release:google.protobuf.MethodDescriptorProto.output_type) clear_has_output_type(); return output_type_.ReleaseNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); } - void MethodDescriptorProto::set_allocated_output_type(::std::string* output_type) { +void MethodDescriptorProto::set_allocated_output_type(::std::string* output_type) { if (output_type != NULL) { set_has_output_type(); } else { @@ -7961,7 +8066,8 @@ void MethodDescriptorProto::clear_options() { } const ::google::protobuf::MethodOptions& MethodDescriptorProto::options() const { // @@protoc_insertion_point(field_get:google.protobuf.MethodDescriptorProto.options) - return options_ != NULL ? *options_ : *default_instance_->options_; + return options_ != NULL ? *options_ + : *::google::protobuf::MethodOptions::internal_default_instance(); } ::google::protobuf::MethodOptions* MethodDescriptorProto::mutable_options() { set_has_options(); @@ -8003,11 +8109,11 @@ void MethodDescriptorProto::clear_client_streaming() { client_streaming_ = false; clear_has_client_streaming(); } - bool MethodDescriptorProto::client_streaming() const { +bool MethodDescriptorProto::client_streaming() const { // @@protoc_insertion_point(field_get:google.protobuf.MethodDescriptorProto.client_streaming) return client_streaming_; } - void MethodDescriptorProto::set_client_streaming(bool value) { +void MethodDescriptorProto::set_client_streaming(bool value) { set_has_client_streaming(); client_streaming_ = value; // @@protoc_insertion_point(field_set:google.protobuf.MethodDescriptorProto.client_streaming) @@ -8027,11 +8133,11 @@ void MethodDescriptorProto::clear_server_streaming() { server_streaming_ = false; clear_has_server_streaming(); } - bool MethodDescriptorProto::server_streaming() const { +bool MethodDescriptorProto::server_streaming() const { // @@protoc_insertion_point(field_get:google.protobuf.MethodDescriptorProto.server_streaming) return server_streaming_; } - void MethodDescriptorProto::set_server_streaming(bool value) { +void MethodDescriptorProto::set_server_streaming(bool value) { set_has_server_streaming(); server_streaming_ = value; // @@protoc_insertion_point(field_set:google.protobuf.MethodDescriptorProto.server_streaming) @@ -8046,7 +8152,7 @@ const ::google::protobuf::EnumDescriptor* FileOptions_OptimizeMode_descriptor() return FileOptions_OptimizeMode_descriptor_; } bool FileOptions_OptimizeMode_IsValid(int value) { - switch(value) { + switch (value) { case 1: case 2: case 3: @@ -8068,7 +8174,6 @@ const int FileOptions::OptimizeMode_ARRAYSIZE; const int FileOptions::kJavaPackageFieldNumber; const int FileOptions::kJavaOuterClassnameFieldNumber; const int FileOptions::kJavaMultipleFilesFieldNumber; -const int FileOptions::kJavaGenerateEqualsAndHashFieldNumber; const int FileOptions::kJavaStringCheckUtf8FieldNumber; const int FileOptions::kOptimizeForFieldNumber; const int FileOptions::kGoPackageFieldNumber; @@ -8084,6 +8189,7 @@ const int FileOptions::kUninterpretedOptionFieldNumber; FileOptions::FileOptions() : ::google::protobuf::Message(), _internal_metadata_(NULL) { + if (this != internal_default_instance()) protobuf_InitDefaults_google_2fprotobuf_2fdescriptor_2eproto(); SharedCtor(); // @@protoc_insertion_point(constructor:google.protobuf.FileOptions) } @@ -8095,28 +8201,20 @@ FileOptions::FileOptions(const FileOptions& from) : ::google::protobuf::Message(), _internal_metadata_(NULL) { SharedCtor(); - MergeFrom(from); + UnsafeMergeFrom(from); // @@protoc_insertion_point(copy_constructor:google.protobuf.FileOptions) } void FileOptions::SharedCtor() { - ::google::protobuf::internal::GetEmptyString(); _cached_size_ = 0; java_package_.UnsafeSetDefault(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); java_outer_classname_.UnsafeSetDefault(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); - java_multiple_files_ = false; - java_generate_equals_and_hash_ = false; - java_string_check_utf8_ = false; - optimize_for_ = 1; go_package_.UnsafeSetDefault(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); - cc_generic_services_ = false; - java_generic_services_ = false; - py_generic_services_ = false; - deprecated_ = false; - cc_enable_arenas_ = false; objc_class_prefix_.UnsafeSetDefault(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); csharp_namespace_.UnsafeSetDefault(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); - ::memset(_has_bits_, 0, sizeof(_has_bits_)); + ::memset(&java_multiple_files_, 0, reinterpret_cast(&cc_enable_arenas_) - + reinterpret_cast(&java_multiple_files_) + sizeof(cc_enable_arenas_)); + optimize_for_ = 1; } FileOptions::~FileOptions() { @@ -8130,8 +8228,6 @@ void FileOptions::SharedDtor() { go_package_.DestroyNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); objc_class_prefix_.DestroyNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); csharp_namespace_.DestroyNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); - if (this != default_instance_) { - } } void FileOptions::SetCachedSize(int size) const { @@ -8145,11 +8241,11 @@ const ::google::protobuf::Descriptor* FileOptions::descriptor() { } const FileOptions& FileOptions::default_instance() { - if (default_instance_ == NULL) protobuf_AddDesc_google_2fprotobuf_2fdescriptor_2eproto(); - return *default_instance_; + protobuf_InitDefaults_google_2fprotobuf_2fdescriptor_2eproto(); + return *internal_default_instance(); } -FileOptions* FileOptions::default_instance_ = NULL; +::google::protobuf::internal::ExplicitlyConstructed FileOptions::default_instance_; FileOptions* FileOptions::New(::google::protobuf::Arena* arena) const { FileOptions* n = new FileOptions; @@ -8179,7 +8275,7 @@ void FileOptions::Clear() { } while (0) if (_has_bits_[0 / 32] & 255u) { - ZR_(java_multiple_files_, cc_generic_services_); + ZR_(java_multiple_files_, java_generic_services_); if (has_java_package()) { java_package_.ClearToEmptyNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); } @@ -8191,8 +8287,8 @@ void FileOptions::Clear() { go_package_.ClearToEmptyNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); } } - if (_has_bits_[8 / 32] & 16128u) { - ZR_(java_generic_services_, cc_enable_arenas_); + if (_has_bits_[8 / 32] & 7936u) { + ZR_(py_generic_services_, cc_enable_arenas_); if (has_objc_class_prefix()) { objc_class_prefix_.ClearToEmptyNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); } @@ -8205,7 +8301,7 @@ void FileOptions::Clear() { #undef ZR_ uninterpreted_option_.Clear(); - ::memset(_has_bits_, 0, sizeof(_has_bits_)); + _has_bits_.Clear(); if (_internal_metadata_.have_unknown_fields()) { mutable_unknown_fields()->Clear(); } @@ -8278,10 +8374,10 @@ bool FileOptions::MergePartialFromCodedStream( case 10: { if (tag == 80) { parse_java_multiple_files: + set_has_java_multiple_files(); DO_((::google::protobuf::internal::WireFormatLite::ReadPrimitive< bool, ::google::protobuf::internal::WireFormatLite::TYPE_BOOL>( input, &java_multiple_files_))); - set_has_java_multiple_files(); } else { goto handle_unusual; } @@ -8310,10 +8406,10 @@ bool FileOptions::MergePartialFromCodedStream( case 16: { if (tag == 128) { parse_cc_generic_services: + set_has_cc_generic_services(); DO_((::google::protobuf::internal::WireFormatLite::ReadPrimitive< bool, ::google::protobuf::internal::WireFormatLite::TYPE_BOOL>( input, &cc_generic_services_))); - set_has_cc_generic_services(); } else { goto handle_unusual; } @@ -8325,10 +8421,10 @@ bool FileOptions::MergePartialFromCodedStream( case 17: { if (tag == 136) { parse_java_generic_services: + set_has_java_generic_services(); DO_((::google::protobuf::internal::WireFormatLite::ReadPrimitive< bool, ::google::protobuf::internal::WireFormatLite::TYPE_BOOL>( input, &java_generic_services_))); - set_has_java_generic_services(); } else { goto handle_unusual; } @@ -8340,29 +8436,14 @@ bool FileOptions::MergePartialFromCodedStream( case 18: { if (tag == 144) { parse_py_generic_services: + set_has_py_generic_services(); DO_((::google::protobuf::internal::WireFormatLite::ReadPrimitive< bool, ::google::protobuf::internal::WireFormatLite::TYPE_BOOL>( input, &py_generic_services_))); - set_has_py_generic_services(); } else { goto handle_unusual; } - if (input->ExpectTag(160)) goto parse_java_generate_equals_and_hash; - break; - } - - // optional bool java_generate_equals_and_hash = 20 [default = false]; - case 20: { - if (tag == 160) { - parse_java_generate_equals_and_hash: - DO_((::google::protobuf::internal::WireFormatLite::ReadPrimitive< - bool, ::google::protobuf::internal::WireFormatLite::TYPE_BOOL>( - input, &java_generate_equals_and_hash_))); - set_has_java_generate_equals_and_hash(); - } else { - goto handle_unusual; - } - if (input->ExpectTag(184)) goto parse_deprecated; + if (input->ExpectTag(184)) goto parse_deprecated; break; } @@ -8370,10 +8451,10 @@ bool FileOptions::MergePartialFromCodedStream( case 23: { if (tag == 184) { parse_deprecated: + set_has_deprecated(); DO_((::google::protobuf::internal::WireFormatLite::ReadPrimitive< bool, ::google::protobuf::internal::WireFormatLite::TYPE_BOOL>( input, &deprecated_))); - set_has_deprecated(); } else { goto handle_unusual; } @@ -8385,10 +8466,10 @@ bool FileOptions::MergePartialFromCodedStream( case 27: { if (tag == 216) { parse_java_string_check_utf8: + set_has_java_string_check_utf8(); DO_((::google::protobuf::internal::WireFormatLite::ReadPrimitive< bool, ::google::protobuf::internal::WireFormatLite::TYPE_BOOL>( input, &java_string_check_utf8_))); - set_has_java_string_check_utf8(); } else { goto handle_unusual; } @@ -8400,10 +8481,10 @@ bool FileOptions::MergePartialFromCodedStream( case 31: { if (tag == 248) { parse_cc_enable_arenas: + set_has_cc_enable_arenas(); DO_((::google::protobuf::internal::WireFormatLite::ReadPrimitive< bool, ::google::protobuf::internal::WireFormatLite::TYPE_BOOL>( input, &cc_enable_arenas_))); - set_has_cc_enable_arenas(); } else { goto handle_unusual; } @@ -8470,7 +8551,7 @@ bool FileOptions::MergePartialFromCodedStream( goto success; } if ((8000u <= tag)) { - DO_(_extensions_.ParseField(tag, input, default_instance_, + DO_(_extensions_.ParseField(tag, input, internal_default_instance(), mutable_unknown_fields())); continue; } @@ -8548,11 +8629,6 @@ void FileOptions::SerializeWithCachedSizes( ::google::protobuf::internal::WireFormatLite::WriteBool(18, this->py_generic_services(), output); } - // optional bool java_generate_equals_and_hash = 20 [default = false]; - if (has_java_generate_equals_and_hash()) { - ::google::protobuf::internal::WireFormatLite::WriteBool(20, this->java_generate_equals_and_hash(), output); - } - // optional bool deprecated = 23 [default = false]; if (has_deprecated()) { ::google::protobuf::internal::WireFormatLite::WriteBool(23, this->deprecated(), output); @@ -8668,11 +8744,6 @@ void FileOptions::SerializeWithCachedSizes( target = ::google::protobuf::internal::WireFormatLite::WriteBoolToArray(18, this->py_generic_services(), target); } - // optional bool java_generate_equals_and_hash = 20 [default = false]; - if (has_java_generate_equals_and_hash()) { - target = ::google::protobuf::internal::WireFormatLite::WriteBoolToArray(20, this->java_generate_equals_and_hash(), target); - } - // optional bool deprecated = 23 [default = false]; if (has_deprecated()) { target = ::google::protobuf::internal::WireFormatLite::WriteBoolToArray(23, this->deprecated(), target); @@ -8729,9 +8800,9 @@ void FileOptions::SerializeWithCachedSizes( return target; } -int FileOptions::ByteSize() const { +size_t FileOptions::ByteSizeLong() const { // @@protoc_insertion_point(message_byte_size_start:google.protobuf.FileOptions) - int total_size = 0; + size_t total_size = 0; if (_has_bits_[0 / 32] & 255u) { // optional string java_package = 1; @@ -8753,11 +8824,6 @@ int FileOptions::ByteSize() const { total_size += 1 + 1; } - // optional bool java_generate_equals_and_hash = 20 [default = false]; - if (has_java_generate_equals_and_hash()) { - total_size += 2 + 1; - } - // optional bool java_string_check_utf8 = 27 [default = false]; if (has_java_string_check_utf8()) { total_size += 2 + 1; @@ -8781,13 +8847,13 @@ int FileOptions::ByteSize() const { total_size += 2 + 1; } - } - if (_has_bits_[8 / 32] & 16128u) { // optional bool java_generic_services = 17 [default = false]; if (has_java_generic_services()) { total_size += 2 + 1; } + } + if (_has_bits_[8 / 32] & 7936u) { // optional bool py_generic_services = 18 [default = false]; if (has_py_generic_services()) { total_size += 2 + 1; @@ -8819,11 +8885,14 @@ int FileOptions::ByteSize() const { } // repeated .google.protobuf.UninterpretedOption uninterpreted_option = 999; - total_size += 2 * this->uninterpreted_option_size(); - for (int i = 0; i < this->uninterpreted_option_size(); i++) { - total_size += - ::google::protobuf::internal::WireFormatLite::MessageSizeNoVirtual( - this->uninterpreted_option(i)); + { + unsigned int count = this->uninterpreted_option_size(); + total_size += 2UL * count; + for (unsigned int i = 0; i < count; i++) { + total_size += + ::google::protobuf::internal::WireFormatLite::MessageSizeNoVirtual( + this->uninterpreted_option(i)); + } } total_size += _extensions_.ByteSize(); @@ -8833,18 +8902,17 @@ int FileOptions::ByteSize() const { ::google::protobuf::internal::WireFormat::ComputeUnknownFieldsSize( unknown_fields()); } + int cached_size = ::google::protobuf::internal::ToCachedSize(total_size); GOOGLE_SAFE_CONCURRENT_WRITES_BEGIN(); - _cached_size_ = total_size; + _cached_size_ = cached_size; GOOGLE_SAFE_CONCURRENT_WRITES_END(); return total_size; } void FileOptions::MergeFrom(const ::google::protobuf::Message& from) { // @@protoc_insertion_point(generalized_merge_from_start:google.protobuf.FileOptions) - if (GOOGLE_PREDICT_FALSE(&from == this)) { - ::google::protobuf::internal::MergeFromFail(__FILE__, __LINE__); - } - const FileOptions* source = + if (GOOGLE_PREDICT_FALSE(&from == this)) MergeFromFail(__LINE__); + const FileOptions* source = ::google::protobuf::internal::DynamicCastToGenerated( &from); if (source == NULL) { @@ -8852,15 +8920,21 @@ void FileOptions::MergeFrom(const ::google::protobuf::Message& from) { ::google::protobuf::internal::ReflectionOps::Merge(from, this); } else { // @@protoc_insertion_point(generalized_merge_from_cast_success:google.protobuf.FileOptions) - MergeFrom(*source); + UnsafeMergeFrom(*source); } } void FileOptions::MergeFrom(const FileOptions& from) { // @@protoc_insertion_point(class_specific_merge_from_start:google.protobuf.FileOptions) - if (GOOGLE_PREDICT_FALSE(&from == this)) { - ::google::protobuf::internal::MergeFromFail(__FILE__, __LINE__); + if (GOOGLE_PREDICT_TRUE(&from != this)) { + UnsafeMergeFrom(from); + } else { + MergeFromFail(__LINE__); } +} + +void FileOptions::UnsafeMergeFrom(const FileOptions& from) { + GOOGLE_DCHECK(&from != this); uninterpreted_option_.MergeFrom(from.uninterpreted_option_); if (from._has_bits_[0 / 32] & (0xffu << (0 % 32))) { if (from.has_java_package()) { @@ -8874,9 +8948,6 @@ void FileOptions::MergeFrom(const FileOptions& from) { if (from.has_java_multiple_files()) { set_java_multiple_files(from.java_multiple_files()); } - if (from.has_java_generate_equals_and_hash()) { - set_java_generate_equals_and_hash(from.java_generate_equals_and_hash()); - } if (from.has_java_string_check_utf8()) { set_java_string_check_utf8(from.java_string_check_utf8()); } @@ -8890,11 +8961,11 @@ void FileOptions::MergeFrom(const FileOptions& from) { if (from.has_cc_generic_services()) { set_cc_generic_services(from.cc_generic_services()); } - } - if (from._has_bits_[8 / 32] & (0xffu << (8 % 32))) { if (from.has_java_generic_services()) { set_java_generic_services(from.java_generic_services()); } + } + if (from._has_bits_[8 / 32] & (0xffu << (8 % 32))) { if (from.has_py_generic_services()) { set_py_generic_services(from.py_generic_services()); } @@ -8915,7 +8986,8 @@ void FileOptions::MergeFrom(const FileOptions& from) { } _extensions_.MergeFrom(from._extensions_); if (from._internal_metadata_.have_unknown_fields()) { - mutable_unknown_fields()->MergeFrom(from.unknown_fields()); + ::google::protobuf::UnknownFieldSet::MergeToInternalMetdata( + from.unknown_fields(), &_internal_metadata_); } } @@ -8930,14 +9002,16 @@ void FileOptions::CopyFrom(const FileOptions& from) { // @@protoc_insertion_point(class_specific_copy_from_start:google.protobuf.FileOptions) if (&from == this) return; Clear(); - MergeFrom(from); + UnsafeMergeFrom(from); } bool FileOptions::IsInitialized() const { if (!::google::protobuf::internal::AllAreInitialized(this->uninterpreted_option())) return false; - if (!_extensions_.IsInitialized()) return false; + if (!_extensions_.IsInitialized()) { + return false; + } return true; } @@ -8949,7 +9023,6 @@ void FileOptions::InternalSwap(FileOptions* other) { java_package_.Swap(&other->java_package_); java_outer_classname_.Swap(&other->java_outer_classname_); std::swap(java_multiple_files_, other->java_multiple_files_); - std::swap(java_generate_equals_and_hash_, other->java_generate_equals_and_hash_); std::swap(java_string_check_utf8_, other->java_string_check_utf8_); std::swap(optimize_for_, other->optimize_for_); go_package_.Swap(&other->go_package_); @@ -8992,37 +9065,37 @@ void FileOptions::clear_java_package() { java_package_.ClearToEmptyNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); clear_has_java_package(); } - const ::std::string& FileOptions::java_package() const { +const ::std::string& FileOptions::java_package() const { // @@protoc_insertion_point(field_get:google.protobuf.FileOptions.java_package) return java_package_.GetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); } - void FileOptions::set_java_package(const ::std::string& value) { +void FileOptions::set_java_package(const ::std::string& value) { set_has_java_package(); java_package_.SetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), value); // @@protoc_insertion_point(field_set:google.protobuf.FileOptions.java_package) } - void FileOptions::set_java_package(const char* value) { +void FileOptions::set_java_package(const char* value) { set_has_java_package(); java_package_.SetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), ::std::string(value)); // @@protoc_insertion_point(field_set_char:google.protobuf.FileOptions.java_package) } - void FileOptions::set_java_package(const char* value, size_t size) { +void FileOptions::set_java_package(const char* value, size_t size) { set_has_java_package(); java_package_.SetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), ::std::string(reinterpret_cast(value), size)); // @@protoc_insertion_point(field_set_pointer:google.protobuf.FileOptions.java_package) } - ::std::string* FileOptions::mutable_java_package() { +::std::string* FileOptions::mutable_java_package() { set_has_java_package(); // @@protoc_insertion_point(field_mutable:google.protobuf.FileOptions.java_package) return java_package_.MutableNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); } - ::std::string* FileOptions::release_java_package() { +::std::string* FileOptions::release_java_package() { // @@protoc_insertion_point(field_release:google.protobuf.FileOptions.java_package) clear_has_java_package(); return java_package_.ReleaseNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); } - void FileOptions::set_allocated_java_package(::std::string* java_package) { +void FileOptions::set_allocated_java_package(::std::string* java_package) { if (java_package != NULL) { set_has_java_package(); } else { @@ -9046,37 +9119,37 @@ void FileOptions::clear_java_outer_classname() { java_outer_classname_.ClearToEmptyNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); clear_has_java_outer_classname(); } - const ::std::string& FileOptions::java_outer_classname() const { +const ::std::string& FileOptions::java_outer_classname() const { // @@protoc_insertion_point(field_get:google.protobuf.FileOptions.java_outer_classname) return java_outer_classname_.GetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); } - void FileOptions::set_java_outer_classname(const ::std::string& value) { +void FileOptions::set_java_outer_classname(const ::std::string& value) { set_has_java_outer_classname(); java_outer_classname_.SetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), value); // @@protoc_insertion_point(field_set:google.protobuf.FileOptions.java_outer_classname) } - void FileOptions::set_java_outer_classname(const char* value) { +void FileOptions::set_java_outer_classname(const char* value) { set_has_java_outer_classname(); java_outer_classname_.SetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), ::std::string(value)); // @@protoc_insertion_point(field_set_char:google.protobuf.FileOptions.java_outer_classname) } - void FileOptions::set_java_outer_classname(const char* value, size_t size) { +void FileOptions::set_java_outer_classname(const char* value, size_t size) { set_has_java_outer_classname(); java_outer_classname_.SetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), ::std::string(reinterpret_cast(value), size)); // @@protoc_insertion_point(field_set_pointer:google.protobuf.FileOptions.java_outer_classname) } - ::std::string* FileOptions::mutable_java_outer_classname() { +::std::string* FileOptions::mutable_java_outer_classname() { set_has_java_outer_classname(); // @@protoc_insertion_point(field_mutable:google.protobuf.FileOptions.java_outer_classname) return java_outer_classname_.MutableNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); } - ::std::string* FileOptions::release_java_outer_classname() { +::std::string* FileOptions::release_java_outer_classname() { // @@protoc_insertion_point(field_release:google.protobuf.FileOptions.java_outer_classname) clear_has_java_outer_classname(); return java_outer_classname_.ReleaseNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); } - void FileOptions::set_allocated_java_outer_classname(::std::string* java_outer_classname) { +void FileOptions::set_allocated_java_outer_classname(::std::string* java_outer_classname) { if (java_outer_classname != NULL) { set_has_java_outer_classname(); } else { @@ -9100,59 +9173,35 @@ void FileOptions::clear_java_multiple_files() { java_multiple_files_ = false; clear_has_java_multiple_files(); } - bool FileOptions::java_multiple_files() const { +bool FileOptions::java_multiple_files() const { // @@protoc_insertion_point(field_get:google.protobuf.FileOptions.java_multiple_files) return java_multiple_files_; } - void FileOptions::set_java_multiple_files(bool value) { +void FileOptions::set_java_multiple_files(bool value) { set_has_java_multiple_files(); java_multiple_files_ = value; // @@protoc_insertion_point(field_set:google.protobuf.FileOptions.java_multiple_files) } -// optional bool java_generate_equals_and_hash = 20 [default = false]; -bool FileOptions::has_java_generate_equals_and_hash() const { - return (_has_bits_[0] & 0x00000008u) != 0; -} -void FileOptions::set_has_java_generate_equals_and_hash() { - _has_bits_[0] |= 0x00000008u; -} -void FileOptions::clear_has_java_generate_equals_and_hash() { - _has_bits_[0] &= ~0x00000008u; -} -void FileOptions::clear_java_generate_equals_and_hash() { - java_generate_equals_and_hash_ = false; - clear_has_java_generate_equals_and_hash(); -} - bool FileOptions::java_generate_equals_and_hash() const { - // @@protoc_insertion_point(field_get:google.protobuf.FileOptions.java_generate_equals_and_hash) - return java_generate_equals_and_hash_; -} - void FileOptions::set_java_generate_equals_and_hash(bool value) { - set_has_java_generate_equals_and_hash(); - java_generate_equals_and_hash_ = value; - // @@protoc_insertion_point(field_set:google.protobuf.FileOptions.java_generate_equals_and_hash) -} - // optional bool java_string_check_utf8 = 27 [default = false]; bool FileOptions::has_java_string_check_utf8() const { - return (_has_bits_[0] & 0x00000010u) != 0; + return (_has_bits_[0] & 0x00000008u) != 0; } void FileOptions::set_has_java_string_check_utf8() { - _has_bits_[0] |= 0x00000010u; + _has_bits_[0] |= 0x00000008u; } void FileOptions::clear_has_java_string_check_utf8() { - _has_bits_[0] &= ~0x00000010u; + _has_bits_[0] &= ~0x00000008u; } void FileOptions::clear_java_string_check_utf8() { java_string_check_utf8_ = false; clear_has_java_string_check_utf8(); } - bool FileOptions::java_string_check_utf8() const { +bool FileOptions::java_string_check_utf8() const { // @@protoc_insertion_point(field_get:google.protobuf.FileOptions.java_string_check_utf8) return java_string_check_utf8_; } - void FileOptions::set_java_string_check_utf8(bool value) { +void FileOptions::set_java_string_check_utf8(bool value) { set_has_java_string_check_utf8(); java_string_check_utf8_ = value; // @@protoc_insertion_point(field_set:google.protobuf.FileOptions.java_string_check_utf8) @@ -9160,23 +9209,23 @@ void FileOptions::clear_java_string_check_utf8() { // optional .google.protobuf.FileOptions.OptimizeMode optimize_for = 9 [default = SPEED]; bool FileOptions::has_optimize_for() const { - return (_has_bits_[0] & 0x00000020u) != 0; + return (_has_bits_[0] & 0x00000010u) != 0; } void FileOptions::set_has_optimize_for() { - _has_bits_[0] |= 0x00000020u; + _has_bits_[0] |= 0x00000010u; } void FileOptions::clear_has_optimize_for() { - _has_bits_[0] &= ~0x00000020u; + _has_bits_[0] &= ~0x00000010u; } void FileOptions::clear_optimize_for() { optimize_for_ = 1; clear_has_optimize_for(); } - ::google::protobuf::FileOptions_OptimizeMode FileOptions::optimize_for() const { +::google::protobuf::FileOptions_OptimizeMode FileOptions::optimize_for() const { // @@protoc_insertion_point(field_get:google.protobuf.FileOptions.optimize_for) return static_cast< ::google::protobuf::FileOptions_OptimizeMode >(optimize_for_); } - void FileOptions::set_optimize_for(::google::protobuf::FileOptions_OptimizeMode value) { +void FileOptions::set_optimize_for(::google::protobuf::FileOptions_OptimizeMode value) { assert(::google::protobuf::FileOptions_OptimizeMode_IsValid(value)); set_has_optimize_for(); optimize_for_ = value; @@ -9185,49 +9234,49 @@ void FileOptions::clear_optimize_for() { // optional string go_package = 11; bool FileOptions::has_go_package() const { - return (_has_bits_[0] & 0x00000040u) != 0; + return (_has_bits_[0] & 0x00000020u) != 0; } void FileOptions::set_has_go_package() { - _has_bits_[0] |= 0x00000040u; + _has_bits_[0] |= 0x00000020u; } void FileOptions::clear_has_go_package() { - _has_bits_[0] &= ~0x00000040u; + _has_bits_[0] &= ~0x00000020u; } void FileOptions::clear_go_package() { go_package_.ClearToEmptyNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); clear_has_go_package(); } - const ::std::string& FileOptions::go_package() const { +const ::std::string& FileOptions::go_package() const { // @@protoc_insertion_point(field_get:google.protobuf.FileOptions.go_package) return go_package_.GetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); } - void FileOptions::set_go_package(const ::std::string& value) { +void FileOptions::set_go_package(const ::std::string& value) { set_has_go_package(); go_package_.SetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), value); // @@protoc_insertion_point(field_set:google.protobuf.FileOptions.go_package) } - void FileOptions::set_go_package(const char* value) { +void FileOptions::set_go_package(const char* value) { set_has_go_package(); go_package_.SetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), ::std::string(value)); // @@protoc_insertion_point(field_set_char:google.protobuf.FileOptions.go_package) } - void FileOptions::set_go_package(const char* value, size_t size) { +void FileOptions::set_go_package(const char* value, size_t size) { set_has_go_package(); go_package_.SetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), ::std::string(reinterpret_cast(value), size)); // @@protoc_insertion_point(field_set_pointer:google.protobuf.FileOptions.go_package) } - ::std::string* FileOptions::mutable_go_package() { +::std::string* FileOptions::mutable_go_package() { set_has_go_package(); // @@protoc_insertion_point(field_mutable:google.protobuf.FileOptions.go_package) return go_package_.MutableNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); } - ::std::string* FileOptions::release_go_package() { +::std::string* FileOptions::release_go_package() { // @@protoc_insertion_point(field_release:google.protobuf.FileOptions.go_package) clear_has_go_package(); return go_package_.ReleaseNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); } - void FileOptions::set_allocated_go_package(::std::string* go_package) { +void FileOptions::set_allocated_go_package(::std::string* go_package) { if (go_package != NULL) { set_has_go_package(); } else { @@ -9239,23 +9288,23 @@ void FileOptions::clear_go_package() { // optional bool cc_generic_services = 16 [default = false]; bool FileOptions::has_cc_generic_services() const { - return (_has_bits_[0] & 0x00000080u) != 0; + return (_has_bits_[0] & 0x00000040u) != 0; } void FileOptions::set_has_cc_generic_services() { - _has_bits_[0] |= 0x00000080u; + _has_bits_[0] |= 0x00000040u; } void FileOptions::clear_has_cc_generic_services() { - _has_bits_[0] &= ~0x00000080u; + _has_bits_[0] &= ~0x00000040u; } void FileOptions::clear_cc_generic_services() { cc_generic_services_ = false; clear_has_cc_generic_services(); } - bool FileOptions::cc_generic_services() const { +bool FileOptions::cc_generic_services() const { // @@protoc_insertion_point(field_get:google.protobuf.FileOptions.cc_generic_services) return cc_generic_services_; } - void FileOptions::set_cc_generic_services(bool value) { +void FileOptions::set_cc_generic_services(bool value) { set_has_cc_generic_services(); cc_generic_services_ = value; // @@protoc_insertion_point(field_set:google.protobuf.FileOptions.cc_generic_services) @@ -9263,23 +9312,23 @@ void FileOptions::clear_cc_generic_services() { // optional bool java_generic_services = 17 [default = false]; bool FileOptions::has_java_generic_services() const { - return (_has_bits_[0] & 0x00000100u) != 0; + return (_has_bits_[0] & 0x00000080u) != 0; } void FileOptions::set_has_java_generic_services() { - _has_bits_[0] |= 0x00000100u; + _has_bits_[0] |= 0x00000080u; } void FileOptions::clear_has_java_generic_services() { - _has_bits_[0] &= ~0x00000100u; + _has_bits_[0] &= ~0x00000080u; } void FileOptions::clear_java_generic_services() { java_generic_services_ = false; clear_has_java_generic_services(); } - bool FileOptions::java_generic_services() const { +bool FileOptions::java_generic_services() const { // @@protoc_insertion_point(field_get:google.protobuf.FileOptions.java_generic_services) return java_generic_services_; } - void FileOptions::set_java_generic_services(bool value) { +void FileOptions::set_java_generic_services(bool value) { set_has_java_generic_services(); java_generic_services_ = value; // @@protoc_insertion_point(field_set:google.protobuf.FileOptions.java_generic_services) @@ -9287,23 +9336,23 @@ void FileOptions::clear_java_generic_services() { // optional bool py_generic_services = 18 [default = false]; bool FileOptions::has_py_generic_services() const { - return (_has_bits_[0] & 0x00000200u) != 0; + return (_has_bits_[0] & 0x00000100u) != 0; } void FileOptions::set_has_py_generic_services() { - _has_bits_[0] |= 0x00000200u; + _has_bits_[0] |= 0x00000100u; } void FileOptions::clear_has_py_generic_services() { - _has_bits_[0] &= ~0x00000200u; + _has_bits_[0] &= ~0x00000100u; } void FileOptions::clear_py_generic_services() { py_generic_services_ = false; clear_has_py_generic_services(); } - bool FileOptions::py_generic_services() const { +bool FileOptions::py_generic_services() const { // @@protoc_insertion_point(field_get:google.protobuf.FileOptions.py_generic_services) return py_generic_services_; } - void FileOptions::set_py_generic_services(bool value) { +void FileOptions::set_py_generic_services(bool value) { set_has_py_generic_services(); py_generic_services_ = value; // @@protoc_insertion_point(field_set:google.protobuf.FileOptions.py_generic_services) @@ -9311,23 +9360,23 @@ void FileOptions::clear_py_generic_services() { // optional bool deprecated = 23 [default = false]; bool FileOptions::has_deprecated() const { - return (_has_bits_[0] & 0x00000400u) != 0; + return (_has_bits_[0] & 0x00000200u) != 0; } void FileOptions::set_has_deprecated() { - _has_bits_[0] |= 0x00000400u; + _has_bits_[0] |= 0x00000200u; } void FileOptions::clear_has_deprecated() { - _has_bits_[0] &= ~0x00000400u; + _has_bits_[0] &= ~0x00000200u; } void FileOptions::clear_deprecated() { deprecated_ = false; clear_has_deprecated(); } - bool FileOptions::deprecated() const { +bool FileOptions::deprecated() const { // @@protoc_insertion_point(field_get:google.protobuf.FileOptions.deprecated) return deprecated_; } - void FileOptions::set_deprecated(bool value) { +void FileOptions::set_deprecated(bool value) { set_has_deprecated(); deprecated_ = value; // @@protoc_insertion_point(field_set:google.protobuf.FileOptions.deprecated) @@ -9335,23 +9384,23 @@ void FileOptions::clear_deprecated() { // optional bool cc_enable_arenas = 31 [default = false]; bool FileOptions::has_cc_enable_arenas() const { - return (_has_bits_[0] & 0x00000800u) != 0; + return (_has_bits_[0] & 0x00000400u) != 0; } void FileOptions::set_has_cc_enable_arenas() { - _has_bits_[0] |= 0x00000800u; + _has_bits_[0] |= 0x00000400u; } void FileOptions::clear_has_cc_enable_arenas() { - _has_bits_[0] &= ~0x00000800u; + _has_bits_[0] &= ~0x00000400u; } void FileOptions::clear_cc_enable_arenas() { cc_enable_arenas_ = false; clear_has_cc_enable_arenas(); } - bool FileOptions::cc_enable_arenas() const { +bool FileOptions::cc_enable_arenas() const { // @@protoc_insertion_point(field_get:google.protobuf.FileOptions.cc_enable_arenas) return cc_enable_arenas_; } - void FileOptions::set_cc_enable_arenas(bool value) { +void FileOptions::set_cc_enable_arenas(bool value) { set_has_cc_enable_arenas(); cc_enable_arenas_ = value; // @@protoc_insertion_point(field_set:google.protobuf.FileOptions.cc_enable_arenas) @@ -9359,49 +9408,49 @@ void FileOptions::clear_cc_enable_arenas() { // optional string objc_class_prefix = 36; bool FileOptions::has_objc_class_prefix() const { - return (_has_bits_[0] & 0x00001000u) != 0; + return (_has_bits_[0] & 0x00000800u) != 0; } void FileOptions::set_has_objc_class_prefix() { - _has_bits_[0] |= 0x00001000u; + _has_bits_[0] |= 0x00000800u; } void FileOptions::clear_has_objc_class_prefix() { - _has_bits_[0] &= ~0x00001000u; + _has_bits_[0] &= ~0x00000800u; } void FileOptions::clear_objc_class_prefix() { objc_class_prefix_.ClearToEmptyNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); clear_has_objc_class_prefix(); } - const ::std::string& FileOptions::objc_class_prefix() const { +const ::std::string& FileOptions::objc_class_prefix() const { // @@protoc_insertion_point(field_get:google.protobuf.FileOptions.objc_class_prefix) return objc_class_prefix_.GetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); } - void FileOptions::set_objc_class_prefix(const ::std::string& value) { +void FileOptions::set_objc_class_prefix(const ::std::string& value) { set_has_objc_class_prefix(); objc_class_prefix_.SetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), value); // @@protoc_insertion_point(field_set:google.protobuf.FileOptions.objc_class_prefix) } - void FileOptions::set_objc_class_prefix(const char* value) { +void FileOptions::set_objc_class_prefix(const char* value) { set_has_objc_class_prefix(); objc_class_prefix_.SetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), ::std::string(value)); // @@protoc_insertion_point(field_set_char:google.protobuf.FileOptions.objc_class_prefix) } - void FileOptions::set_objc_class_prefix(const char* value, size_t size) { +void FileOptions::set_objc_class_prefix(const char* value, size_t size) { set_has_objc_class_prefix(); objc_class_prefix_.SetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), ::std::string(reinterpret_cast(value), size)); // @@protoc_insertion_point(field_set_pointer:google.protobuf.FileOptions.objc_class_prefix) } - ::std::string* FileOptions::mutable_objc_class_prefix() { +::std::string* FileOptions::mutable_objc_class_prefix() { set_has_objc_class_prefix(); // @@protoc_insertion_point(field_mutable:google.protobuf.FileOptions.objc_class_prefix) return objc_class_prefix_.MutableNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); } - ::std::string* FileOptions::release_objc_class_prefix() { +::std::string* FileOptions::release_objc_class_prefix() { // @@protoc_insertion_point(field_release:google.protobuf.FileOptions.objc_class_prefix) clear_has_objc_class_prefix(); return objc_class_prefix_.ReleaseNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); } - void FileOptions::set_allocated_objc_class_prefix(::std::string* objc_class_prefix) { +void FileOptions::set_allocated_objc_class_prefix(::std::string* objc_class_prefix) { if (objc_class_prefix != NULL) { set_has_objc_class_prefix(); } else { @@ -9413,49 +9462,49 @@ void FileOptions::clear_objc_class_prefix() { // optional string csharp_namespace = 37; bool FileOptions::has_csharp_namespace() const { - return (_has_bits_[0] & 0x00002000u) != 0; + return (_has_bits_[0] & 0x00001000u) != 0; } void FileOptions::set_has_csharp_namespace() { - _has_bits_[0] |= 0x00002000u; + _has_bits_[0] |= 0x00001000u; } void FileOptions::clear_has_csharp_namespace() { - _has_bits_[0] &= ~0x00002000u; + _has_bits_[0] &= ~0x00001000u; } void FileOptions::clear_csharp_namespace() { csharp_namespace_.ClearToEmptyNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); clear_has_csharp_namespace(); } - const ::std::string& FileOptions::csharp_namespace() const { +const ::std::string& FileOptions::csharp_namespace() const { // @@protoc_insertion_point(field_get:google.protobuf.FileOptions.csharp_namespace) return csharp_namespace_.GetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); } - void FileOptions::set_csharp_namespace(const ::std::string& value) { +void FileOptions::set_csharp_namespace(const ::std::string& value) { set_has_csharp_namespace(); csharp_namespace_.SetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), value); // @@protoc_insertion_point(field_set:google.protobuf.FileOptions.csharp_namespace) } - void FileOptions::set_csharp_namespace(const char* value) { +void FileOptions::set_csharp_namespace(const char* value) { set_has_csharp_namespace(); csharp_namespace_.SetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), ::std::string(value)); // @@protoc_insertion_point(field_set_char:google.protobuf.FileOptions.csharp_namespace) } - void FileOptions::set_csharp_namespace(const char* value, size_t size) { +void FileOptions::set_csharp_namespace(const char* value, size_t size) { set_has_csharp_namespace(); csharp_namespace_.SetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), ::std::string(reinterpret_cast(value), size)); // @@protoc_insertion_point(field_set_pointer:google.protobuf.FileOptions.csharp_namespace) } - ::std::string* FileOptions::mutable_csharp_namespace() { +::std::string* FileOptions::mutable_csharp_namespace() { set_has_csharp_namespace(); // @@protoc_insertion_point(field_mutable:google.protobuf.FileOptions.csharp_namespace) return csharp_namespace_.MutableNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); } - ::std::string* FileOptions::release_csharp_namespace() { +::std::string* FileOptions::release_csharp_namespace() { // @@protoc_insertion_point(field_release:google.protobuf.FileOptions.csharp_namespace) clear_has_csharp_namespace(); return csharp_namespace_.ReleaseNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); } - void FileOptions::set_allocated_csharp_namespace(::std::string* csharp_namespace) { +void FileOptions::set_allocated_csharp_namespace(::std::string* csharp_namespace) { if (csharp_namespace != NULL) { set_has_csharp_namespace(); } else { @@ -9509,6 +9558,7 @@ const int MessageOptions::kUninterpretedOptionFieldNumber; MessageOptions::MessageOptions() : ::google::protobuf::Message(), _internal_metadata_(NULL) { + if (this != internal_default_instance()) protobuf_InitDefaults_google_2fprotobuf_2fdescriptor_2eproto(); SharedCtor(); // @@protoc_insertion_point(constructor:google.protobuf.MessageOptions) } @@ -9520,17 +9570,14 @@ MessageOptions::MessageOptions(const MessageOptions& from) : ::google::protobuf::Message(), _internal_metadata_(NULL) { SharedCtor(); - MergeFrom(from); + UnsafeMergeFrom(from); // @@protoc_insertion_point(copy_constructor:google.protobuf.MessageOptions) } void MessageOptions::SharedCtor() { _cached_size_ = 0; - message_set_wire_format_ = false; - no_standard_descriptor_accessor_ = false; - deprecated_ = false; - map_entry_ = false; - ::memset(_has_bits_, 0, sizeof(_has_bits_)); + ::memset(&message_set_wire_format_, 0, reinterpret_cast(&map_entry_) - + reinterpret_cast(&message_set_wire_format_) + sizeof(map_entry_)); } MessageOptions::~MessageOptions() { @@ -9539,8 +9586,6 @@ MessageOptions::~MessageOptions() { } void MessageOptions::SharedDtor() { - if (this != default_instance_) { - } } void MessageOptions::SetCachedSize(int size) const { @@ -9554,11 +9599,11 @@ const ::google::protobuf::Descriptor* MessageOptions::descriptor() { } const MessageOptions& MessageOptions::default_instance() { - if (default_instance_ == NULL) protobuf_AddDesc_google_2fprotobuf_2fdescriptor_2eproto(); - return *default_instance_; + protobuf_InitDefaults_google_2fprotobuf_2fdescriptor_2eproto(); + return *internal_default_instance(); } -MessageOptions* MessageOptions::default_instance_ = NULL; +::google::protobuf::internal::ExplicitlyConstructed MessageOptions::default_instance_; MessageOptions* MessageOptions::New(::google::protobuf::Arena* arena) const { MessageOptions* n = new MessageOptions; @@ -9593,7 +9638,7 @@ void MessageOptions::Clear() { #undef ZR_ uninterpreted_option_.Clear(); - ::memset(_has_bits_, 0, sizeof(_has_bits_)); + _has_bits_.Clear(); if (_internal_metadata_.have_unknown_fields()) { mutable_unknown_fields()->Clear(); } @@ -9612,10 +9657,10 @@ bool MessageOptions::MergePartialFromCodedStream( // optional bool message_set_wire_format = 1 [default = false]; case 1: { if (tag == 8) { + set_has_message_set_wire_format(); DO_((::google::protobuf::internal::WireFormatLite::ReadPrimitive< bool, ::google::protobuf::internal::WireFormatLite::TYPE_BOOL>( input, &message_set_wire_format_))); - set_has_message_set_wire_format(); } else { goto handle_unusual; } @@ -9627,10 +9672,10 @@ bool MessageOptions::MergePartialFromCodedStream( case 2: { if (tag == 16) { parse_no_standard_descriptor_accessor: + set_has_no_standard_descriptor_accessor(); DO_((::google::protobuf::internal::WireFormatLite::ReadPrimitive< bool, ::google::protobuf::internal::WireFormatLite::TYPE_BOOL>( input, &no_standard_descriptor_accessor_))); - set_has_no_standard_descriptor_accessor(); } else { goto handle_unusual; } @@ -9642,10 +9687,10 @@ bool MessageOptions::MergePartialFromCodedStream( case 3: { if (tag == 24) { parse_deprecated: + set_has_deprecated(); DO_((::google::protobuf::internal::WireFormatLite::ReadPrimitive< bool, ::google::protobuf::internal::WireFormatLite::TYPE_BOOL>( input, &deprecated_))); - set_has_deprecated(); } else { goto handle_unusual; } @@ -9657,10 +9702,10 @@ bool MessageOptions::MergePartialFromCodedStream( case 7: { if (tag == 56) { parse_map_entry: + set_has_map_entry(); DO_((::google::protobuf::internal::WireFormatLite::ReadPrimitive< bool, ::google::protobuf::internal::WireFormatLite::TYPE_BOOL>( input, &map_entry_))); - set_has_map_entry(); } else { goto handle_unusual; } @@ -9693,7 +9738,7 @@ bool MessageOptions::MergePartialFromCodedStream( goto success; } if ((8000u <= tag)) { - DO_(_extensions_.ParseField(tag, input, default_instance_, + DO_(_extensions_.ParseField(tag, input, internal_default_instance(), mutable_unknown_fields())); continue; } @@ -9795,9 +9840,9 @@ void MessageOptions::SerializeWithCachedSizes( return target; } -int MessageOptions::ByteSize() const { +size_t MessageOptions::ByteSizeLong() const { // @@protoc_insertion_point(message_byte_size_start:google.protobuf.MessageOptions) - int total_size = 0; + size_t total_size = 0; if (_has_bits_[0 / 32] & 15u) { // optional bool message_set_wire_format = 1 [default = false]; @@ -9822,11 +9867,14 @@ int MessageOptions::ByteSize() const { } // repeated .google.protobuf.UninterpretedOption uninterpreted_option = 999; - total_size += 2 * this->uninterpreted_option_size(); - for (int i = 0; i < this->uninterpreted_option_size(); i++) { - total_size += - ::google::protobuf::internal::WireFormatLite::MessageSizeNoVirtual( - this->uninterpreted_option(i)); + { + unsigned int count = this->uninterpreted_option_size(); + total_size += 2UL * count; + for (unsigned int i = 0; i < count; i++) { + total_size += + ::google::protobuf::internal::WireFormatLite::MessageSizeNoVirtual( + this->uninterpreted_option(i)); + } } total_size += _extensions_.ByteSize(); @@ -9836,18 +9884,17 @@ int MessageOptions::ByteSize() const { ::google::protobuf::internal::WireFormat::ComputeUnknownFieldsSize( unknown_fields()); } + int cached_size = ::google::protobuf::internal::ToCachedSize(total_size); GOOGLE_SAFE_CONCURRENT_WRITES_BEGIN(); - _cached_size_ = total_size; + _cached_size_ = cached_size; GOOGLE_SAFE_CONCURRENT_WRITES_END(); return total_size; } void MessageOptions::MergeFrom(const ::google::protobuf::Message& from) { // @@protoc_insertion_point(generalized_merge_from_start:google.protobuf.MessageOptions) - if (GOOGLE_PREDICT_FALSE(&from == this)) { - ::google::protobuf::internal::MergeFromFail(__FILE__, __LINE__); - } - const MessageOptions* source = + if (GOOGLE_PREDICT_FALSE(&from == this)) MergeFromFail(__LINE__); + const MessageOptions* source = ::google::protobuf::internal::DynamicCastToGenerated( &from); if (source == NULL) { @@ -9855,15 +9902,21 @@ void MessageOptions::MergeFrom(const ::google::protobuf::Message& from) { ::google::protobuf::internal::ReflectionOps::Merge(from, this); } else { // @@protoc_insertion_point(generalized_merge_from_cast_success:google.protobuf.MessageOptions) - MergeFrom(*source); + UnsafeMergeFrom(*source); } } void MessageOptions::MergeFrom(const MessageOptions& from) { // @@protoc_insertion_point(class_specific_merge_from_start:google.protobuf.MessageOptions) - if (GOOGLE_PREDICT_FALSE(&from == this)) { - ::google::protobuf::internal::MergeFromFail(__FILE__, __LINE__); + if (GOOGLE_PREDICT_TRUE(&from != this)) { + UnsafeMergeFrom(from); + } else { + MergeFromFail(__LINE__); } +} + +void MessageOptions::UnsafeMergeFrom(const MessageOptions& from) { + GOOGLE_DCHECK(&from != this); uninterpreted_option_.MergeFrom(from.uninterpreted_option_); if (from._has_bits_[0 / 32] & (0xffu << (0 % 32))) { if (from.has_message_set_wire_format()) { @@ -9881,7 +9934,8 @@ void MessageOptions::MergeFrom(const MessageOptions& from) { } _extensions_.MergeFrom(from._extensions_); if (from._internal_metadata_.have_unknown_fields()) { - mutable_unknown_fields()->MergeFrom(from.unknown_fields()); + ::google::protobuf::UnknownFieldSet::MergeToInternalMetdata( + from.unknown_fields(), &_internal_metadata_); } } @@ -9896,14 +9950,16 @@ void MessageOptions::CopyFrom(const MessageOptions& from) { // @@protoc_insertion_point(class_specific_copy_from_start:google.protobuf.MessageOptions) if (&from == this) return; Clear(); - MergeFrom(from); + UnsafeMergeFrom(from); } bool MessageOptions::IsInitialized() const { if (!::google::protobuf::internal::AllAreInitialized(this->uninterpreted_option())) return false; - if (!_extensions_.IsInitialized()) return false; + if (!_extensions_.IsInitialized()) { + return false; + } return true; } @@ -9948,11 +10004,11 @@ void MessageOptions::clear_message_set_wire_format() { message_set_wire_format_ = false; clear_has_message_set_wire_format(); } - bool MessageOptions::message_set_wire_format() const { +bool MessageOptions::message_set_wire_format() const { // @@protoc_insertion_point(field_get:google.protobuf.MessageOptions.message_set_wire_format) return message_set_wire_format_; } - void MessageOptions::set_message_set_wire_format(bool value) { +void MessageOptions::set_message_set_wire_format(bool value) { set_has_message_set_wire_format(); message_set_wire_format_ = value; // @@protoc_insertion_point(field_set:google.protobuf.MessageOptions.message_set_wire_format) @@ -9972,11 +10028,11 @@ void MessageOptions::clear_no_standard_descriptor_accessor() { no_standard_descriptor_accessor_ = false; clear_has_no_standard_descriptor_accessor(); } - bool MessageOptions::no_standard_descriptor_accessor() const { +bool MessageOptions::no_standard_descriptor_accessor() const { // @@protoc_insertion_point(field_get:google.protobuf.MessageOptions.no_standard_descriptor_accessor) return no_standard_descriptor_accessor_; } - void MessageOptions::set_no_standard_descriptor_accessor(bool value) { +void MessageOptions::set_no_standard_descriptor_accessor(bool value) { set_has_no_standard_descriptor_accessor(); no_standard_descriptor_accessor_ = value; // @@protoc_insertion_point(field_set:google.protobuf.MessageOptions.no_standard_descriptor_accessor) @@ -9996,11 +10052,11 @@ void MessageOptions::clear_deprecated() { deprecated_ = false; clear_has_deprecated(); } - bool MessageOptions::deprecated() const { +bool MessageOptions::deprecated() const { // @@protoc_insertion_point(field_get:google.protobuf.MessageOptions.deprecated) return deprecated_; } - void MessageOptions::set_deprecated(bool value) { +void MessageOptions::set_deprecated(bool value) { set_has_deprecated(); deprecated_ = value; // @@protoc_insertion_point(field_set:google.protobuf.MessageOptions.deprecated) @@ -10020,11 +10076,11 @@ void MessageOptions::clear_map_entry() { map_entry_ = false; clear_has_map_entry(); } - bool MessageOptions::map_entry() const { +bool MessageOptions::map_entry() const { // @@protoc_insertion_point(field_get:google.protobuf.MessageOptions.map_entry) return map_entry_; } - void MessageOptions::set_map_entry(bool value) { +void MessageOptions::set_map_entry(bool value) { set_has_map_entry(); map_entry_ = value; // @@protoc_insertion_point(field_set:google.protobuf.MessageOptions.map_entry) @@ -10069,7 +10125,7 @@ const ::google::protobuf::EnumDescriptor* FieldOptions_CType_descriptor() { return FieldOptions_CType_descriptor_; } bool FieldOptions_CType_IsValid(int value) { - switch(value) { + switch (value) { case 0: case 1: case 2: @@ -10092,7 +10148,7 @@ const ::google::protobuf::EnumDescriptor* FieldOptions_JSType_descriptor() { return FieldOptions_JSType_descriptor_; } bool FieldOptions_JSType_IsValid(int value) { - switch(value) { + switch (value) { case 0: case 1: case 2: @@ -10122,6 +10178,7 @@ const int FieldOptions::kUninterpretedOptionFieldNumber; FieldOptions::FieldOptions() : ::google::protobuf::Message(), _internal_metadata_(NULL) { + if (this != internal_default_instance()) protobuf_InitDefaults_google_2fprotobuf_2fdescriptor_2eproto(); SharedCtor(); // @@protoc_insertion_point(constructor:google.protobuf.FieldOptions) } @@ -10133,19 +10190,14 @@ FieldOptions::FieldOptions(const FieldOptions& from) : ::google::protobuf::Message(), _internal_metadata_(NULL) { SharedCtor(); - MergeFrom(from); + UnsafeMergeFrom(from); // @@protoc_insertion_point(copy_constructor:google.protobuf.FieldOptions) } void FieldOptions::SharedCtor() { _cached_size_ = 0; - ctype_ = 0; - packed_ = false; - jstype_ = 0; - lazy_ = false; - deprecated_ = false; - weak_ = false; - ::memset(_has_bits_, 0, sizeof(_has_bits_)); + ::memset(&ctype_, 0, reinterpret_cast(&weak_) - + reinterpret_cast(&ctype_) + sizeof(weak_)); } FieldOptions::~FieldOptions() { @@ -10154,8 +10206,6 @@ FieldOptions::~FieldOptions() { } void FieldOptions::SharedDtor() { - if (this != default_instance_) { - } } void FieldOptions::SetCachedSize(int size) const { @@ -10169,11 +10219,11 @@ const ::google::protobuf::Descriptor* FieldOptions::descriptor() { } const FieldOptions& FieldOptions::default_instance() { - if (default_instance_ == NULL) protobuf_AddDesc_google_2fprotobuf_2fdescriptor_2eproto(); - return *default_instance_; + protobuf_InitDefaults_google_2fprotobuf_2fdescriptor_2eproto(); + return *internal_default_instance(); } -FieldOptions* FieldOptions::default_instance_ = NULL; +::google::protobuf::internal::ExplicitlyConstructed FieldOptions::default_instance_; FieldOptions* FieldOptions::New(::google::protobuf::Arena* arena) const { FieldOptions* n = new FieldOptions; @@ -10202,16 +10252,13 @@ void FieldOptions::Clear() { ZR_HELPER_(last) - ZR_HELPER_(first) + sizeof(last));\ } while (0) - if (_has_bits_[0 / 32] & 63u) { - ZR_(ctype_, jstype_); - ZR_(packed_, weak_); - } + ZR_(ctype_, weak_); #undef ZR_HELPER_ #undef ZR_ uninterpreted_option_.Clear(); - ::memset(_has_bits_, 0, sizeof(_has_bits_)); + _has_bits_.Clear(); if (_internal_metadata_.have_unknown_fields()) { mutable_unknown_fields()->Clear(); } @@ -10250,10 +10297,10 @@ bool FieldOptions::MergePartialFromCodedStream( case 2: { if (tag == 16) { parse_packed: + set_has_packed(); DO_((::google::protobuf::internal::WireFormatLite::ReadPrimitive< bool, ::google::protobuf::internal::WireFormatLite::TYPE_BOOL>( input, &packed_))); - set_has_packed(); } else { goto handle_unusual; } @@ -10265,10 +10312,10 @@ bool FieldOptions::MergePartialFromCodedStream( case 3: { if (tag == 24) { parse_deprecated: + set_has_deprecated(); DO_((::google::protobuf::internal::WireFormatLite::ReadPrimitive< bool, ::google::protobuf::internal::WireFormatLite::TYPE_BOOL>( input, &deprecated_))); - set_has_deprecated(); } else { goto handle_unusual; } @@ -10280,10 +10327,10 @@ bool FieldOptions::MergePartialFromCodedStream( case 5: { if (tag == 40) { parse_lazy: + set_has_lazy(); DO_((::google::protobuf::internal::WireFormatLite::ReadPrimitive< bool, ::google::protobuf::internal::WireFormatLite::TYPE_BOOL>( input, &lazy_))); - set_has_lazy(); } else { goto handle_unusual; } @@ -10315,10 +10362,10 @@ bool FieldOptions::MergePartialFromCodedStream( case 10: { if (tag == 80) { parse_weak: + set_has_weak(); DO_((::google::protobuf::internal::WireFormatLite::ReadPrimitive< bool, ::google::protobuf::internal::WireFormatLite::TYPE_BOOL>( input, &weak_))); - set_has_weak(); } else { goto handle_unusual; } @@ -10351,7 +10398,7 @@ bool FieldOptions::MergePartialFromCodedStream( goto success; } if ((8000u <= tag)) { - DO_(_extensions_.ParseField(tag, input, default_instance_, + DO_(_extensions_.ParseField(tag, input, internal_default_instance(), mutable_unknown_fields())); continue; } @@ -10477,9 +10524,9 @@ void FieldOptions::SerializeWithCachedSizes( return target; } -int FieldOptions::ByteSize() const { +size_t FieldOptions::ByteSizeLong() const { // @@protoc_insertion_point(message_byte_size_start:google.protobuf.FieldOptions) - int total_size = 0; + size_t total_size = 0; if (_has_bits_[0 / 32] & 63u) { // optional .google.protobuf.FieldOptions.CType ctype = 1 [default = STRING]; @@ -10516,11 +10563,14 @@ int FieldOptions::ByteSize() const { } // repeated .google.protobuf.UninterpretedOption uninterpreted_option = 999; - total_size += 2 * this->uninterpreted_option_size(); - for (int i = 0; i < this->uninterpreted_option_size(); i++) { - total_size += - ::google::protobuf::internal::WireFormatLite::MessageSizeNoVirtual( - this->uninterpreted_option(i)); + { + unsigned int count = this->uninterpreted_option_size(); + total_size += 2UL * count; + for (unsigned int i = 0; i < count; i++) { + total_size += + ::google::protobuf::internal::WireFormatLite::MessageSizeNoVirtual( + this->uninterpreted_option(i)); + } } total_size += _extensions_.ByteSize(); @@ -10530,18 +10580,17 @@ int FieldOptions::ByteSize() const { ::google::protobuf::internal::WireFormat::ComputeUnknownFieldsSize( unknown_fields()); } + int cached_size = ::google::protobuf::internal::ToCachedSize(total_size); GOOGLE_SAFE_CONCURRENT_WRITES_BEGIN(); - _cached_size_ = total_size; + _cached_size_ = cached_size; GOOGLE_SAFE_CONCURRENT_WRITES_END(); return total_size; } void FieldOptions::MergeFrom(const ::google::protobuf::Message& from) { // @@protoc_insertion_point(generalized_merge_from_start:google.protobuf.FieldOptions) - if (GOOGLE_PREDICT_FALSE(&from == this)) { - ::google::protobuf::internal::MergeFromFail(__FILE__, __LINE__); - } - const FieldOptions* source = + if (GOOGLE_PREDICT_FALSE(&from == this)) MergeFromFail(__LINE__); + const FieldOptions* source = ::google::protobuf::internal::DynamicCastToGenerated( &from); if (source == NULL) { @@ -10549,15 +10598,21 @@ void FieldOptions::MergeFrom(const ::google::protobuf::Message& from) { ::google::protobuf::internal::ReflectionOps::Merge(from, this); } else { // @@protoc_insertion_point(generalized_merge_from_cast_success:google.protobuf.FieldOptions) - MergeFrom(*source); + UnsafeMergeFrom(*source); } } void FieldOptions::MergeFrom(const FieldOptions& from) { // @@protoc_insertion_point(class_specific_merge_from_start:google.protobuf.FieldOptions) - if (GOOGLE_PREDICT_FALSE(&from == this)) { - ::google::protobuf::internal::MergeFromFail(__FILE__, __LINE__); + if (GOOGLE_PREDICT_TRUE(&from != this)) { + UnsafeMergeFrom(from); + } else { + MergeFromFail(__LINE__); } +} + +void FieldOptions::UnsafeMergeFrom(const FieldOptions& from) { + GOOGLE_DCHECK(&from != this); uninterpreted_option_.MergeFrom(from.uninterpreted_option_); if (from._has_bits_[0 / 32] & (0xffu << (0 % 32))) { if (from.has_ctype()) { @@ -10581,7 +10636,8 @@ void FieldOptions::MergeFrom(const FieldOptions& from) { } _extensions_.MergeFrom(from._extensions_); if (from._internal_metadata_.have_unknown_fields()) { - mutable_unknown_fields()->MergeFrom(from.unknown_fields()); + ::google::protobuf::UnknownFieldSet::MergeToInternalMetdata( + from.unknown_fields(), &_internal_metadata_); } } @@ -10596,14 +10652,16 @@ void FieldOptions::CopyFrom(const FieldOptions& from) { // @@protoc_insertion_point(class_specific_copy_from_start:google.protobuf.FieldOptions) if (&from == this) return; Clear(); - MergeFrom(from); + UnsafeMergeFrom(from); } bool FieldOptions::IsInitialized() const { if (!::google::protobuf::internal::AllAreInitialized(this->uninterpreted_option())) return false; - if (!_extensions_.IsInitialized()) return false; + if (!_extensions_.IsInitialized()) { + return false; + } return true; } @@ -10650,11 +10708,11 @@ void FieldOptions::clear_ctype() { ctype_ = 0; clear_has_ctype(); } - ::google::protobuf::FieldOptions_CType FieldOptions::ctype() const { +::google::protobuf::FieldOptions_CType FieldOptions::ctype() const { // @@protoc_insertion_point(field_get:google.protobuf.FieldOptions.ctype) return static_cast< ::google::protobuf::FieldOptions_CType >(ctype_); } - void FieldOptions::set_ctype(::google::protobuf::FieldOptions_CType value) { +void FieldOptions::set_ctype(::google::protobuf::FieldOptions_CType value) { assert(::google::protobuf::FieldOptions_CType_IsValid(value)); set_has_ctype(); ctype_ = value; @@ -10675,11 +10733,11 @@ void FieldOptions::clear_packed() { packed_ = false; clear_has_packed(); } - bool FieldOptions::packed() const { +bool FieldOptions::packed() const { // @@protoc_insertion_point(field_get:google.protobuf.FieldOptions.packed) return packed_; } - void FieldOptions::set_packed(bool value) { +void FieldOptions::set_packed(bool value) { set_has_packed(); packed_ = value; // @@protoc_insertion_point(field_set:google.protobuf.FieldOptions.packed) @@ -10699,11 +10757,11 @@ void FieldOptions::clear_jstype() { jstype_ = 0; clear_has_jstype(); } - ::google::protobuf::FieldOptions_JSType FieldOptions::jstype() const { +::google::protobuf::FieldOptions_JSType FieldOptions::jstype() const { // @@protoc_insertion_point(field_get:google.protobuf.FieldOptions.jstype) return static_cast< ::google::protobuf::FieldOptions_JSType >(jstype_); } - void FieldOptions::set_jstype(::google::protobuf::FieldOptions_JSType value) { +void FieldOptions::set_jstype(::google::protobuf::FieldOptions_JSType value) { assert(::google::protobuf::FieldOptions_JSType_IsValid(value)); set_has_jstype(); jstype_ = value; @@ -10724,11 +10782,11 @@ void FieldOptions::clear_lazy() { lazy_ = false; clear_has_lazy(); } - bool FieldOptions::lazy() const { +bool FieldOptions::lazy() const { // @@protoc_insertion_point(field_get:google.protobuf.FieldOptions.lazy) return lazy_; } - void FieldOptions::set_lazy(bool value) { +void FieldOptions::set_lazy(bool value) { set_has_lazy(); lazy_ = value; // @@protoc_insertion_point(field_set:google.protobuf.FieldOptions.lazy) @@ -10748,11 +10806,11 @@ void FieldOptions::clear_deprecated() { deprecated_ = false; clear_has_deprecated(); } - bool FieldOptions::deprecated() const { +bool FieldOptions::deprecated() const { // @@protoc_insertion_point(field_get:google.protobuf.FieldOptions.deprecated) return deprecated_; } - void FieldOptions::set_deprecated(bool value) { +void FieldOptions::set_deprecated(bool value) { set_has_deprecated(); deprecated_ = value; // @@protoc_insertion_point(field_set:google.protobuf.FieldOptions.deprecated) @@ -10772,11 +10830,11 @@ void FieldOptions::clear_weak() { weak_ = false; clear_has_weak(); } - bool FieldOptions::weak() const { +bool FieldOptions::weak() const { // @@protoc_insertion_point(field_get:google.protobuf.FieldOptions.weak) return weak_; } - void FieldOptions::set_weak(bool value) { +void FieldOptions::set_weak(bool value) { set_has_weak(); weak_ = value; // @@protoc_insertion_point(field_set:google.protobuf.FieldOptions.weak) @@ -10822,6 +10880,7 @@ const int OneofOptions::kUninterpretedOptionFieldNumber; OneofOptions::OneofOptions() : ::google::protobuf::Message(), _internal_metadata_(NULL) { + if (this != internal_default_instance()) protobuf_InitDefaults_google_2fprotobuf_2fdescriptor_2eproto(); SharedCtor(); // @@protoc_insertion_point(constructor:google.protobuf.OneofOptions) } @@ -10833,13 +10892,12 @@ OneofOptions::OneofOptions(const OneofOptions& from) : ::google::protobuf::Message(), _internal_metadata_(NULL) { SharedCtor(); - MergeFrom(from); + UnsafeMergeFrom(from); // @@protoc_insertion_point(copy_constructor:google.protobuf.OneofOptions) } void OneofOptions::SharedCtor() { _cached_size_ = 0; - ::memset(_has_bits_, 0, sizeof(_has_bits_)); } OneofOptions::~OneofOptions() { @@ -10848,8 +10906,6 @@ OneofOptions::~OneofOptions() { } void OneofOptions::SharedDtor() { - if (this != default_instance_) { - } } void OneofOptions::SetCachedSize(int size) const { @@ -10863,11 +10919,11 @@ const ::google::protobuf::Descriptor* OneofOptions::descriptor() { } const OneofOptions& OneofOptions::default_instance() { - if (default_instance_ == NULL) protobuf_AddDesc_google_2fprotobuf_2fdescriptor_2eproto(); - return *default_instance_; + protobuf_InitDefaults_google_2fprotobuf_2fdescriptor_2eproto(); + return *internal_default_instance(); } -OneofOptions* OneofOptions::default_instance_ = NULL; +::google::protobuf::internal::ExplicitlyConstructed OneofOptions::default_instance_; OneofOptions* OneofOptions::New(::google::protobuf::Arena* arena) const { OneofOptions* n = new OneofOptions; @@ -10881,7 +10937,7 @@ void OneofOptions::Clear() { // @@protoc_insertion_point(message_clear_start:google.protobuf.OneofOptions) _extensions_.Clear(); uninterpreted_option_.Clear(); - ::memset(_has_bits_, 0, sizeof(_has_bits_)); + _has_bits_.Clear(); if (_internal_metadata_.have_unknown_fields()) { mutable_unknown_fields()->Clear(); } @@ -10921,7 +10977,7 @@ bool OneofOptions::MergePartialFromCodedStream( goto success; } if ((8000u <= tag)) { - DO_(_extensions_.ParseField(tag, input, default_instance_, + DO_(_extensions_.ParseField(tag, input, internal_default_instance(), mutable_unknown_fields())); continue; } @@ -10983,16 +11039,19 @@ void OneofOptions::SerializeWithCachedSizes( return target; } -int OneofOptions::ByteSize() const { +size_t OneofOptions::ByteSizeLong() const { // @@protoc_insertion_point(message_byte_size_start:google.protobuf.OneofOptions) - int total_size = 0; + size_t total_size = 0; // repeated .google.protobuf.UninterpretedOption uninterpreted_option = 999; - total_size += 2 * this->uninterpreted_option_size(); - for (int i = 0; i < this->uninterpreted_option_size(); i++) { - total_size += - ::google::protobuf::internal::WireFormatLite::MessageSizeNoVirtual( - this->uninterpreted_option(i)); + { + unsigned int count = this->uninterpreted_option_size(); + total_size += 2UL * count; + for (unsigned int i = 0; i < count; i++) { + total_size += + ::google::protobuf::internal::WireFormatLite::MessageSizeNoVirtual( + this->uninterpreted_option(i)); + } } total_size += _extensions_.ByteSize(); @@ -11002,18 +11061,17 @@ int OneofOptions::ByteSize() const { ::google::protobuf::internal::WireFormat::ComputeUnknownFieldsSize( unknown_fields()); } + int cached_size = ::google::protobuf::internal::ToCachedSize(total_size); GOOGLE_SAFE_CONCURRENT_WRITES_BEGIN(); - _cached_size_ = total_size; + _cached_size_ = cached_size; GOOGLE_SAFE_CONCURRENT_WRITES_END(); return total_size; } void OneofOptions::MergeFrom(const ::google::protobuf::Message& from) { // @@protoc_insertion_point(generalized_merge_from_start:google.protobuf.OneofOptions) - if (GOOGLE_PREDICT_FALSE(&from == this)) { - ::google::protobuf::internal::MergeFromFail(__FILE__, __LINE__); - } - const OneofOptions* source = + if (GOOGLE_PREDICT_FALSE(&from == this)) MergeFromFail(__LINE__); + const OneofOptions* source = ::google::protobuf::internal::DynamicCastToGenerated( &from); if (source == NULL) { @@ -11021,19 +11079,26 @@ void OneofOptions::MergeFrom(const ::google::protobuf::Message& from) { ::google::protobuf::internal::ReflectionOps::Merge(from, this); } else { // @@protoc_insertion_point(generalized_merge_from_cast_success:google.protobuf.OneofOptions) - MergeFrom(*source); + UnsafeMergeFrom(*source); } } void OneofOptions::MergeFrom(const OneofOptions& from) { // @@protoc_insertion_point(class_specific_merge_from_start:google.protobuf.OneofOptions) - if (GOOGLE_PREDICT_FALSE(&from == this)) { - ::google::protobuf::internal::MergeFromFail(__FILE__, __LINE__); + if (GOOGLE_PREDICT_TRUE(&from != this)) { + UnsafeMergeFrom(from); + } else { + MergeFromFail(__LINE__); } +} + +void OneofOptions::UnsafeMergeFrom(const OneofOptions& from) { + GOOGLE_DCHECK(&from != this); uninterpreted_option_.MergeFrom(from.uninterpreted_option_); _extensions_.MergeFrom(from._extensions_); if (from._internal_metadata_.have_unknown_fields()) { - mutable_unknown_fields()->MergeFrom(from.unknown_fields()); + ::google::protobuf::UnknownFieldSet::MergeToInternalMetdata( + from.unknown_fields(), &_internal_metadata_); } } @@ -11048,14 +11113,16 @@ void OneofOptions::CopyFrom(const OneofOptions& from) { // @@protoc_insertion_point(class_specific_copy_from_start:google.protobuf.OneofOptions) if (&from == this) return; Clear(); - MergeFrom(from); + UnsafeMergeFrom(from); } bool OneofOptions::IsInitialized() const { if (!::google::protobuf::internal::AllAreInitialized(this->uninterpreted_option())) return false; - if (!_extensions_.IsInitialized()) return false; + if (!_extensions_.IsInitialized()) { + return false; + } return true; } @@ -11124,6 +11191,7 @@ const int EnumOptions::kUninterpretedOptionFieldNumber; EnumOptions::EnumOptions() : ::google::protobuf::Message(), _internal_metadata_(NULL) { + if (this != internal_default_instance()) protobuf_InitDefaults_google_2fprotobuf_2fdescriptor_2eproto(); SharedCtor(); // @@protoc_insertion_point(constructor:google.protobuf.EnumOptions) } @@ -11135,15 +11203,14 @@ EnumOptions::EnumOptions(const EnumOptions& from) : ::google::protobuf::Message(), _internal_metadata_(NULL) { SharedCtor(); - MergeFrom(from); + UnsafeMergeFrom(from); // @@protoc_insertion_point(copy_constructor:google.protobuf.EnumOptions) } void EnumOptions::SharedCtor() { _cached_size_ = 0; - allow_alias_ = false; - deprecated_ = false; - ::memset(_has_bits_, 0, sizeof(_has_bits_)); + ::memset(&allow_alias_, 0, reinterpret_cast(&deprecated_) - + reinterpret_cast(&allow_alias_) + sizeof(deprecated_)); } EnumOptions::~EnumOptions() { @@ -11152,8 +11219,6 @@ EnumOptions::~EnumOptions() { } void EnumOptions::SharedDtor() { - if (this != default_instance_) { - } } void EnumOptions::SetCachedSize(int size) const { @@ -11167,11 +11232,11 @@ const ::google::protobuf::Descriptor* EnumOptions::descriptor() { } const EnumOptions& EnumOptions::default_instance() { - if (default_instance_ == NULL) protobuf_AddDesc_google_2fprotobuf_2fdescriptor_2eproto(); - return *default_instance_; + protobuf_InitDefaults_google_2fprotobuf_2fdescriptor_2eproto(); + return *internal_default_instance(); } -EnumOptions* EnumOptions::default_instance_ = NULL; +::google::protobuf::internal::ExplicitlyConstructed EnumOptions::default_instance_; EnumOptions* EnumOptions::New(::google::protobuf::Arena* arena) const { EnumOptions* n = new EnumOptions; @@ -11206,7 +11271,7 @@ void EnumOptions::Clear() { #undef ZR_ uninterpreted_option_.Clear(); - ::memset(_has_bits_, 0, sizeof(_has_bits_)); + _has_bits_.Clear(); if (_internal_metadata_.have_unknown_fields()) { mutable_unknown_fields()->Clear(); } @@ -11225,10 +11290,10 @@ bool EnumOptions::MergePartialFromCodedStream( // optional bool allow_alias = 2; case 2: { if (tag == 16) { + set_has_allow_alias(); DO_((::google::protobuf::internal::WireFormatLite::ReadPrimitive< bool, ::google::protobuf::internal::WireFormatLite::TYPE_BOOL>( input, &allow_alias_))); - set_has_allow_alias(); } else { goto handle_unusual; } @@ -11240,10 +11305,10 @@ bool EnumOptions::MergePartialFromCodedStream( case 3: { if (tag == 24) { parse_deprecated: + set_has_deprecated(); DO_((::google::protobuf::internal::WireFormatLite::ReadPrimitive< bool, ::google::protobuf::internal::WireFormatLite::TYPE_BOOL>( input, &deprecated_))); - set_has_deprecated(); } else { goto handle_unusual; } @@ -11276,7 +11341,7 @@ bool EnumOptions::MergePartialFromCodedStream( goto success; } if ((8000u <= tag)) { - DO_(_extensions_.ParseField(tag, input, default_instance_, + DO_(_extensions_.ParseField(tag, input, internal_default_instance(), mutable_unknown_fields())); continue; } @@ -11358,9 +11423,9 @@ void EnumOptions::SerializeWithCachedSizes( return target; } -int EnumOptions::ByteSize() const { +size_t EnumOptions::ByteSizeLong() const { // @@protoc_insertion_point(message_byte_size_start:google.protobuf.EnumOptions) - int total_size = 0; + size_t total_size = 0; if (_has_bits_[0 / 32] & 3u) { // optional bool allow_alias = 2; @@ -11375,11 +11440,14 @@ int EnumOptions::ByteSize() const { } // repeated .google.protobuf.UninterpretedOption uninterpreted_option = 999; - total_size += 2 * this->uninterpreted_option_size(); - for (int i = 0; i < this->uninterpreted_option_size(); i++) { - total_size += - ::google::protobuf::internal::WireFormatLite::MessageSizeNoVirtual( - this->uninterpreted_option(i)); + { + unsigned int count = this->uninterpreted_option_size(); + total_size += 2UL * count; + for (unsigned int i = 0; i < count; i++) { + total_size += + ::google::protobuf::internal::WireFormatLite::MessageSizeNoVirtual( + this->uninterpreted_option(i)); + } } total_size += _extensions_.ByteSize(); @@ -11389,18 +11457,17 @@ int EnumOptions::ByteSize() const { ::google::protobuf::internal::WireFormat::ComputeUnknownFieldsSize( unknown_fields()); } + int cached_size = ::google::protobuf::internal::ToCachedSize(total_size); GOOGLE_SAFE_CONCURRENT_WRITES_BEGIN(); - _cached_size_ = total_size; + _cached_size_ = cached_size; GOOGLE_SAFE_CONCURRENT_WRITES_END(); return total_size; } void EnumOptions::MergeFrom(const ::google::protobuf::Message& from) { // @@protoc_insertion_point(generalized_merge_from_start:google.protobuf.EnumOptions) - if (GOOGLE_PREDICT_FALSE(&from == this)) { - ::google::protobuf::internal::MergeFromFail(__FILE__, __LINE__); - } - const EnumOptions* source = + if (GOOGLE_PREDICT_FALSE(&from == this)) MergeFromFail(__LINE__); + const EnumOptions* source = ::google::protobuf::internal::DynamicCastToGenerated( &from); if (source == NULL) { @@ -11408,15 +11475,21 @@ void EnumOptions::MergeFrom(const ::google::protobuf::Message& from) { ::google::protobuf::internal::ReflectionOps::Merge(from, this); } else { // @@protoc_insertion_point(generalized_merge_from_cast_success:google.protobuf.EnumOptions) - MergeFrom(*source); + UnsafeMergeFrom(*source); } } void EnumOptions::MergeFrom(const EnumOptions& from) { // @@protoc_insertion_point(class_specific_merge_from_start:google.protobuf.EnumOptions) - if (GOOGLE_PREDICT_FALSE(&from == this)) { - ::google::protobuf::internal::MergeFromFail(__FILE__, __LINE__); + if (GOOGLE_PREDICT_TRUE(&from != this)) { + UnsafeMergeFrom(from); + } else { + MergeFromFail(__LINE__); } +} + +void EnumOptions::UnsafeMergeFrom(const EnumOptions& from) { + GOOGLE_DCHECK(&from != this); uninterpreted_option_.MergeFrom(from.uninterpreted_option_); if (from._has_bits_[0 / 32] & (0xffu << (0 % 32))) { if (from.has_allow_alias()) { @@ -11428,7 +11501,8 @@ void EnumOptions::MergeFrom(const EnumOptions& from) { } _extensions_.MergeFrom(from._extensions_); if (from._internal_metadata_.have_unknown_fields()) { - mutable_unknown_fields()->MergeFrom(from.unknown_fields()); + ::google::protobuf::UnknownFieldSet::MergeToInternalMetdata( + from.unknown_fields(), &_internal_metadata_); } } @@ -11443,14 +11517,16 @@ void EnumOptions::CopyFrom(const EnumOptions& from) { // @@protoc_insertion_point(class_specific_copy_from_start:google.protobuf.EnumOptions) if (&from == this) return; Clear(); - MergeFrom(from); + UnsafeMergeFrom(from); } bool EnumOptions::IsInitialized() const { if (!::google::protobuf::internal::AllAreInitialized(this->uninterpreted_option())) return false; - if (!_extensions_.IsInitialized()) return false; + if (!_extensions_.IsInitialized()) { + return false; + } return true; } @@ -11493,11 +11569,11 @@ void EnumOptions::clear_allow_alias() { allow_alias_ = false; clear_has_allow_alias(); } - bool EnumOptions::allow_alias() const { +bool EnumOptions::allow_alias() const { // @@protoc_insertion_point(field_get:google.protobuf.EnumOptions.allow_alias) return allow_alias_; } - void EnumOptions::set_allow_alias(bool value) { +void EnumOptions::set_allow_alias(bool value) { set_has_allow_alias(); allow_alias_ = value; // @@protoc_insertion_point(field_set:google.protobuf.EnumOptions.allow_alias) @@ -11517,11 +11593,11 @@ void EnumOptions::clear_deprecated() { deprecated_ = false; clear_has_deprecated(); } - bool EnumOptions::deprecated() const { +bool EnumOptions::deprecated() const { // @@protoc_insertion_point(field_get:google.protobuf.EnumOptions.deprecated) return deprecated_; } - void EnumOptions::set_deprecated(bool value) { +void EnumOptions::set_deprecated(bool value) { set_has_deprecated(); deprecated_ = value; // @@protoc_insertion_point(field_set:google.protobuf.EnumOptions.deprecated) @@ -11568,6 +11644,7 @@ const int EnumValueOptions::kUninterpretedOptionFieldNumber; EnumValueOptions::EnumValueOptions() : ::google::protobuf::Message(), _internal_metadata_(NULL) { + if (this != internal_default_instance()) protobuf_InitDefaults_google_2fprotobuf_2fdescriptor_2eproto(); SharedCtor(); // @@protoc_insertion_point(constructor:google.protobuf.EnumValueOptions) } @@ -11579,14 +11656,13 @@ EnumValueOptions::EnumValueOptions(const EnumValueOptions& from) : ::google::protobuf::Message(), _internal_metadata_(NULL) { SharedCtor(); - MergeFrom(from); + UnsafeMergeFrom(from); // @@protoc_insertion_point(copy_constructor:google.protobuf.EnumValueOptions) } void EnumValueOptions::SharedCtor() { _cached_size_ = 0; deprecated_ = false; - ::memset(_has_bits_, 0, sizeof(_has_bits_)); } EnumValueOptions::~EnumValueOptions() { @@ -11595,8 +11671,6 @@ EnumValueOptions::~EnumValueOptions() { } void EnumValueOptions::SharedDtor() { - if (this != default_instance_) { - } } void EnumValueOptions::SetCachedSize(int size) const { @@ -11610,11 +11684,11 @@ const ::google::protobuf::Descriptor* EnumValueOptions::descriptor() { } const EnumValueOptions& EnumValueOptions::default_instance() { - if (default_instance_ == NULL) protobuf_AddDesc_google_2fprotobuf_2fdescriptor_2eproto(); - return *default_instance_; + protobuf_InitDefaults_google_2fprotobuf_2fdescriptor_2eproto(); + return *internal_default_instance(); } -EnumValueOptions* EnumValueOptions::default_instance_ = NULL; +::google::protobuf::internal::ExplicitlyConstructed EnumValueOptions::default_instance_; EnumValueOptions* EnumValueOptions::New(::google::protobuf::Arena* arena) const { EnumValueOptions* n = new EnumValueOptions; @@ -11629,7 +11703,7 @@ void EnumValueOptions::Clear() { _extensions_.Clear(); deprecated_ = false; uninterpreted_option_.Clear(); - ::memset(_has_bits_, 0, sizeof(_has_bits_)); + _has_bits_.Clear(); if (_internal_metadata_.have_unknown_fields()) { mutable_unknown_fields()->Clear(); } @@ -11648,10 +11722,10 @@ bool EnumValueOptions::MergePartialFromCodedStream( // optional bool deprecated = 1 [default = false]; case 1: { if (tag == 8) { + set_has_deprecated(); DO_((::google::protobuf::internal::WireFormatLite::ReadPrimitive< bool, ::google::protobuf::internal::WireFormatLite::TYPE_BOOL>( input, &deprecated_))); - set_has_deprecated(); } else { goto handle_unusual; } @@ -11684,7 +11758,7 @@ bool EnumValueOptions::MergePartialFromCodedStream( goto success; } if ((8000u <= tag)) { - DO_(_extensions_.ParseField(tag, input, default_instance_, + DO_(_extensions_.ParseField(tag, input, internal_default_instance(), mutable_unknown_fields())); continue; } @@ -11756,9 +11830,9 @@ void EnumValueOptions::SerializeWithCachedSizes( return target; } -int EnumValueOptions::ByteSize() const { +size_t EnumValueOptions::ByteSizeLong() const { // @@protoc_insertion_point(message_byte_size_start:google.protobuf.EnumValueOptions) - int total_size = 0; + size_t total_size = 0; // optional bool deprecated = 1 [default = false]; if (has_deprecated()) { @@ -11766,11 +11840,14 @@ int EnumValueOptions::ByteSize() const { } // repeated .google.protobuf.UninterpretedOption uninterpreted_option = 999; - total_size += 2 * this->uninterpreted_option_size(); - for (int i = 0; i < this->uninterpreted_option_size(); i++) { - total_size += - ::google::protobuf::internal::WireFormatLite::MessageSizeNoVirtual( - this->uninterpreted_option(i)); + { + unsigned int count = this->uninterpreted_option_size(); + total_size += 2UL * count; + for (unsigned int i = 0; i < count; i++) { + total_size += + ::google::protobuf::internal::WireFormatLite::MessageSizeNoVirtual( + this->uninterpreted_option(i)); + } } total_size += _extensions_.ByteSize(); @@ -11780,18 +11857,17 @@ int EnumValueOptions::ByteSize() const { ::google::protobuf::internal::WireFormat::ComputeUnknownFieldsSize( unknown_fields()); } + int cached_size = ::google::protobuf::internal::ToCachedSize(total_size); GOOGLE_SAFE_CONCURRENT_WRITES_BEGIN(); - _cached_size_ = total_size; + _cached_size_ = cached_size; GOOGLE_SAFE_CONCURRENT_WRITES_END(); return total_size; } void EnumValueOptions::MergeFrom(const ::google::protobuf::Message& from) { // @@protoc_insertion_point(generalized_merge_from_start:google.protobuf.EnumValueOptions) - if (GOOGLE_PREDICT_FALSE(&from == this)) { - ::google::protobuf::internal::MergeFromFail(__FILE__, __LINE__); - } - const EnumValueOptions* source = + if (GOOGLE_PREDICT_FALSE(&from == this)) MergeFromFail(__LINE__); + const EnumValueOptions* source = ::google::protobuf::internal::DynamicCastToGenerated( &from); if (source == NULL) { @@ -11799,15 +11875,21 @@ void EnumValueOptions::MergeFrom(const ::google::protobuf::Message& from) { ::google::protobuf::internal::ReflectionOps::Merge(from, this); } else { // @@protoc_insertion_point(generalized_merge_from_cast_success:google.protobuf.EnumValueOptions) - MergeFrom(*source); + UnsafeMergeFrom(*source); } } void EnumValueOptions::MergeFrom(const EnumValueOptions& from) { // @@protoc_insertion_point(class_specific_merge_from_start:google.protobuf.EnumValueOptions) - if (GOOGLE_PREDICT_FALSE(&from == this)) { - ::google::protobuf::internal::MergeFromFail(__FILE__, __LINE__); + if (GOOGLE_PREDICT_TRUE(&from != this)) { + UnsafeMergeFrom(from); + } else { + MergeFromFail(__LINE__); } +} + +void EnumValueOptions::UnsafeMergeFrom(const EnumValueOptions& from) { + GOOGLE_DCHECK(&from != this); uninterpreted_option_.MergeFrom(from.uninterpreted_option_); if (from._has_bits_[0 / 32] & (0xffu << (0 % 32))) { if (from.has_deprecated()) { @@ -11816,7 +11898,8 @@ void EnumValueOptions::MergeFrom(const EnumValueOptions& from) { } _extensions_.MergeFrom(from._extensions_); if (from._internal_metadata_.have_unknown_fields()) { - mutable_unknown_fields()->MergeFrom(from.unknown_fields()); + ::google::protobuf::UnknownFieldSet::MergeToInternalMetdata( + from.unknown_fields(), &_internal_metadata_); } } @@ -11831,14 +11914,16 @@ void EnumValueOptions::CopyFrom(const EnumValueOptions& from) { // @@protoc_insertion_point(class_specific_copy_from_start:google.protobuf.EnumValueOptions) if (&from == this) return; Clear(); - MergeFrom(from); + UnsafeMergeFrom(from); } bool EnumValueOptions::IsInitialized() const { if (!::google::protobuf::internal::AllAreInitialized(this->uninterpreted_option())) return false; - if (!_extensions_.IsInitialized()) return false; + if (!_extensions_.IsInitialized()) { + return false; + } return true; } @@ -11880,11 +11965,11 @@ void EnumValueOptions::clear_deprecated() { deprecated_ = false; clear_has_deprecated(); } - bool EnumValueOptions::deprecated() const { +bool EnumValueOptions::deprecated() const { // @@protoc_insertion_point(field_get:google.protobuf.EnumValueOptions.deprecated) return deprecated_; } - void EnumValueOptions::set_deprecated(bool value) { +void EnumValueOptions::set_deprecated(bool value) { set_has_deprecated(); deprecated_ = value; // @@protoc_insertion_point(field_set:google.protobuf.EnumValueOptions.deprecated) @@ -11931,6 +12016,7 @@ const int ServiceOptions::kUninterpretedOptionFieldNumber; ServiceOptions::ServiceOptions() : ::google::protobuf::Message(), _internal_metadata_(NULL) { + if (this != internal_default_instance()) protobuf_InitDefaults_google_2fprotobuf_2fdescriptor_2eproto(); SharedCtor(); // @@protoc_insertion_point(constructor:google.protobuf.ServiceOptions) } @@ -11942,14 +12028,13 @@ ServiceOptions::ServiceOptions(const ServiceOptions& from) : ::google::protobuf::Message(), _internal_metadata_(NULL) { SharedCtor(); - MergeFrom(from); + UnsafeMergeFrom(from); // @@protoc_insertion_point(copy_constructor:google.protobuf.ServiceOptions) } void ServiceOptions::SharedCtor() { _cached_size_ = 0; deprecated_ = false; - ::memset(_has_bits_, 0, sizeof(_has_bits_)); } ServiceOptions::~ServiceOptions() { @@ -11958,8 +12043,6 @@ ServiceOptions::~ServiceOptions() { } void ServiceOptions::SharedDtor() { - if (this != default_instance_) { - } } void ServiceOptions::SetCachedSize(int size) const { @@ -11973,11 +12056,11 @@ const ::google::protobuf::Descriptor* ServiceOptions::descriptor() { } const ServiceOptions& ServiceOptions::default_instance() { - if (default_instance_ == NULL) protobuf_AddDesc_google_2fprotobuf_2fdescriptor_2eproto(); - return *default_instance_; + protobuf_InitDefaults_google_2fprotobuf_2fdescriptor_2eproto(); + return *internal_default_instance(); } -ServiceOptions* ServiceOptions::default_instance_ = NULL; +::google::protobuf::internal::ExplicitlyConstructed ServiceOptions::default_instance_; ServiceOptions* ServiceOptions::New(::google::protobuf::Arena* arena) const { ServiceOptions* n = new ServiceOptions; @@ -11992,7 +12075,7 @@ void ServiceOptions::Clear() { _extensions_.Clear(); deprecated_ = false; uninterpreted_option_.Clear(); - ::memset(_has_bits_, 0, sizeof(_has_bits_)); + _has_bits_.Clear(); if (_internal_metadata_.have_unknown_fields()) { mutable_unknown_fields()->Clear(); } @@ -12011,10 +12094,10 @@ bool ServiceOptions::MergePartialFromCodedStream( // optional bool deprecated = 33 [default = false]; case 33: { if (tag == 264) { + set_has_deprecated(); DO_((::google::protobuf::internal::WireFormatLite::ReadPrimitive< bool, ::google::protobuf::internal::WireFormatLite::TYPE_BOOL>( input, &deprecated_))); - set_has_deprecated(); } else { goto handle_unusual; } @@ -12047,7 +12130,7 @@ bool ServiceOptions::MergePartialFromCodedStream( goto success; } if ((8000u <= tag)) { - DO_(_extensions_.ParseField(tag, input, default_instance_, + DO_(_extensions_.ParseField(tag, input, internal_default_instance(), mutable_unknown_fields())); continue; } @@ -12119,9 +12202,9 @@ void ServiceOptions::SerializeWithCachedSizes( return target; } -int ServiceOptions::ByteSize() const { +size_t ServiceOptions::ByteSizeLong() const { // @@protoc_insertion_point(message_byte_size_start:google.protobuf.ServiceOptions) - int total_size = 0; + size_t total_size = 0; // optional bool deprecated = 33 [default = false]; if (has_deprecated()) { @@ -12129,11 +12212,14 @@ int ServiceOptions::ByteSize() const { } // repeated .google.protobuf.UninterpretedOption uninterpreted_option = 999; - total_size += 2 * this->uninterpreted_option_size(); - for (int i = 0; i < this->uninterpreted_option_size(); i++) { - total_size += - ::google::protobuf::internal::WireFormatLite::MessageSizeNoVirtual( - this->uninterpreted_option(i)); + { + unsigned int count = this->uninterpreted_option_size(); + total_size += 2UL * count; + for (unsigned int i = 0; i < count; i++) { + total_size += + ::google::protobuf::internal::WireFormatLite::MessageSizeNoVirtual( + this->uninterpreted_option(i)); + } } total_size += _extensions_.ByteSize(); @@ -12143,18 +12229,17 @@ int ServiceOptions::ByteSize() const { ::google::protobuf::internal::WireFormat::ComputeUnknownFieldsSize( unknown_fields()); } + int cached_size = ::google::protobuf::internal::ToCachedSize(total_size); GOOGLE_SAFE_CONCURRENT_WRITES_BEGIN(); - _cached_size_ = total_size; + _cached_size_ = cached_size; GOOGLE_SAFE_CONCURRENT_WRITES_END(); return total_size; } void ServiceOptions::MergeFrom(const ::google::protobuf::Message& from) { // @@protoc_insertion_point(generalized_merge_from_start:google.protobuf.ServiceOptions) - if (GOOGLE_PREDICT_FALSE(&from == this)) { - ::google::protobuf::internal::MergeFromFail(__FILE__, __LINE__); - } - const ServiceOptions* source = + if (GOOGLE_PREDICT_FALSE(&from == this)) MergeFromFail(__LINE__); + const ServiceOptions* source = ::google::protobuf::internal::DynamicCastToGenerated( &from); if (source == NULL) { @@ -12162,15 +12247,21 @@ void ServiceOptions::MergeFrom(const ::google::protobuf::Message& from) { ::google::protobuf::internal::ReflectionOps::Merge(from, this); } else { // @@protoc_insertion_point(generalized_merge_from_cast_success:google.protobuf.ServiceOptions) - MergeFrom(*source); + UnsafeMergeFrom(*source); } } void ServiceOptions::MergeFrom(const ServiceOptions& from) { // @@protoc_insertion_point(class_specific_merge_from_start:google.protobuf.ServiceOptions) - if (GOOGLE_PREDICT_FALSE(&from == this)) { - ::google::protobuf::internal::MergeFromFail(__FILE__, __LINE__); + if (GOOGLE_PREDICT_TRUE(&from != this)) { + UnsafeMergeFrom(from); + } else { + MergeFromFail(__LINE__); } +} + +void ServiceOptions::UnsafeMergeFrom(const ServiceOptions& from) { + GOOGLE_DCHECK(&from != this); uninterpreted_option_.MergeFrom(from.uninterpreted_option_); if (from._has_bits_[0 / 32] & (0xffu << (0 % 32))) { if (from.has_deprecated()) { @@ -12179,7 +12270,8 @@ void ServiceOptions::MergeFrom(const ServiceOptions& from) { } _extensions_.MergeFrom(from._extensions_); if (from._internal_metadata_.have_unknown_fields()) { - mutable_unknown_fields()->MergeFrom(from.unknown_fields()); + ::google::protobuf::UnknownFieldSet::MergeToInternalMetdata( + from.unknown_fields(), &_internal_metadata_); } } @@ -12194,14 +12286,16 @@ void ServiceOptions::CopyFrom(const ServiceOptions& from) { // @@protoc_insertion_point(class_specific_copy_from_start:google.protobuf.ServiceOptions) if (&from == this) return; Clear(); - MergeFrom(from); + UnsafeMergeFrom(from); } bool ServiceOptions::IsInitialized() const { if (!::google::protobuf::internal::AllAreInitialized(this->uninterpreted_option())) return false; - if (!_extensions_.IsInitialized()) return false; + if (!_extensions_.IsInitialized()) { + return false; + } return true; } @@ -12243,11 +12337,11 @@ void ServiceOptions::clear_deprecated() { deprecated_ = false; clear_has_deprecated(); } - bool ServiceOptions::deprecated() const { +bool ServiceOptions::deprecated() const { // @@protoc_insertion_point(field_get:google.protobuf.ServiceOptions.deprecated) return deprecated_; } - void ServiceOptions::set_deprecated(bool value) { +void ServiceOptions::set_deprecated(bool value) { set_has_deprecated(); deprecated_ = value; // @@protoc_insertion_point(field_set:google.protobuf.ServiceOptions.deprecated) @@ -12294,6 +12388,7 @@ const int MethodOptions::kUninterpretedOptionFieldNumber; MethodOptions::MethodOptions() : ::google::protobuf::Message(), _internal_metadata_(NULL) { + if (this != internal_default_instance()) protobuf_InitDefaults_google_2fprotobuf_2fdescriptor_2eproto(); SharedCtor(); // @@protoc_insertion_point(constructor:google.protobuf.MethodOptions) } @@ -12305,14 +12400,13 @@ MethodOptions::MethodOptions(const MethodOptions& from) : ::google::protobuf::Message(), _internal_metadata_(NULL) { SharedCtor(); - MergeFrom(from); + UnsafeMergeFrom(from); // @@protoc_insertion_point(copy_constructor:google.protobuf.MethodOptions) } void MethodOptions::SharedCtor() { _cached_size_ = 0; deprecated_ = false; - ::memset(_has_bits_, 0, sizeof(_has_bits_)); } MethodOptions::~MethodOptions() { @@ -12321,8 +12415,6 @@ MethodOptions::~MethodOptions() { } void MethodOptions::SharedDtor() { - if (this != default_instance_) { - } } void MethodOptions::SetCachedSize(int size) const { @@ -12336,11 +12428,11 @@ const ::google::protobuf::Descriptor* MethodOptions::descriptor() { } const MethodOptions& MethodOptions::default_instance() { - if (default_instance_ == NULL) protobuf_AddDesc_google_2fprotobuf_2fdescriptor_2eproto(); - return *default_instance_; + protobuf_InitDefaults_google_2fprotobuf_2fdescriptor_2eproto(); + return *internal_default_instance(); } -MethodOptions* MethodOptions::default_instance_ = NULL; +::google::protobuf::internal::ExplicitlyConstructed MethodOptions::default_instance_; MethodOptions* MethodOptions::New(::google::protobuf::Arena* arena) const { MethodOptions* n = new MethodOptions; @@ -12355,7 +12447,7 @@ void MethodOptions::Clear() { _extensions_.Clear(); deprecated_ = false; uninterpreted_option_.Clear(); - ::memset(_has_bits_, 0, sizeof(_has_bits_)); + _has_bits_.Clear(); if (_internal_metadata_.have_unknown_fields()) { mutable_unknown_fields()->Clear(); } @@ -12374,10 +12466,10 @@ bool MethodOptions::MergePartialFromCodedStream( // optional bool deprecated = 33 [default = false]; case 33: { if (tag == 264) { + set_has_deprecated(); DO_((::google::protobuf::internal::WireFormatLite::ReadPrimitive< bool, ::google::protobuf::internal::WireFormatLite::TYPE_BOOL>( input, &deprecated_))); - set_has_deprecated(); } else { goto handle_unusual; } @@ -12410,7 +12502,7 @@ bool MethodOptions::MergePartialFromCodedStream( goto success; } if ((8000u <= tag)) { - DO_(_extensions_.ParseField(tag, input, default_instance_, + DO_(_extensions_.ParseField(tag, input, internal_default_instance(), mutable_unknown_fields())); continue; } @@ -12482,9 +12574,9 @@ void MethodOptions::SerializeWithCachedSizes( return target; } -int MethodOptions::ByteSize() const { +size_t MethodOptions::ByteSizeLong() const { // @@protoc_insertion_point(message_byte_size_start:google.protobuf.MethodOptions) - int total_size = 0; + size_t total_size = 0; // optional bool deprecated = 33 [default = false]; if (has_deprecated()) { @@ -12492,11 +12584,14 @@ int MethodOptions::ByteSize() const { } // repeated .google.protobuf.UninterpretedOption uninterpreted_option = 999; - total_size += 2 * this->uninterpreted_option_size(); - for (int i = 0; i < this->uninterpreted_option_size(); i++) { - total_size += - ::google::protobuf::internal::WireFormatLite::MessageSizeNoVirtual( - this->uninterpreted_option(i)); + { + unsigned int count = this->uninterpreted_option_size(); + total_size += 2UL * count; + for (unsigned int i = 0; i < count; i++) { + total_size += + ::google::protobuf::internal::WireFormatLite::MessageSizeNoVirtual( + this->uninterpreted_option(i)); + } } total_size += _extensions_.ByteSize(); @@ -12506,18 +12601,17 @@ int MethodOptions::ByteSize() const { ::google::protobuf::internal::WireFormat::ComputeUnknownFieldsSize( unknown_fields()); } + int cached_size = ::google::protobuf::internal::ToCachedSize(total_size); GOOGLE_SAFE_CONCURRENT_WRITES_BEGIN(); - _cached_size_ = total_size; + _cached_size_ = cached_size; GOOGLE_SAFE_CONCURRENT_WRITES_END(); return total_size; } void MethodOptions::MergeFrom(const ::google::protobuf::Message& from) { // @@protoc_insertion_point(generalized_merge_from_start:google.protobuf.MethodOptions) - if (GOOGLE_PREDICT_FALSE(&from == this)) { - ::google::protobuf::internal::MergeFromFail(__FILE__, __LINE__); - } - const MethodOptions* source = + if (GOOGLE_PREDICT_FALSE(&from == this)) MergeFromFail(__LINE__); + const MethodOptions* source = ::google::protobuf::internal::DynamicCastToGenerated( &from); if (source == NULL) { @@ -12525,15 +12619,21 @@ void MethodOptions::MergeFrom(const ::google::protobuf::Message& from) { ::google::protobuf::internal::ReflectionOps::Merge(from, this); } else { // @@protoc_insertion_point(generalized_merge_from_cast_success:google.protobuf.MethodOptions) - MergeFrom(*source); + UnsafeMergeFrom(*source); } } void MethodOptions::MergeFrom(const MethodOptions& from) { // @@protoc_insertion_point(class_specific_merge_from_start:google.protobuf.MethodOptions) - if (GOOGLE_PREDICT_FALSE(&from == this)) { - ::google::protobuf::internal::MergeFromFail(__FILE__, __LINE__); + if (GOOGLE_PREDICT_TRUE(&from != this)) { + UnsafeMergeFrom(from); + } else { + MergeFromFail(__LINE__); } +} + +void MethodOptions::UnsafeMergeFrom(const MethodOptions& from) { + GOOGLE_DCHECK(&from != this); uninterpreted_option_.MergeFrom(from.uninterpreted_option_); if (from._has_bits_[0 / 32] & (0xffu << (0 % 32))) { if (from.has_deprecated()) { @@ -12542,7 +12642,8 @@ void MethodOptions::MergeFrom(const MethodOptions& from) { } _extensions_.MergeFrom(from._extensions_); if (from._internal_metadata_.have_unknown_fields()) { - mutable_unknown_fields()->MergeFrom(from.unknown_fields()); + ::google::protobuf::UnknownFieldSet::MergeToInternalMetdata( + from.unknown_fields(), &_internal_metadata_); } } @@ -12557,14 +12658,16 @@ void MethodOptions::CopyFrom(const MethodOptions& from) { // @@protoc_insertion_point(class_specific_copy_from_start:google.protobuf.MethodOptions) if (&from == this) return; Clear(); - MergeFrom(from); + UnsafeMergeFrom(from); } bool MethodOptions::IsInitialized() const { if (!::google::protobuf::internal::AllAreInitialized(this->uninterpreted_option())) return false; - if (!_extensions_.IsInitialized()) return false; + if (!_extensions_.IsInitialized()) { + return false; + } return true; } @@ -12606,11 +12709,11 @@ void MethodOptions::clear_deprecated() { deprecated_ = false; clear_has_deprecated(); } - bool MethodOptions::deprecated() const { +bool MethodOptions::deprecated() const { // @@protoc_insertion_point(field_get:google.protobuf.MethodOptions.deprecated) return deprecated_; } - void MethodOptions::set_deprecated(bool value) { +void MethodOptions::set_deprecated(bool value) { set_has_deprecated(); deprecated_ = value; // @@protoc_insertion_point(field_set:google.protobuf.MethodOptions.deprecated) @@ -12657,6 +12760,7 @@ const int UninterpretedOption_NamePart::kIsExtensionFieldNumber; UninterpretedOption_NamePart::UninterpretedOption_NamePart() : ::google::protobuf::Message(), _internal_metadata_(NULL) { + if (this != internal_default_instance()) protobuf_InitDefaults_google_2fprotobuf_2fdescriptor_2eproto(); SharedCtor(); // @@protoc_insertion_point(constructor:google.protobuf.UninterpretedOption.NamePart) } @@ -12668,16 +12772,14 @@ UninterpretedOption_NamePart::UninterpretedOption_NamePart(const UninterpretedOp : ::google::protobuf::Message(), _internal_metadata_(NULL) { SharedCtor(); - MergeFrom(from); + UnsafeMergeFrom(from); // @@protoc_insertion_point(copy_constructor:google.protobuf.UninterpretedOption.NamePart) } void UninterpretedOption_NamePart::SharedCtor() { - ::google::protobuf::internal::GetEmptyString(); _cached_size_ = 0; name_part_.UnsafeSetDefault(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); is_extension_ = false; - ::memset(_has_bits_, 0, sizeof(_has_bits_)); } UninterpretedOption_NamePart::~UninterpretedOption_NamePart() { @@ -12687,8 +12789,6 @@ UninterpretedOption_NamePart::~UninterpretedOption_NamePart() { void UninterpretedOption_NamePart::SharedDtor() { name_part_.DestroyNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); - if (this != default_instance_) { - } } void UninterpretedOption_NamePart::SetCachedSize(int size) const { @@ -12702,11 +12802,11 @@ const ::google::protobuf::Descriptor* UninterpretedOption_NamePart::descriptor() } const UninterpretedOption_NamePart& UninterpretedOption_NamePart::default_instance() { - if (default_instance_ == NULL) protobuf_AddDesc_google_2fprotobuf_2fdescriptor_2eproto(); - return *default_instance_; + protobuf_InitDefaults_google_2fprotobuf_2fdescriptor_2eproto(); + return *internal_default_instance(); } -UninterpretedOption_NamePart* UninterpretedOption_NamePart::default_instance_ = NULL; +::google::protobuf::internal::ExplicitlyConstructed UninterpretedOption_NamePart::default_instance_; UninterpretedOption_NamePart* UninterpretedOption_NamePart::New(::google::protobuf::Arena* arena) const { UninterpretedOption_NamePart* n = new UninterpretedOption_NamePart; @@ -12724,7 +12824,7 @@ void UninterpretedOption_NamePart::Clear() { } is_extension_ = false; } - ::memset(_has_bits_, 0, sizeof(_has_bits_)); + _has_bits_.Clear(); if (_internal_metadata_.have_unknown_fields()) { mutable_unknown_fields()->Clear(); } @@ -12760,10 +12860,10 @@ bool UninterpretedOption_NamePart::MergePartialFromCodedStream( case 2: { if (tag == 16) { parse_is_extension: + set_has_is_extension(); DO_((::google::protobuf::internal::WireFormatLite::ReadPrimitive< bool, ::google::protobuf::internal::WireFormatLite::TYPE_BOOL>( input, &is_extension_))); - set_has_is_extension(); } else { goto handle_unusual; } @@ -12846,9 +12946,9 @@ void UninterpretedOption_NamePart::SerializeWithCachedSizes( return target; } -int UninterpretedOption_NamePart::RequiredFieldsByteSizeFallback() const { +size_t UninterpretedOption_NamePart::RequiredFieldsByteSizeFallback() const { // @@protoc_insertion_point(required_fields_byte_size_fallback_start:google.protobuf.UninterpretedOption.NamePart) - int total_size = 0; + size_t total_size = 0; if (has_name_part()) { // required string name_part = 1; @@ -12864,9 +12964,9 @@ int UninterpretedOption_NamePart::RequiredFieldsByteSizeFallback() const { return total_size; } -int UninterpretedOption_NamePart::ByteSize() const { +size_t UninterpretedOption_NamePart::ByteSizeLong() const { // @@protoc_insertion_point(message_byte_size_start:google.protobuf.UninterpretedOption.NamePart) - int total_size = 0; + size_t total_size = 0; if (((_has_bits_[0] & 0x00000003) ^ 0x00000003) == 0) { // All required fields are present. // required string name_part = 1; @@ -12885,18 +12985,17 @@ int UninterpretedOption_NamePart::ByteSize() const { ::google::protobuf::internal::WireFormat::ComputeUnknownFieldsSize( unknown_fields()); } + int cached_size = ::google::protobuf::internal::ToCachedSize(total_size); GOOGLE_SAFE_CONCURRENT_WRITES_BEGIN(); - _cached_size_ = total_size; + _cached_size_ = cached_size; GOOGLE_SAFE_CONCURRENT_WRITES_END(); return total_size; } void UninterpretedOption_NamePart::MergeFrom(const ::google::protobuf::Message& from) { // @@protoc_insertion_point(generalized_merge_from_start:google.protobuf.UninterpretedOption.NamePart) - if (GOOGLE_PREDICT_FALSE(&from == this)) { - ::google::protobuf::internal::MergeFromFail(__FILE__, __LINE__); - } - const UninterpretedOption_NamePart* source = + if (GOOGLE_PREDICT_FALSE(&from == this)) MergeFromFail(__LINE__); + const UninterpretedOption_NamePart* source = ::google::protobuf::internal::DynamicCastToGenerated( &from); if (source == NULL) { @@ -12904,15 +13003,21 @@ void UninterpretedOption_NamePart::MergeFrom(const ::google::protobuf::Message& ::google::protobuf::internal::ReflectionOps::Merge(from, this); } else { // @@protoc_insertion_point(generalized_merge_from_cast_success:google.protobuf.UninterpretedOption.NamePart) - MergeFrom(*source); + UnsafeMergeFrom(*source); } } void UninterpretedOption_NamePart::MergeFrom(const UninterpretedOption_NamePart& from) { // @@protoc_insertion_point(class_specific_merge_from_start:google.protobuf.UninterpretedOption.NamePart) - if (GOOGLE_PREDICT_FALSE(&from == this)) { - ::google::protobuf::internal::MergeFromFail(__FILE__, __LINE__); + if (GOOGLE_PREDICT_TRUE(&from != this)) { + UnsafeMergeFrom(from); + } else { + MergeFromFail(__LINE__); } +} + +void UninterpretedOption_NamePart::UnsafeMergeFrom(const UninterpretedOption_NamePart& from) { + GOOGLE_DCHECK(&from != this); if (from._has_bits_[0 / 32] & (0xffu << (0 % 32))) { if (from.has_name_part()) { set_has_name_part(); @@ -12923,7 +13028,8 @@ void UninterpretedOption_NamePart::MergeFrom(const UninterpretedOption_NamePart& } } if (from._internal_metadata_.have_unknown_fields()) { - mutable_unknown_fields()->MergeFrom(from.unknown_fields()); + ::google::protobuf::UnknownFieldSet::MergeToInternalMetdata( + from.unknown_fields(), &_internal_metadata_); } } @@ -12938,7 +13044,7 @@ void UninterpretedOption_NamePart::CopyFrom(const UninterpretedOption_NamePart& // @@protoc_insertion_point(class_specific_copy_from_start:google.protobuf.UninterpretedOption.NamePart) if (&from == this) return; Clear(); - MergeFrom(from); + UnsafeMergeFrom(from); } bool UninterpretedOption_NamePart::IsInitialized() const { @@ -12982,6 +13088,7 @@ const int UninterpretedOption::kAggregateValueFieldNumber; UninterpretedOption::UninterpretedOption() : ::google::protobuf::Message(), _internal_metadata_(NULL) { + if (this != internal_default_instance()) protobuf_InitDefaults_google_2fprotobuf_2fdescriptor_2eproto(); SharedCtor(); // @@protoc_insertion_point(constructor:google.protobuf.UninterpretedOption) } @@ -12993,20 +13100,17 @@ UninterpretedOption::UninterpretedOption(const UninterpretedOption& from) : ::google::protobuf::Message(), _internal_metadata_(NULL) { SharedCtor(); - MergeFrom(from); + UnsafeMergeFrom(from); // @@protoc_insertion_point(copy_constructor:google.protobuf.UninterpretedOption) } void UninterpretedOption::SharedCtor() { - ::google::protobuf::internal::GetEmptyString(); _cached_size_ = 0; identifier_value_.UnsafeSetDefault(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); - positive_int_value_ = GOOGLE_ULONGLONG(0); - negative_int_value_ = GOOGLE_LONGLONG(0); - double_value_ = 0; string_value_.UnsafeSetDefault(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); aggregate_value_.UnsafeSetDefault(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); - ::memset(_has_bits_, 0, sizeof(_has_bits_)); + ::memset(&positive_int_value_, 0, reinterpret_cast(&double_value_) - + reinterpret_cast(&positive_int_value_) + sizeof(double_value_)); } UninterpretedOption::~UninterpretedOption() { @@ -13018,8 +13122,6 @@ void UninterpretedOption::SharedDtor() { identifier_value_.DestroyNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); string_value_.DestroyNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); aggregate_value_.DestroyNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); - if (this != default_instance_) { - } } void UninterpretedOption::SetCachedSize(int size) const { @@ -13033,11 +13135,11 @@ const ::google::protobuf::Descriptor* UninterpretedOption::descriptor() { } const UninterpretedOption& UninterpretedOption::default_instance() { - if (default_instance_ == NULL) protobuf_AddDesc_google_2fprotobuf_2fdescriptor_2eproto(); - return *default_instance_; + protobuf_InitDefaults_google_2fprotobuf_2fdescriptor_2eproto(); + return *internal_default_instance(); } -UninterpretedOption* UninterpretedOption::default_instance_ = NULL; +::google::protobuf::internal::ExplicitlyConstructed UninterpretedOption::default_instance_; UninterpretedOption* UninterpretedOption::New(::google::protobuf::Arena* arena) const { UninterpretedOption* n = new UninterpretedOption; @@ -13082,7 +13184,7 @@ void UninterpretedOption::Clear() { #undef ZR_ name_.Clear(); - ::memset(_has_bits_, 0, sizeof(_has_bits_)); + _has_bits_.Clear(); if (_internal_metadata_.have_unknown_fields()) { mutable_unknown_fields()->Clear(); } @@ -13135,10 +13237,10 @@ bool UninterpretedOption::MergePartialFromCodedStream( case 4: { if (tag == 32) { parse_positive_int_value: + set_has_positive_int_value(); DO_((::google::protobuf::internal::WireFormatLite::ReadPrimitive< ::google::protobuf::uint64, ::google::protobuf::internal::WireFormatLite::TYPE_UINT64>( input, &positive_int_value_))); - set_has_positive_int_value(); } else { goto handle_unusual; } @@ -13150,10 +13252,10 @@ bool UninterpretedOption::MergePartialFromCodedStream( case 5: { if (tag == 40) { parse_negative_int_value: + set_has_negative_int_value(); DO_((::google::protobuf::internal::WireFormatLite::ReadPrimitive< ::google::protobuf::int64, ::google::protobuf::internal::WireFormatLite::TYPE_INT64>( input, &negative_int_value_))); - set_has_negative_int_value(); } else { goto handle_unusual; } @@ -13165,10 +13267,10 @@ bool UninterpretedOption::MergePartialFromCodedStream( case 6: { if (tag == 49) { parse_double_value: + set_has_double_value(); DO_((::google::protobuf::internal::WireFormatLite::ReadPrimitive< double, ::google::protobuf::internal::WireFormatLite::TYPE_DOUBLE>( input, &double_value_))); - set_has_double_value(); } else { goto handle_unusual; } @@ -13348,9 +13450,9 @@ void UninterpretedOption::SerializeWithCachedSizes( return target; } -int UninterpretedOption::ByteSize() const { +size_t UninterpretedOption::ByteSizeLong() const { // @@protoc_insertion_point(message_byte_size_start:google.protobuf.UninterpretedOption) - int total_size = 0; + size_t total_size = 0; if (_has_bits_[1 / 32] & 126u) { // optional string identifier_value = 3; @@ -13395,11 +13497,14 @@ int UninterpretedOption::ByteSize() const { } // repeated .google.protobuf.UninterpretedOption.NamePart name = 2; - total_size += 1 * this->name_size(); - for (int i = 0; i < this->name_size(); i++) { - total_size += - ::google::protobuf::internal::WireFormatLite::MessageSizeNoVirtual( - this->name(i)); + { + unsigned int count = this->name_size(); + total_size += 1UL * count; + for (unsigned int i = 0; i < count; i++) { + total_size += + ::google::protobuf::internal::WireFormatLite::MessageSizeNoVirtual( + this->name(i)); + } } if (_internal_metadata_.have_unknown_fields()) { @@ -13407,18 +13512,17 @@ int UninterpretedOption::ByteSize() const { ::google::protobuf::internal::WireFormat::ComputeUnknownFieldsSize( unknown_fields()); } + int cached_size = ::google::protobuf::internal::ToCachedSize(total_size); GOOGLE_SAFE_CONCURRENT_WRITES_BEGIN(); - _cached_size_ = total_size; + _cached_size_ = cached_size; GOOGLE_SAFE_CONCURRENT_WRITES_END(); return total_size; } void UninterpretedOption::MergeFrom(const ::google::protobuf::Message& from) { // @@protoc_insertion_point(generalized_merge_from_start:google.protobuf.UninterpretedOption) - if (GOOGLE_PREDICT_FALSE(&from == this)) { - ::google::protobuf::internal::MergeFromFail(__FILE__, __LINE__); - } - const UninterpretedOption* source = + if (GOOGLE_PREDICT_FALSE(&from == this)) MergeFromFail(__LINE__); + const UninterpretedOption* source = ::google::protobuf::internal::DynamicCastToGenerated( &from); if (source == NULL) { @@ -13426,15 +13530,21 @@ void UninterpretedOption::MergeFrom(const ::google::protobuf::Message& from) { ::google::protobuf::internal::ReflectionOps::Merge(from, this); } else { // @@protoc_insertion_point(generalized_merge_from_cast_success:google.protobuf.UninterpretedOption) - MergeFrom(*source); + UnsafeMergeFrom(*source); } } void UninterpretedOption::MergeFrom(const UninterpretedOption& from) { // @@protoc_insertion_point(class_specific_merge_from_start:google.protobuf.UninterpretedOption) - if (GOOGLE_PREDICT_FALSE(&from == this)) { - ::google::protobuf::internal::MergeFromFail(__FILE__, __LINE__); + if (GOOGLE_PREDICT_TRUE(&from != this)) { + UnsafeMergeFrom(from); + } else { + MergeFromFail(__LINE__); } +} + +void UninterpretedOption::UnsafeMergeFrom(const UninterpretedOption& from) { + GOOGLE_DCHECK(&from != this); name_.MergeFrom(from.name_); if (from._has_bits_[1 / 32] & (0xffu << (1 % 32))) { if (from.has_identifier_value()) { @@ -13460,7 +13570,8 @@ void UninterpretedOption::MergeFrom(const UninterpretedOption& from) { } } if (from._internal_metadata_.have_unknown_fields()) { - mutable_unknown_fields()->MergeFrom(from.unknown_fields()); + ::google::protobuf::UnknownFieldSet::MergeToInternalMetdata( + from.unknown_fields(), &_internal_metadata_); } } @@ -13475,7 +13586,7 @@ void UninterpretedOption::CopyFrom(const UninterpretedOption& from) { // @@protoc_insertion_point(class_specific_copy_from_start:google.protobuf.UninterpretedOption) if (&from == this) return; Clear(); - MergeFrom(from); + UnsafeMergeFrom(from); } bool UninterpretedOption::IsInitialized() const { @@ -13526,37 +13637,37 @@ void UninterpretedOption_NamePart::clear_name_part() { name_part_.ClearToEmptyNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); clear_has_name_part(); } - const ::std::string& UninterpretedOption_NamePart::name_part() const { +const ::std::string& UninterpretedOption_NamePart::name_part() const { // @@protoc_insertion_point(field_get:google.protobuf.UninterpretedOption.NamePart.name_part) return name_part_.GetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); } - void UninterpretedOption_NamePart::set_name_part(const ::std::string& value) { +void UninterpretedOption_NamePart::set_name_part(const ::std::string& value) { set_has_name_part(); name_part_.SetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), value); // @@protoc_insertion_point(field_set:google.protobuf.UninterpretedOption.NamePart.name_part) } - void UninterpretedOption_NamePart::set_name_part(const char* value) { +void UninterpretedOption_NamePart::set_name_part(const char* value) { set_has_name_part(); name_part_.SetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), ::std::string(value)); // @@protoc_insertion_point(field_set_char:google.protobuf.UninterpretedOption.NamePart.name_part) } - void UninterpretedOption_NamePart::set_name_part(const char* value, size_t size) { +void UninterpretedOption_NamePart::set_name_part(const char* value, size_t size) { set_has_name_part(); name_part_.SetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), ::std::string(reinterpret_cast(value), size)); // @@protoc_insertion_point(field_set_pointer:google.protobuf.UninterpretedOption.NamePart.name_part) } - ::std::string* UninterpretedOption_NamePart::mutable_name_part() { +::std::string* UninterpretedOption_NamePart::mutable_name_part() { set_has_name_part(); // @@protoc_insertion_point(field_mutable:google.protobuf.UninterpretedOption.NamePart.name_part) return name_part_.MutableNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); } - ::std::string* UninterpretedOption_NamePart::release_name_part() { +::std::string* UninterpretedOption_NamePart::release_name_part() { // @@protoc_insertion_point(field_release:google.protobuf.UninterpretedOption.NamePart.name_part) clear_has_name_part(); return name_part_.ReleaseNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); } - void UninterpretedOption_NamePart::set_allocated_name_part(::std::string* name_part) { +void UninterpretedOption_NamePart::set_allocated_name_part(::std::string* name_part) { if (name_part != NULL) { set_has_name_part(); } else { @@ -13580,11 +13691,11 @@ void UninterpretedOption_NamePart::clear_is_extension() { is_extension_ = false; clear_has_is_extension(); } - bool UninterpretedOption_NamePart::is_extension() const { +bool UninterpretedOption_NamePart::is_extension() const { // @@protoc_insertion_point(field_get:google.protobuf.UninterpretedOption.NamePart.is_extension) return is_extension_; } - void UninterpretedOption_NamePart::set_is_extension(bool value) { +void UninterpretedOption_NamePart::set_is_extension(bool value) { set_has_is_extension(); is_extension_ = value; // @@protoc_insertion_point(field_set:google.protobuf.UninterpretedOption.NamePart.is_extension) @@ -13638,37 +13749,37 @@ void UninterpretedOption::clear_identifier_value() { identifier_value_.ClearToEmptyNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); clear_has_identifier_value(); } - const ::std::string& UninterpretedOption::identifier_value() const { +const ::std::string& UninterpretedOption::identifier_value() const { // @@protoc_insertion_point(field_get:google.protobuf.UninterpretedOption.identifier_value) return identifier_value_.GetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); } - void UninterpretedOption::set_identifier_value(const ::std::string& value) { +void UninterpretedOption::set_identifier_value(const ::std::string& value) { set_has_identifier_value(); identifier_value_.SetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), value); // @@protoc_insertion_point(field_set:google.protobuf.UninterpretedOption.identifier_value) } - void UninterpretedOption::set_identifier_value(const char* value) { +void UninterpretedOption::set_identifier_value(const char* value) { set_has_identifier_value(); identifier_value_.SetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), ::std::string(value)); // @@protoc_insertion_point(field_set_char:google.protobuf.UninterpretedOption.identifier_value) } - void UninterpretedOption::set_identifier_value(const char* value, size_t size) { +void UninterpretedOption::set_identifier_value(const char* value, size_t size) { set_has_identifier_value(); identifier_value_.SetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), ::std::string(reinterpret_cast(value), size)); // @@protoc_insertion_point(field_set_pointer:google.protobuf.UninterpretedOption.identifier_value) } - ::std::string* UninterpretedOption::mutable_identifier_value() { +::std::string* UninterpretedOption::mutable_identifier_value() { set_has_identifier_value(); // @@protoc_insertion_point(field_mutable:google.protobuf.UninterpretedOption.identifier_value) return identifier_value_.MutableNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); } - ::std::string* UninterpretedOption::release_identifier_value() { +::std::string* UninterpretedOption::release_identifier_value() { // @@protoc_insertion_point(field_release:google.protobuf.UninterpretedOption.identifier_value) clear_has_identifier_value(); return identifier_value_.ReleaseNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); } - void UninterpretedOption::set_allocated_identifier_value(::std::string* identifier_value) { +void UninterpretedOption::set_allocated_identifier_value(::std::string* identifier_value) { if (identifier_value != NULL) { set_has_identifier_value(); } else { @@ -13692,11 +13803,11 @@ void UninterpretedOption::clear_positive_int_value() { positive_int_value_ = GOOGLE_ULONGLONG(0); clear_has_positive_int_value(); } - ::google::protobuf::uint64 UninterpretedOption::positive_int_value() const { +::google::protobuf::uint64 UninterpretedOption::positive_int_value() const { // @@protoc_insertion_point(field_get:google.protobuf.UninterpretedOption.positive_int_value) return positive_int_value_; } - void UninterpretedOption::set_positive_int_value(::google::protobuf::uint64 value) { +void UninterpretedOption::set_positive_int_value(::google::protobuf::uint64 value) { set_has_positive_int_value(); positive_int_value_ = value; // @@protoc_insertion_point(field_set:google.protobuf.UninterpretedOption.positive_int_value) @@ -13716,11 +13827,11 @@ void UninterpretedOption::clear_negative_int_value() { negative_int_value_ = GOOGLE_LONGLONG(0); clear_has_negative_int_value(); } - ::google::protobuf::int64 UninterpretedOption::negative_int_value() const { +::google::protobuf::int64 UninterpretedOption::negative_int_value() const { // @@protoc_insertion_point(field_get:google.protobuf.UninterpretedOption.negative_int_value) return negative_int_value_; } - void UninterpretedOption::set_negative_int_value(::google::protobuf::int64 value) { +void UninterpretedOption::set_negative_int_value(::google::protobuf::int64 value) { set_has_negative_int_value(); negative_int_value_ = value; // @@protoc_insertion_point(field_set:google.protobuf.UninterpretedOption.negative_int_value) @@ -13740,11 +13851,11 @@ void UninterpretedOption::clear_double_value() { double_value_ = 0; clear_has_double_value(); } - double UninterpretedOption::double_value() const { +double UninterpretedOption::double_value() const { // @@protoc_insertion_point(field_get:google.protobuf.UninterpretedOption.double_value) return double_value_; } - void UninterpretedOption::set_double_value(double value) { +void UninterpretedOption::set_double_value(double value) { set_has_double_value(); double_value_ = value; // @@protoc_insertion_point(field_set:google.protobuf.UninterpretedOption.double_value) @@ -13764,37 +13875,37 @@ void UninterpretedOption::clear_string_value() { string_value_.ClearToEmptyNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); clear_has_string_value(); } - const ::std::string& UninterpretedOption::string_value() const { +const ::std::string& UninterpretedOption::string_value() const { // @@protoc_insertion_point(field_get:google.protobuf.UninterpretedOption.string_value) return string_value_.GetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); } - void UninterpretedOption::set_string_value(const ::std::string& value) { +void UninterpretedOption::set_string_value(const ::std::string& value) { set_has_string_value(); string_value_.SetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), value); // @@protoc_insertion_point(field_set:google.protobuf.UninterpretedOption.string_value) } - void UninterpretedOption::set_string_value(const char* value) { +void UninterpretedOption::set_string_value(const char* value) { set_has_string_value(); string_value_.SetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), ::std::string(value)); // @@protoc_insertion_point(field_set_char:google.protobuf.UninterpretedOption.string_value) } - void UninterpretedOption::set_string_value(const void* value, size_t size) { +void UninterpretedOption::set_string_value(const void* value, size_t size) { set_has_string_value(); string_value_.SetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), ::std::string(reinterpret_cast(value), size)); // @@protoc_insertion_point(field_set_pointer:google.protobuf.UninterpretedOption.string_value) } - ::std::string* UninterpretedOption::mutable_string_value() { +::std::string* UninterpretedOption::mutable_string_value() { set_has_string_value(); // @@protoc_insertion_point(field_mutable:google.protobuf.UninterpretedOption.string_value) return string_value_.MutableNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); } - ::std::string* UninterpretedOption::release_string_value() { +::std::string* UninterpretedOption::release_string_value() { // @@protoc_insertion_point(field_release:google.protobuf.UninterpretedOption.string_value) clear_has_string_value(); return string_value_.ReleaseNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); } - void UninterpretedOption::set_allocated_string_value(::std::string* string_value) { +void UninterpretedOption::set_allocated_string_value(::std::string* string_value) { if (string_value != NULL) { set_has_string_value(); } else { @@ -13818,37 +13929,37 @@ void UninterpretedOption::clear_aggregate_value() { aggregate_value_.ClearToEmptyNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); clear_has_aggregate_value(); } - const ::std::string& UninterpretedOption::aggregate_value() const { +const ::std::string& UninterpretedOption::aggregate_value() const { // @@protoc_insertion_point(field_get:google.protobuf.UninterpretedOption.aggregate_value) return aggregate_value_.GetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); } - void UninterpretedOption::set_aggregate_value(const ::std::string& value) { +void UninterpretedOption::set_aggregate_value(const ::std::string& value) { set_has_aggregate_value(); aggregate_value_.SetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), value); // @@protoc_insertion_point(field_set:google.protobuf.UninterpretedOption.aggregate_value) } - void UninterpretedOption::set_aggregate_value(const char* value) { +void UninterpretedOption::set_aggregate_value(const char* value) { set_has_aggregate_value(); aggregate_value_.SetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), ::std::string(value)); // @@protoc_insertion_point(field_set_char:google.protobuf.UninterpretedOption.aggregate_value) } - void UninterpretedOption::set_aggregate_value(const char* value, size_t size) { +void UninterpretedOption::set_aggregate_value(const char* value, size_t size) { set_has_aggregate_value(); aggregate_value_.SetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), ::std::string(reinterpret_cast(value), size)); // @@protoc_insertion_point(field_set_pointer:google.protobuf.UninterpretedOption.aggregate_value) } - ::std::string* UninterpretedOption::mutable_aggregate_value() { +::std::string* UninterpretedOption::mutable_aggregate_value() { set_has_aggregate_value(); // @@protoc_insertion_point(field_mutable:google.protobuf.UninterpretedOption.aggregate_value) return aggregate_value_.MutableNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); } - ::std::string* UninterpretedOption::release_aggregate_value() { +::std::string* UninterpretedOption::release_aggregate_value() { // @@protoc_insertion_point(field_release:google.protobuf.UninterpretedOption.aggregate_value) clear_has_aggregate_value(); return aggregate_value_.ReleaseNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); } - void UninterpretedOption::set_allocated_aggregate_value(::std::string* aggregate_value) { +void UninterpretedOption::set_allocated_aggregate_value(::std::string* aggregate_value) { if (aggregate_value != NULL) { set_has_aggregate_value(); } else { @@ -13872,6 +13983,7 @@ const int SourceCodeInfo_Location::kLeadingDetachedCommentsFieldNumber; SourceCodeInfo_Location::SourceCodeInfo_Location() : ::google::protobuf::Message(), _internal_metadata_(NULL) { + if (this != internal_default_instance()) protobuf_InitDefaults_google_2fprotobuf_2fdescriptor_2eproto(); SharedCtor(); // @@protoc_insertion_point(constructor:google.protobuf.SourceCodeInfo.Location) } @@ -13883,16 +13995,14 @@ SourceCodeInfo_Location::SourceCodeInfo_Location(const SourceCodeInfo_Location& : ::google::protobuf::Message(), _internal_metadata_(NULL) { SharedCtor(); - MergeFrom(from); + UnsafeMergeFrom(from); // @@protoc_insertion_point(copy_constructor:google.protobuf.SourceCodeInfo.Location) } void SourceCodeInfo_Location::SharedCtor() { - ::google::protobuf::internal::GetEmptyString(); _cached_size_ = 0; leading_comments_.UnsafeSetDefault(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); trailing_comments_.UnsafeSetDefault(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); - ::memset(_has_bits_, 0, sizeof(_has_bits_)); } SourceCodeInfo_Location::~SourceCodeInfo_Location() { @@ -13903,8 +14013,6 @@ SourceCodeInfo_Location::~SourceCodeInfo_Location() { void SourceCodeInfo_Location::SharedDtor() { leading_comments_.DestroyNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); trailing_comments_.DestroyNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); - if (this != default_instance_) { - } } void SourceCodeInfo_Location::SetCachedSize(int size) const { @@ -13918,11 +14026,11 @@ const ::google::protobuf::Descriptor* SourceCodeInfo_Location::descriptor() { } const SourceCodeInfo_Location& SourceCodeInfo_Location::default_instance() { - if (default_instance_ == NULL) protobuf_AddDesc_google_2fprotobuf_2fdescriptor_2eproto(); - return *default_instance_; + protobuf_InitDefaults_google_2fprotobuf_2fdescriptor_2eproto(); + return *internal_default_instance(); } -SourceCodeInfo_Location* SourceCodeInfo_Location::default_instance_ = NULL; +::google::protobuf::internal::ExplicitlyConstructed SourceCodeInfo_Location::default_instance_; SourceCodeInfo_Location* SourceCodeInfo_Location::New(::google::protobuf::Arena* arena) const { SourceCodeInfo_Location* n = new SourceCodeInfo_Location; @@ -13945,7 +14053,7 @@ void SourceCodeInfo_Location::Clear() { path_.Clear(); span_.Clear(); leading_detached_comments_.Clear(); - ::memset(_has_bits_, 0, sizeof(_has_bits_)); + _has_bits_.Clear(); if (_internal_metadata_.have_unknown_fields()) { mutable_unknown_fields()->Clear(); } @@ -14203,9 +14311,9 @@ void SourceCodeInfo_Location::SerializeWithCachedSizes( return target; } -int SourceCodeInfo_Location::ByteSize() const { +size_t SourceCodeInfo_Location::ByteSizeLong() const { // @@protoc_insertion_point(message_byte_size_start:google.protobuf.SourceCodeInfo.Location) - int total_size = 0; + size_t total_size = 0; if (_has_bits_[2 / 32] & 12u) { // optional string leading_comments = 3; @@ -14225,8 +14333,9 @@ int SourceCodeInfo_Location::ByteSize() const { } // repeated int32 path = 1 [packed = true]; { - int data_size = 0; - for (int i = 0; i < this->path_size(); i++) { + size_t data_size = 0; + unsigned int count = this->path_size(); + for (unsigned int i = 0; i < count; i++) { data_size += ::google::protobuf::internal::WireFormatLite:: Int32Size(this->path(i)); } @@ -14234,16 +14343,18 @@ int SourceCodeInfo_Location::ByteSize() const { total_size += 1 + ::google::protobuf::internal::WireFormatLite::Int32Size(data_size); } + int cached_size = ::google::protobuf::internal::ToCachedSize(data_size); GOOGLE_SAFE_CONCURRENT_WRITES_BEGIN(); - _path_cached_byte_size_ = data_size; + _path_cached_byte_size_ = cached_size; GOOGLE_SAFE_CONCURRENT_WRITES_END(); total_size += data_size; } // repeated int32 span = 2 [packed = true]; { - int data_size = 0; - for (int i = 0; i < this->span_size(); i++) { + size_t data_size = 0; + unsigned int count = this->span_size(); + for (unsigned int i = 0; i < count; i++) { data_size += ::google::protobuf::internal::WireFormatLite:: Int32Size(this->span(i)); } @@ -14251,14 +14362,16 @@ int SourceCodeInfo_Location::ByteSize() const { total_size += 1 + ::google::protobuf::internal::WireFormatLite::Int32Size(data_size); } + int cached_size = ::google::protobuf::internal::ToCachedSize(data_size); GOOGLE_SAFE_CONCURRENT_WRITES_BEGIN(); - _span_cached_byte_size_ = data_size; + _span_cached_byte_size_ = cached_size; GOOGLE_SAFE_CONCURRENT_WRITES_END(); total_size += data_size; } // repeated string leading_detached_comments = 6; - total_size += 1 * this->leading_detached_comments_size(); + total_size += 1 * + ::google::protobuf::internal::FromIntSize(this->leading_detached_comments_size()); for (int i = 0; i < this->leading_detached_comments_size(); i++) { total_size += ::google::protobuf::internal::WireFormatLite::StringSize( this->leading_detached_comments(i)); @@ -14269,18 +14382,17 @@ int SourceCodeInfo_Location::ByteSize() const { ::google::protobuf::internal::WireFormat::ComputeUnknownFieldsSize( unknown_fields()); } + int cached_size = ::google::protobuf::internal::ToCachedSize(total_size); GOOGLE_SAFE_CONCURRENT_WRITES_BEGIN(); - _cached_size_ = total_size; + _cached_size_ = cached_size; GOOGLE_SAFE_CONCURRENT_WRITES_END(); return total_size; } void SourceCodeInfo_Location::MergeFrom(const ::google::protobuf::Message& from) { // @@protoc_insertion_point(generalized_merge_from_start:google.protobuf.SourceCodeInfo.Location) - if (GOOGLE_PREDICT_FALSE(&from == this)) { - ::google::protobuf::internal::MergeFromFail(__FILE__, __LINE__); - } - const SourceCodeInfo_Location* source = + if (GOOGLE_PREDICT_FALSE(&from == this)) MergeFromFail(__LINE__); + const SourceCodeInfo_Location* source = ::google::protobuf::internal::DynamicCastToGenerated( &from); if (source == NULL) { @@ -14288,18 +14400,24 @@ void SourceCodeInfo_Location::MergeFrom(const ::google::protobuf::Message& from) ::google::protobuf::internal::ReflectionOps::Merge(from, this); } else { // @@protoc_insertion_point(generalized_merge_from_cast_success:google.protobuf.SourceCodeInfo.Location) - MergeFrom(*source); + UnsafeMergeFrom(*source); } } void SourceCodeInfo_Location::MergeFrom(const SourceCodeInfo_Location& from) { // @@protoc_insertion_point(class_specific_merge_from_start:google.protobuf.SourceCodeInfo.Location) - if (GOOGLE_PREDICT_FALSE(&from == this)) { - ::google::protobuf::internal::MergeFromFail(__FILE__, __LINE__); + if (GOOGLE_PREDICT_TRUE(&from != this)) { + UnsafeMergeFrom(from); + } else { + MergeFromFail(__LINE__); } - path_.MergeFrom(from.path_); - span_.MergeFrom(from.span_); - leading_detached_comments_.MergeFrom(from.leading_detached_comments_); +} + +void SourceCodeInfo_Location::UnsafeMergeFrom(const SourceCodeInfo_Location& from) { + GOOGLE_DCHECK(&from != this); + path_.UnsafeMergeFrom(from.path_); + span_.UnsafeMergeFrom(from.span_); + leading_detached_comments_.UnsafeMergeFrom(from.leading_detached_comments_); if (from._has_bits_[2 / 32] & (0xffu << (2 % 32))) { if (from.has_leading_comments()) { set_has_leading_comments(); @@ -14311,7 +14429,8 @@ void SourceCodeInfo_Location::MergeFrom(const SourceCodeInfo_Location& from) { } } if (from._internal_metadata_.have_unknown_fields()) { - mutable_unknown_fields()->MergeFrom(from.unknown_fields()); + ::google::protobuf::UnknownFieldSet::MergeToInternalMetdata( + from.unknown_fields(), &_internal_metadata_); } } @@ -14326,7 +14445,7 @@ void SourceCodeInfo_Location::CopyFrom(const SourceCodeInfo_Location& from) { // @@protoc_insertion_point(class_specific_copy_from_start:google.protobuf.SourceCodeInfo.Location) if (&from == this) return; Clear(); - MergeFrom(from); + UnsafeMergeFrom(from); } bool SourceCodeInfo_Location::IsInitialized() const { @@ -14366,6 +14485,7 @@ const int SourceCodeInfo::kLocationFieldNumber; SourceCodeInfo::SourceCodeInfo() : ::google::protobuf::Message(), _internal_metadata_(NULL) { + if (this != internal_default_instance()) protobuf_InitDefaults_google_2fprotobuf_2fdescriptor_2eproto(); SharedCtor(); // @@protoc_insertion_point(constructor:google.protobuf.SourceCodeInfo) } @@ -14377,13 +14497,12 @@ SourceCodeInfo::SourceCodeInfo(const SourceCodeInfo& from) : ::google::protobuf::Message(), _internal_metadata_(NULL) { SharedCtor(); - MergeFrom(from); + UnsafeMergeFrom(from); // @@protoc_insertion_point(copy_constructor:google.protobuf.SourceCodeInfo) } void SourceCodeInfo::SharedCtor() { _cached_size_ = 0; - ::memset(_has_bits_, 0, sizeof(_has_bits_)); } SourceCodeInfo::~SourceCodeInfo() { @@ -14392,8 +14511,6 @@ SourceCodeInfo::~SourceCodeInfo() { } void SourceCodeInfo::SharedDtor() { - if (this != default_instance_) { - } } void SourceCodeInfo::SetCachedSize(int size) const { @@ -14407,11 +14524,11 @@ const ::google::protobuf::Descriptor* SourceCodeInfo::descriptor() { } const SourceCodeInfo& SourceCodeInfo::default_instance() { - if (default_instance_ == NULL) protobuf_AddDesc_google_2fprotobuf_2fdescriptor_2eproto(); - return *default_instance_; + protobuf_InitDefaults_google_2fprotobuf_2fdescriptor_2eproto(); + return *internal_default_instance(); } -SourceCodeInfo* SourceCodeInfo::default_instance_ = NULL; +::google::protobuf::internal::ExplicitlyConstructed SourceCodeInfo::default_instance_; SourceCodeInfo* SourceCodeInfo::New(::google::protobuf::Arena* arena) const { SourceCodeInfo* n = new SourceCodeInfo; @@ -14424,7 +14541,7 @@ SourceCodeInfo* SourceCodeInfo::New(::google::protobuf::Arena* arena) const { void SourceCodeInfo::Clear() { // @@protoc_insertion_point(message_clear_start:google.protobuf.SourceCodeInfo) location_.Clear(); - ::memset(_has_bits_, 0, sizeof(_has_bits_)); + _has_bits_.Clear(); if (_internal_metadata_.have_unknown_fields()) { mutable_unknown_fields()->Clear(); } @@ -14513,16 +14630,19 @@ void SourceCodeInfo::SerializeWithCachedSizes( return target; } -int SourceCodeInfo::ByteSize() const { +size_t SourceCodeInfo::ByteSizeLong() const { // @@protoc_insertion_point(message_byte_size_start:google.protobuf.SourceCodeInfo) - int total_size = 0; + size_t total_size = 0; // repeated .google.protobuf.SourceCodeInfo.Location location = 1; - total_size += 1 * this->location_size(); - for (int i = 0; i < this->location_size(); i++) { - total_size += - ::google::protobuf::internal::WireFormatLite::MessageSizeNoVirtual( - this->location(i)); + { + unsigned int count = this->location_size(); + total_size += 1UL * count; + for (unsigned int i = 0; i < count; i++) { + total_size += + ::google::protobuf::internal::WireFormatLite::MessageSizeNoVirtual( + this->location(i)); + } } if (_internal_metadata_.have_unknown_fields()) { @@ -14530,18 +14650,17 @@ int SourceCodeInfo::ByteSize() const { ::google::protobuf::internal::WireFormat::ComputeUnknownFieldsSize( unknown_fields()); } + int cached_size = ::google::protobuf::internal::ToCachedSize(total_size); GOOGLE_SAFE_CONCURRENT_WRITES_BEGIN(); - _cached_size_ = total_size; + _cached_size_ = cached_size; GOOGLE_SAFE_CONCURRENT_WRITES_END(); return total_size; } void SourceCodeInfo::MergeFrom(const ::google::protobuf::Message& from) { // @@protoc_insertion_point(generalized_merge_from_start:google.protobuf.SourceCodeInfo) - if (GOOGLE_PREDICT_FALSE(&from == this)) { - ::google::protobuf::internal::MergeFromFail(__FILE__, __LINE__); - } - const SourceCodeInfo* source = + if (GOOGLE_PREDICT_FALSE(&from == this)) MergeFromFail(__LINE__); + const SourceCodeInfo* source = ::google::protobuf::internal::DynamicCastToGenerated( &from); if (source == NULL) { @@ -14549,18 +14668,25 @@ void SourceCodeInfo::MergeFrom(const ::google::protobuf::Message& from) { ::google::protobuf::internal::ReflectionOps::Merge(from, this); } else { // @@protoc_insertion_point(generalized_merge_from_cast_success:google.protobuf.SourceCodeInfo) - MergeFrom(*source); + UnsafeMergeFrom(*source); } } void SourceCodeInfo::MergeFrom(const SourceCodeInfo& from) { // @@protoc_insertion_point(class_specific_merge_from_start:google.protobuf.SourceCodeInfo) - if (GOOGLE_PREDICT_FALSE(&from == this)) { - ::google::protobuf::internal::MergeFromFail(__FILE__, __LINE__); + if (GOOGLE_PREDICT_TRUE(&from != this)) { + UnsafeMergeFrom(from); + } else { + MergeFromFail(__LINE__); } +} + +void SourceCodeInfo::UnsafeMergeFrom(const SourceCodeInfo& from) { + GOOGLE_DCHECK(&from != this); location_.MergeFrom(from.location_); if (from._internal_metadata_.have_unknown_fields()) { - mutable_unknown_fields()->MergeFrom(from.unknown_fields()); + ::google::protobuf::UnknownFieldSet::MergeToInternalMetdata( + from.unknown_fields(), &_internal_metadata_); } } @@ -14575,7 +14701,7 @@ void SourceCodeInfo::CopyFrom(const SourceCodeInfo& from) { // @@protoc_insertion_point(class_specific_copy_from_start:google.protobuf.SourceCodeInfo) if (&from == this) return; Clear(); - MergeFrom(from); + UnsafeMergeFrom(from); } bool SourceCodeInfo::IsInitialized() const { @@ -14612,24 +14738,24 @@ int SourceCodeInfo_Location::path_size() const { void SourceCodeInfo_Location::clear_path() { path_.Clear(); } - ::google::protobuf::int32 SourceCodeInfo_Location::path(int index) const { +::google::protobuf::int32 SourceCodeInfo_Location::path(int index) const { // @@protoc_insertion_point(field_get:google.protobuf.SourceCodeInfo.Location.path) return path_.Get(index); } - void SourceCodeInfo_Location::set_path(int index, ::google::protobuf::int32 value) { +void SourceCodeInfo_Location::set_path(int index, ::google::protobuf::int32 value) { path_.Set(index, value); // @@protoc_insertion_point(field_set:google.protobuf.SourceCodeInfo.Location.path) } - void SourceCodeInfo_Location::add_path(::google::protobuf::int32 value) { +void SourceCodeInfo_Location::add_path(::google::protobuf::int32 value) { path_.Add(value); // @@protoc_insertion_point(field_add:google.protobuf.SourceCodeInfo.Location.path) } - const ::google::protobuf::RepeatedField< ::google::protobuf::int32 >& +const ::google::protobuf::RepeatedField< ::google::protobuf::int32 >& SourceCodeInfo_Location::path() const { // @@protoc_insertion_point(field_list:google.protobuf.SourceCodeInfo.Location.path) return path_; } - ::google::protobuf::RepeatedField< ::google::protobuf::int32 >* +::google::protobuf::RepeatedField< ::google::protobuf::int32 >* SourceCodeInfo_Location::mutable_path() { // @@protoc_insertion_point(field_mutable_list:google.protobuf.SourceCodeInfo.Location.path) return &path_; @@ -14642,24 +14768,24 @@ int SourceCodeInfo_Location::span_size() const { void SourceCodeInfo_Location::clear_span() { span_.Clear(); } - ::google::protobuf::int32 SourceCodeInfo_Location::span(int index) const { +::google::protobuf::int32 SourceCodeInfo_Location::span(int index) const { // @@protoc_insertion_point(field_get:google.protobuf.SourceCodeInfo.Location.span) return span_.Get(index); } - void SourceCodeInfo_Location::set_span(int index, ::google::protobuf::int32 value) { +void SourceCodeInfo_Location::set_span(int index, ::google::protobuf::int32 value) { span_.Set(index, value); // @@protoc_insertion_point(field_set:google.protobuf.SourceCodeInfo.Location.span) } - void SourceCodeInfo_Location::add_span(::google::protobuf::int32 value) { +void SourceCodeInfo_Location::add_span(::google::protobuf::int32 value) { span_.Add(value); // @@protoc_insertion_point(field_add:google.protobuf.SourceCodeInfo.Location.span) } - const ::google::protobuf::RepeatedField< ::google::protobuf::int32 >& +const ::google::protobuf::RepeatedField< ::google::protobuf::int32 >& SourceCodeInfo_Location::span() const { // @@protoc_insertion_point(field_list:google.protobuf.SourceCodeInfo.Location.span) return span_; } - ::google::protobuf::RepeatedField< ::google::protobuf::int32 >* +::google::protobuf::RepeatedField< ::google::protobuf::int32 >* SourceCodeInfo_Location::mutable_span() { // @@protoc_insertion_point(field_mutable_list:google.protobuf.SourceCodeInfo.Location.span) return &span_; @@ -14679,37 +14805,37 @@ void SourceCodeInfo_Location::clear_leading_comments() { leading_comments_.ClearToEmptyNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); clear_has_leading_comments(); } - const ::std::string& SourceCodeInfo_Location::leading_comments() const { +const ::std::string& SourceCodeInfo_Location::leading_comments() const { // @@protoc_insertion_point(field_get:google.protobuf.SourceCodeInfo.Location.leading_comments) return leading_comments_.GetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); } - void SourceCodeInfo_Location::set_leading_comments(const ::std::string& value) { +void SourceCodeInfo_Location::set_leading_comments(const ::std::string& value) { set_has_leading_comments(); leading_comments_.SetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), value); // @@protoc_insertion_point(field_set:google.protobuf.SourceCodeInfo.Location.leading_comments) } - void SourceCodeInfo_Location::set_leading_comments(const char* value) { +void SourceCodeInfo_Location::set_leading_comments(const char* value) { set_has_leading_comments(); leading_comments_.SetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), ::std::string(value)); // @@protoc_insertion_point(field_set_char:google.protobuf.SourceCodeInfo.Location.leading_comments) } - void SourceCodeInfo_Location::set_leading_comments(const char* value, size_t size) { +void SourceCodeInfo_Location::set_leading_comments(const char* value, size_t size) { set_has_leading_comments(); leading_comments_.SetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), ::std::string(reinterpret_cast(value), size)); // @@protoc_insertion_point(field_set_pointer:google.protobuf.SourceCodeInfo.Location.leading_comments) } - ::std::string* SourceCodeInfo_Location::mutable_leading_comments() { +::std::string* SourceCodeInfo_Location::mutable_leading_comments() { set_has_leading_comments(); // @@protoc_insertion_point(field_mutable:google.protobuf.SourceCodeInfo.Location.leading_comments) return leading_comments_.MutableNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); } - ::std::string* SourceCodeInfo_Location::release_leading_comments() { +::std::string* SourceCodeInfo_Location::release_leading_comments() { // @@protoc_insertion_point(field_release:google.protobuf.SourceCodeInfo.Location.leading_comments) clear_has_leading_comments(); return leading_comments_.ReleaseNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); } - void SourceCodeInfo_Location::set_allocated_leading_comments(::std::string* leading_comments) { +void SourceCodeInfo_Location::set_allocated_leading_comments(::std::string* leading_comments) { if (leading_comments != NULL) { set_has_leading_comments(); } else { @@ -14733,37 +14859,37 @@ void SourceCodeInfo_Location::clear_trailing_comments() { trailing_comments_.ClearToEmptyNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); clear_has_trailing_comments(); } - const ::std::string& SourceCodeInfo_Location::trailing_comments() const { +const ::std::string& SourceCodeInfo_Location::trailing_comments() const { // @@protoc_insertion_point(field_get:google.protobuf.SourceCodeInfo.Location.trailing_comments) return trailing_comments_.GetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); } - void SourceCodeInfo_Location::set_trailing_comments(const ::std::string& value) { +void SourceCodeInfo_Location::set_trailing_comments(const ::std::string& value) { set_has_trailing_comments(); trailing_comments_.SetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), value); // @@protoc_insertion_point(field_set:google.protobuf.SourceCodeInfo.Location.trailing_comments) } - void SourceCodeInfo_Location::set_trailing_comments(const char* value) { +void SourceCodeInfo_Location::set_trailing_comments(const char* value) { set_has_trailing_comments(); trailing_comments_.SetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), ::std::string(value)); // @@protoc_insertion_point(field_set_char:google.protobuf.SourceCodeInfo.Location.trailing_comments) } - void SourceCodeInfo_Location::set_trailing_comments(const char* value, size_t size) { +void SourceCodeInfo_Location::set_trailing_comments(const char* value, size_t size) { set_has_trailing_comments(); trailing_comments_.SetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), ::std::string(reinterpret_cast(value), size)); // @@protoc_insertion_point(field_set_pointer:google.protobuf.SourceCodeInfo.Location.trailing_comments) } - ::std::string* SourceCodeInfo_Location::mutable_trailing_comments() { +::std::string* SourceCodeInfo_Location::mutable_trailing_comments() { set_has_trailing_comments(); // @@protoc_insertion_point(field_mutable:google.protobuf.SourceCodeInfo.Location.trailing_comments) return trailing_comments_.MutableNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); } - ::std::string* SourceCodeInfo_Location::release_trailing_comments() { +::std::string* SourceCodeInfo_Location::release_trailing_comments() { // @@protoc_insertion_point(field_release:google.protobuf.SourceCodeInfo.Location.trailing_comments) clear_has_trailing_comments(); return trailing_comments_.ReleaseNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); } - void SourceCodeInfo_Location::set_allocated_trailing_comments(::std::string* trailing_comments) { +void SourceCodeInfo_Location::set_allocated_trailing_comments(::std::string* trailing_comments) { if (trailing_comments != NULL) { set_has_trailing_comments(); } else { @@ -14780,49 +14906,49 @@ int SourceCodeInfo_Location::leading_detached_comments_size() const { void SourceCodeInfo_Location::clear_leading_detached_comments() { leading_detached_comments_.Clear(); } - const ::std::string& SourceCodeInfo_Location::leading_detached_comments(int index) const { +const ::std::string& SourceCodeInfo_Location::leading_detached_comments(int index) const { // @@protoc_insertion_point(field_get:google.protobuf.SourceCodeInfo.Location.leading_detached_comments) return leading_detached_comments_.Get(index); } - ::std::string* SourceCodeInfo_Location::mutable_leading_detached_comments(int index) { +::std::string* SourceCodeInfo_Location::mutable_leading_detached_comments(int index) { // @@protoc_insertion_point(field_mutable:google.protobuf.SourceCodeInfo.Location.leading_detached_comments) return leading_detached_comments_.Mutable(index); } - void SourceCodeInfo_Location::set_leading_detached_comments(int index, const ::std::string& value) { +void SourceCodeInfo_Location::set_leading_detached_comments(int index, const ::std::string& value) { // @@protoc_insertion_point(field_set:google.protobuf.SourceCodeInfo.Location.leading_detached_comments) leading_detached_comments_.Mutable(index)->assign(value); } - void SourceCodeInfo_Location::set_leading_detached_comments(int index, const char* value) { +void SourceCodeInfo_Location::set_leading_detached_comments(int index, const char* value) { leading_detached_comments_.Mutable(index)->assign(value); // @@protoc_insertion_point(field_set_char:google.protobuf.SourceCodeInfo.Location.leading_detached_comments) } - void SourceCodeInfo_Location::set_leading_detached_comments(int index, const char* value, size_t size) { +void SourceCodeInfo_Location::set_leading_detached_comments(int index, const char* value, size_t size) { leading_detached_comments_.Mutable(index)->assign( reinterpret_cast(value), size); // @@protoc_insertion_point(field_set_pointer:google.protobuf.SourceCodeInfo.Location.leading_detached_comments) } - ::std::string* SourceCodeInfo_Location::add_leading_detached_comments() { +::std::string* SourceCodeInfo_Location::add_leading_detached_comments() { // @@protoc_insertion_point(field_add_mutable:google.protobuf.SourceCodeInfo.Location.leading_detached_comments) return leading_detached_comments_.Add(); } - void SourceCodeInfo_Location::add_leading_detached_comments(const ::std::string& value) { +void SourceCodeInfo_Location::add_leading_detached_comments(const ::std::string& value) { leading_detached_comments_.Add()->assign(value); // @@protoc_insertion_point(field_add:google.protobuf.SourceCodeInfo.Location.leading_detached_comments) } - void SourceCodeInfo_Location::add_leading_detached_comments(const char* value) { +void SourceCodeInfo_Location::add_leading_detached_comments(const char* value) { leading_detached_comments_.Add()->assign(value); // @@protoc_insertion_point(field_add_char:google.protobuf.SourceCodeInfo.Location.leading_detached_comments) } - void SourceCodeInfo_Location::add_leading_detached_comments(const char* value, size_t size) { +void SourceCodeInfo_Location::add_leading_detached_comments(const char* value, size_t size) { leading_detached_comments_.Add()->assign(reinterpret_cast(value), size); // @@protoc_insertion_point(field_add_pointer:google.protobuf.SourceCodeInfo.Location.leading_detached_comments) } - const ::google::protobuf::RepeatedPtrField< ::std::string>& +const ::google::protobuf::RepeatedPtrField< ::std::string>& SourceCodeInfo_Location::leading_detached_comments() const { // @@protoc_insertion_point(field_list:google.protobuf.SourceCodeInfo.Location.leading_detached_comments) return leading_detached_comments_; } - ::google::protobuf::RepeatedPtrField< ::std::string>* +::google::protobuf::RepeatedPtrField< ::std::string>* SourceCodeInfo_Location::mutable_leading_detached_comments() { // @@protoc_insertion_point(field_mutable_list:google.protobuf.SourceCodeInfo.Location.leading_detached_comments) return &leading_detached_comments_; @@ -14875,6 +15001,7 @@ const int GeneratedCodeInfo_Annotation::kEndFieldNumber; GeneratedCodeInfo_Annotation::GeneratedCodeInfo_Annotation() : ::google::protobuf::Message(), _internal_metadata_(NULL) { + if (this != internal_default_instance()) protobuf_InitDefaults_google_2fprotobuf_2fdescriptor_2eproto(); SharedCtor(); // @@protoc_insertion_point(constructor:google.protobuf.GeneratedCodeInfo.Annotation) } @@ -14886,17 +15013,15 @@ GeneratedCodeInfo_Annotation::GeneratedCodeInfo_Annotation(const GeneratedCodeIn : ::google::protobuf::Message(), _internal_metadata_(NULL) { SharedCtor(); - MergeFrom(from); + UnsafeMergeFrom(from); // @@protoc_insertion_point(copy_constructor:google.protobuf.GeneratedCodeInfo.Annotation) } void GeneratedCodeInfo_Annotation::SharedCtor() { - ::google::protobuf::internal::GetEmptyString(); _cached_size_ = 0; source_file_.UnsafeSetDefault(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); - begin_ = 0; - end_ = 0; - ::memset(_has_bits_, 0, sizeof(_has_bits_)); + ::memset(&begin_, 0, reinterpret_cast(&end_) - + reinterpret_cast(&begin_) + sizeof(end_)); } GeneratedCodeInfo_Annotation::~GeneratedCodeInfo_Annotation() { @@ -14906,8 +15031,6 @@ GeneratedCodeInfo_Annotation::~GeneratedCodeInfo_Annotation() { void GeneratedCodeInfo_Annotation::SharedDtor() { source_file_.DestroyNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); - if (this != default_instance_) { - } } void GeneratedCodeInfo_Annotation::SetCachedSize(int size) const { @@ -14921,11 +15044,11 @@ const ::google::protobuf::Descriptor* GeneratedCodeInfo_Annotation::descriptor() } const GeneratedCodeInfo_Annotation& GeneratedCodeInfo_Annotation::default_instance() { - if (default_instance_ == NULL) protobuf_AddDesc_google_2fprotobuf_2fdescriptor_2eproto(); - return *default_instance_; + protobuf_InitDefaults_google_2fprotobuf_2fdescriptor_2eproto(); + return *internal_default_instance(); } -GeneratedCodeInfo_Annotation* GeneratedCodeInfo_Annotation::default_instance_ = NULL; +::google::protobuf::internal::ExplicitlyConstructed GeneratedCodeInfo_Annotation::default_instance_; GeneratedCodeInfo_Annotation* GeneratedCodeInfo_Annotation::New(::google::protobuf::Arena* arena) const { GeneratedCodeInfo_Annotation* n = new GeneratedCodeInfo_Annotation; @@ -14964,7 +15087,7 @@ void GeneratedCodeInfo_Annotation::Clear() { #undef ZR_ path_.Clear(); - ::memset(_has_bits_, 0, sizeof(_has_bits_)); + _has_bits_.Clear(); if (_internal_metadata_.have_unknown_fields()) { mutable_unknown_fields()->Clear(); } @@ -15018,10 +15141,10 @@ bool GeneratedCodeInfo_Annotation::MergePartialFromCodedStream( case 3: { if (tag == 24) { parse_begin: + set_has_begin(); DO_((::google::protobuf::internal::WireFormatLite::ReadPrimitive< ::google::protobuf::int32, ::google::protobuf::internal::WireFormatLite::TYPE_INT32>( input, &begin_))); - set_has_begin(); } else { goto handle_unusual; } @@ -15033,10 +15156,10 @@ bool GeneratedCodeInfo_Annotation::MergePartialFromCodedStream( case 4: { if (tag == 32) { parse_end: + set_has_end(); DO_((::google::protobuf::internal::WireFormatLite::ReadPrimitive< ::google::protobuf::int32, ::google::protobuf::internal::WireFormatLite::TYPE_INT32>( input, &end_))); - set_has_end(); } else { goto handle_unusual; } @@ -15153,9 +15276,9 @@ void GeneratedCodeInfo_Annotation::SerializeWithCachedSizes( return target; } -int GeneratedCodeInfo_Annotation::ByteSize() const { +size_t GeneratedCodeInfo_Annotation::ByteSizeLong() const { // @@protoc_insertion_point(message_byte_size_start:google.protobuf.GeneratedCodeInfo.Annotation) - int total_size = 0; + size_t total_size = 0; if (_has_bits_[1 / 32] & 14u) { // optional string source_file = 2; @@ -15182,8 +15305,9 @@ int GeneratedCodeInfo_Annotation::ByteSize() const { } // repeated int32 path = 1 [packed = true]; { - int data_size = 0; - for (int i = 0; i < this->path_size(); i++) { + size_t data_size = 0; + unsigned int count = this->path_size(); + for (unsigned int i = 0; i < count; i++) { data_size += ::google::protobuf::internal::WireFormatLite:: Int32Size(this->path(i)); } @@ -15191,8 +15315,9 @@ int GeneratedCodeInfo_Annotation::ByteSize() const { total_size += 1 + ::google::protobuf::internal::WireFormatLite::Int32Size(data_size); } + int cached_size = ::google::protobuf::internal::ToCachedSize(data_size); GOOGLE_SAFE_CONCURRENT_WRITES_BEGIN(); - _path_cached_byte_size_ = data_size; + _path_cached_byte_size_ = cached_size; GOOGLE_SAFE_CONCURRENT_WRITES_END(); total_size += data_size; } @@ -15202,18 +15327,17 @@ int GeneratedCodeInfo_Annotation::ByteSize() const { ::google::protobuf::internal::WireFormat::ComputeUnknownFieldsSize( unknown_fields()); } + int cached_size = ::google::protobuf::internal::ToCachedSize(total_size); GOOGLE_SAFE_CONCURRENT_WRITES_BEGIN(); - _cached_size_ = total_size; + _cached_size_ = cached_size; GOOGLE_SAFE_CONCURRENT_WRITES_END(); return total_size; } void GeneratedCodeInfo_Annotation::MergeFrom(const ::google::protobuf::Message& from) { // @@protoc_insertion_point(generalized_merge_from_start:google.protobuf.GeneratedCodeInfo.Annotation) - if (GOOGLE_PREDICT_FALSE(&from == this)) { - ::google::protobuf::internal::MergeFromFail(__FILE__, __LINE__); - } - const GeneratedCodeInfo_Annotation* source = + if (GOOGLE_PREDICT_FALSE(&from == this)) MergeFromFail(__LINE__); + const GeneratedCodeInfo_Annotation* source = ::google::protobuf::internal::DynamicCastToGenerated( &from); if (source == NULL) { @@ -15221,16 +15345,22 @@ void GeneratedCodeInfo_Annotation::MergeFrom(const ::google::protobuf::Message& ::google::protobuf::internal::ReflectionOps::Merge(from, this); } else { // @@protoc_insertion_point(generalized_merge_from_cast_success:google.protobuf.GeneratedCodeInfo.Annotation) - MergeFrom(*source); + UnsafeMergeFrom(*source); } } void GeneratedCodeInfo_Annotation::MergeFrom(const GeneratedCodeInfo_Annotation& from) { // @@protoc_insertion_point(class_specific_merge_from_start:google.protobuf.GeneratedCodeInfo.Annotation) - if (GOOGLE_PREDICT_FALSE(&from == this)) { - ::google::protobuf::internal::MergeFromFail(__FILE__, __LINE__); + if (GOOGLE_PREDICT_TRUE(&from != this)) { + UnsafeMergeFrom(from); + } else { + MergeFromFail(__LINE__); } - path_.MergeFrom(from.path_); +} + +void GeneratedCodeInfo_Annotation::UnsafeMergeFrom(const GeneratedCodeInfo_Annotation& from) { + GOOGLE_DCHECK(&from != this); + path_.UnsafeMergeFrom(from.path_); if (from._has_bits_[1 / 32] & (0xffu << (1 % 32))) { if (from.has_source_file()) { set_has_source_file(); @@ -15244,7 +15374,8 @@ void GeneratedCodeInfo_Annotation::MergeFrom(const GeneratedCodeInfo_Annotation& } } if (from._internal_metadata_.have_unknown_fields()) { - mutable_unknown_fields()->MergeFrom(from.unknown_fields()); + ::google::protobuf::UnknownFieldSet::MergeToInternalMetdata( + from.unknown_fields(), &_internal_metadata_); } } @@ -15259,7 +15390,7 @@ void GeneratedCodeInfo_Annotation::CopyFrom(const GeneratedCodeInfo_Annotation& // @@protoc_insertion_point(class_specific_copy_from_start:google.protobuf.GeneratedCodeInfo.Annotation) if (&from == this) return; Clear(); - MergeFrom(from); + UnsafeMergeFrom(from); } bool GeneratedCodeInfo_Annotation::IsInitialized() const { @@ -15298,6 +15429,7 @@ const int GeneratedCodeInfo::kAnnotationFieldNumber; GeneratedCodeInfo::GeneratedCodeInfo() : ::google::protobuf::Message(), _internal_metadata_(NULL) { + if (this != internal_default_instance()) protobuf_InitDefaults_google_2fprotobuf_2fdescriptor_2eproto(); SharedCtor(); // @@protoc_insertion_point(constructor:google.protobuf.GeneratedCodeInfo) } @@ -15309,13 +15441,12 @@ GeneratedCodeInfo::GeneratedCodeInfo(const GeneratedCodeInfo& from) : ::google::protobuf::Message(), _internal_metadata_(NULL) { SharedCtor(); - MergeFrom(from); + UnsafeMergeFrom(from); // @@protoc_insertion_point(copy_constructor:google.protobuf.GeneratedCodeInfo) } void GeneratedCodeInfo::SharedCtor() { _cached_size_ = 0; - ::memset(_has_bits_, 0, sizeof(_has_bits_)); } GeneratedCodeInfo::~GeneratedCodeInfo() { @@ -15324,8 +15455,6 @@ GeneratedCodeInfo::~GeneratedCodeInfo() { } void GeneratedCodeInfo::SharedDtor() { - if (this != default_instance_) { - } } void GeneratedCodeInfo::SetCachedSize(int size) const { @@ -15339,11 +15468,11 @@ const ::google::protobuf::Descriptor* GeneratedCodeInfo::descriptor() { } const GeneratedCodeInfo& GeneratedCodeInfo::default_instance() { - if (default_instance_ == NULL) protobuf_AddDesc_google_2fprotobuf_2fdescriptor_2eproto(); - return *default_instance_; + protobuf_InitDefaults_google_2fprotobuf_2fdescriptor_2eproto(); + return *internal_default_instance(); } -GeneratedCodeInfo* GeneratedCodeInfo::default_instance_ = NULL; +::google::protobuf::internal::ExplicitlyConstructed GeneratedCodeInfo::default_instance_; GeneratedCodeInfo* GeneratedCodeInfo::New(::google::protobuf::Arena* arena) const { GeneratedCodeInfo* n = new GeneratedCodeInfo; @@ -15356,7 +15485,7 @@ GeneratedCodeInfo* GeneratedCodeInfo::New(::google::protobuf::Arena* arena) cons void GeneratedCodeInfo::Clear() { // @@protoc_insertion_point(message_clear_start:google.protobuf.GeneratedCodeInfo) annotation_.Clear(); - ::memset(_has_bits_, 0, sizeof(_has_bits_)); + _has_bits_.Clear(); if (_internal_metadata_.have_unknown_fields()) { mutable_unknown_fields()->Clear(); } @@ -15445,16 +15574,19 @@ void GeneratedCodeInfo::SerializeWithCachedSizes( return target; } -int GeneratedCodeInfo::ByteSize() const { +size_t GeneratedCodeInfo::ByteSizeLong() const { // @@protoc_insertion_point(message_byte_size_start:google.protobuf.GeneratedCodeInfo) - int total_size = 0; + size_t total_size = 0; // repeated .google.protobuf.GeneratedCodeInfo.Annotation annotation = 1; - total_size += 1 * this->annotation_size(); - for (int i = 0; i < this->annotation_size(); i++) { - total_size += - ::google::protobuf::internal::WireFormatLite::MessageSizeNoVirtual( - this->annotation(i)); + { + unsigned int count = this->annotation_size(); + total_size += 1UL * count; + for (unsigned int i = 0; i < count; i++) { + total_size += + ::google::protobuf::internal::WireFormatLite::MessageSizeNoVirtual( + this->annotation(i)); + } } if (_internal_metadata_.have_unknown_fields()) { @@ -15462,18 +15594,17 @@ int GeneratedCodeInfo::ByteSize() const { ::google::protobuf::internal::WireFormat::ComputeUnknownFieldsSize( unknown_fields()); } + int cached_size = ::google::protobuf::internal::ToCachedSize(total_size); GOOGLE_SAFE_CONCURRENT_WRITES_BEGIN(); - _cached_size_ = total_size; + _cached_size_ = cached_size; GOOGLE_SAFE_CONCURRENT_WRITES_END(); return total_size; } void GeneratedCodeInfo::MergeFrom(const ::google::protobuf::Message& from) { // @@protoc_insertion_point(generalized_merge_from_start:google.protobuf.GeneratedCodeInfo) - if (GOOGLE_PREDICT_FALSE(&from == this)) { - ::google::protobuf::internal::MergeFromFail(__FILE__, __LINE__); - } - const GeneratedCodeInfo* source = + if (GOOGLE_PREDICT_FALSE(&from == this)) MergeFromFail(__LINE__); + const GeneratedCodeInfo* source = ::google::protobuf::internal::DynamicCastToGenerated( &from); if (source == NULL) { @@ -15481,18 +15612,25 @@ void GeneratedCodeInfo::MergeFrom(const ::google::protobuf::Message& from) { ::google::protobuf::internal::ReflectionOps::Merge(from, this); } else { // @@protoc_insertion_point(generalized_merge_from_cast_success:google.protobuf.GeneratedCodeInfo) - MergeFrom(*source); + UnsafeMergeFrom(*source); } } void GeneratedCodeInfo::MergeFrom(const GeneratedCodeInfo& from) { // @@protoc_insertion_point(class_specific_merge_from_start:google.protobuf.GeneratedCodeInfo) - if (GOOGLE_PREDICT_FALSE(&from == this)) { - ::google::protobuf::internal::MergeFromFail(__FILE__, __LINE__); + if (GOOGLE_PREDICT_TRUE(&from != this)) { + UnsafeMergeFrom(from); + } else { + MergeFromFail(__LINE__); } +} + +void GeneratedCodeInfo::UnsafeMergeFrom(const GeneratedCodeInfo& from) { + GOOGLE_DCHECK(&from != this); annotation_.MergeFrom(from.annotation_); if (from._internal_metadata_.have_unknown_fields()) { - mutable_unknown_fields()->MergeFrom(from.unknown_fields()); + ::google::protobuf::UnknownFieldSet::MergeToInternalMetdata( + from.unknown_fields(), &_internal_metadata_); } } @@ -15507,7 +15645,7 @@ void GeneratedCodeInfo::CopyFrom(const GeneratedCodeInfo& from) { // @@protoc_insertion_point(class_specific_copy_from_start:google.protobuf.GeneratedCodeInfo) if (&from == this) return; Clear(); - MergeFrom(from); + UnsafeMergeFrom(from); } bool GeneratedCodeInfo::IsInitialized() const { @@ -15544,24 +15682,24 @@ int GeneratedCodeInfo_Annotation::path_size() const { void GeneratedCodeInfo_Annotation::clear_path() { path_.Clear(); } - ::google::protobuf::int32 GeneratedCodeInfo_Annotation::path(int index) const { +::google::protobuf::int32 GeneratedCodeInfo_Annotation::path(int index) const { // @@protoc_insertion_point(field_get:google.protobuf.GeneratedCodeInfo.Annotation.path) return path_.Get(index); } - void GeneratedCodeInfo_Annotation::set_path(int index, ::google::protobuf::int32 value) { +void GeneratedCodeInfo_Annotation::set_path(int index, ::google::protobuf::int32 value) { path_.Set(index, value); // @@protoc_insertion_point(field_set:google.protobuf.GeneratedCodeInfo.Annotation.path) } - void GeneratedCodeInfo_Annotation::add_path(::google::protobuf::int32 value) { +void GeneratedCodeInfo_Annotation::add_path(::google::protobuf::int32 value) { path_.Add(value); // @@protoc_insertion_point(field_add:google.protobuf.GeneratedCodeInfo.Annotation.path) } - const ::google::protobuf::RepeatedField< ::google::protobuf::int32 >& +const ::google::protobuf::RepeatedField< ::google::protobuf::int32 >& GeneratedCodeInfo_Annotation::path() const { // @@protoc_insertion_point(field_list:google.protobuf.GeneratedCodeInfo.Annotation.path) return path_; } - ::google::protobuf::RepeatedField< ::google::protobuf::int32 >* +::google::protobuf::RepeatedField< ::google::protobuf::int32 >* GeneratedCodeInfo_Annotation::mutable_path() { // @@protoc_insertion_point(field_mutable_list:google.protobuf.GeneratedCodeInfo.Annotation.path) return &path_; @@ -15581,37 +15719,37 @@ void GeneratedCodeInfo_Annotation::clear_source_file() { source_file_.ClearToEmptyNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); clear_has_source_file(); } - const ::std::string& GeneratedCodeInfo_Annotation::source_file() const { +const ::std::string& GeneratedCodeInfo_Annotation::source_file() const { // @@protoc_insertion_point(field_get:google.protobuf.GeneratedCodeInfo.Annotation.source_file) return source_file_.GetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); } - void GeneratedCodeInfo_Annotation::set_source_file(const ::std::string& value) { +void GeneratedCodeInfo_Annotation::set_source_file(const ::std::string& value) { set_has_source_file(); source_file_.SetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), value); // @@protoc_insertion_point(field_set:google.protobuf.GeneratedCodeInfo.Annotation.source_file) } - void GeneratedCodeInfo_Annotation::set_source_file(const char* value) { +void GeneratedCodeInfo_Annotation::set_source_file(const char* value) { set_has_source_file(); source_file_.SetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), ::std::string(value)); // @@protoc_insertion_point(field_set_char:google.protobuf.GeneratedCodeInfo.Annotation.source_file) } - void GeneratedCodeInfo_Annotation::set_source_file(const char* value, size_t size) { +void GeneratedCodeInfo_Annotation::set_source_file(const char* value, size_t size) { set_has_source_file(); source_file_.SetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), ::std::string(reinterpret_cast(value), size)); // @@protoc_insertion_point(field_set_pointer:google.protobuf.GeneratedCodeInfo.Annotation.source_file) } - ::std::string* GeneratedCodeInfo_Annotation::mutable_source_file() { +::std::string* GeneratedCodeInfo_Annotation::mutable_source_file() { set_has_source_file(); // @@protoc_insertion_point(field_mutable:google.protobuf.GeneratedCodeInfo.Annotation.source_file) return source_file_.MutableNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); } - ::std::string* GeneratedCodeInfo_Annotation::release_source_file() { +::std::string* GeneratedCodeInfo_Annotation::release_source_file() { // @@protoc_insertion_point(field_release:google.protobuf.GeneratedCodeInfo.Annotation.source_file) clear_has_source_file(); return source_file_.ReleaseNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); } - void GeneratedCodeInfo_Annotation::set_allocated_source_file(::std::string* source_file) { +void GeneratedCodeInfo_Annotation::set_allocated_source_file(::std::string* source_file) { if (source_file != NULL) { set_has_source_file(); } else { @@ -15635,11 +15773,11 @@ void GeneratedCodeInfo_Annotation::clear_begin() { begin_ = 0; clear_has_begin(); } - ::google::protobuf::int32 GeneratedCodeInfo_Annotation::begin() const { +::google::protobuf::int32 GeneratedCodeInfo_Annotation::begin() const { // @@protoc_insertion_point(field_get:google.protobuf.GeneratedCodeInfo.Annotation.begin) return begin_; } - void GeneratedCodeInfo_Annotation::set_begin(::google::protobuf::int32 value) { +void GeneratedCodeInfo_Annotation::set_begin(::google::protobuf::int32 value) { set_has_begin(); begin_ = value; // @@protoc_insertion_point(field_set:google.protobuf.GeneratedCodeInfo.Annotation.begin) @@ -15659,11 +15797,11 @@ void GeneratedCodeInfo_Annotation::clear_end() { end_ = 0; clear_has_end(); } - ::google::protobuf::int32 GeneratedCodeInfo_Annotation::end() const { +::google::protobuf::int32 GeneratedCodeInfo_Annotation::end() const { // @@protoc_insertion_point(field_get:google.protobuf.GeneratedCodeInfo.Annotation.end) return end_; } - void GeneratedCodeInfo_Annotation::set_end(::google::protobuf::int32 value) { +void GeneratedCodeInfo_Annotation::set_end(::google::protobuf::int32 value) { set_has_end(); end_ = value; // @@protoc_insertion_point(field_set:google.protobuf.GeneratedCodeInfo.Annotation.end) diff --git a/src/google/protobuf/descriptor.pb.h b/src/google/protobuf/descriptor.pb.h index f5f97f37..13f60520 100644 --- a/src/google/protobuf/descriptor.pb.h +++ b/src/google/protobuf/descriptor.pb.h @@ -35,6 +35,7 @@ namespace protobuf { // Internal implementation detail -- do not call these. void LIBPROTOBUF_EXPORT protobuf_AddDesc_google_2fprotobuf_2fdescriptor_2eproto(); +void LIBPROTOBUF_EXPORT protobuf_InitDefaults_google_2fprotobuf_2fdescriptor_2eproto(); void protobuf_AssignDesc_google_2fprotobuf_2fdescriptor_2eproto(); void protobuf_ShutdownFile_google_2fprotobuf_2fdescriptor_2eproto(); @@ -204,6 +205,10 @@ class LIBPROTOBUF_EXPORT FileDescriptorSet : public ::google::protobuf::Message static const ::google::protobuf::Descriptor* descriptor(); static const FileDescriptorSet& default_instance(); + static inline const FileDescriptorSet* internal_default_instance() { + return &default_instance_.get(); + } + void Swap(FileDescriptorSet* other); // implements Message ---------------------------------------------- @@ -218,7 +223,7 @@ class LIBPROTOBUF_EXPORT FileDescriptorSet : public ::google::protobuf::Message void Clear(); bool IsInitialized() const; - int ByteSize() const; + size_t ByteSizeLong() const; bool MergePartialFromCodedStream( ::google::protobuf::io::CodedInputStream* input); void SerializeWithCachedSizes( @@ -234,6 +239,7 @@ class LIBPROTOBUF_EXPORT FileDescriptorSet : public ::google::protobuf::Message void SharedDtor(); void SetCachedSize(int size) const; void InternalSwap(FileDescriptorSet* other); + void UnsafeMergeFrom(const FileDescriptorSet& from); private: inline ::google::protobuf::Arena* GetArenaNoVirtual() const { return _internal_metadata_.arena(); @@ -265,15 +271,16 @@ class LIBPROTOBUF_EXPORT FileDescriptorSet : public ::google::protobuf::Message private: ::google::protobuf::internal::InternalMetadataWithArena _internal_metadata_; - ::google::protobuf::uint32 _has_bits_[1]; + ::google::protobuf::internal::HasBits<1> _has_bits_; mutable int _cached_size_; ::google::protobuf::RepeatedPtrField< ::google::protobuf::FileDescriptorProto > file_; - friend void LIBPROTOBUF_EXPORT protobuf_AddDesc_google_2fprotobuf_2fdescriptor_2eproto(); + friend void LIBPROTOBUF_EXPORT protobuf_InitDefaults_google_2fprotobuf_2fdescriptor_2eproto_impl(); + friend void LIBPROTOBUF_EXPORT protobuf_AddDesc_google_2fprotobuf_2fdescriptor_2eproto_impl(); friend void protobuf_AssignDesc_google_2fprotobuf_2fdescriptor_2eproto(); friend void protobuf_ShutdownFile_google_2fprotobuf_2fdescriptor_2eproto(); void InitAsDefaultInstance(); - static FileDescriptorSet* default_instance_; + static ::google::protobuf::internal::ExplicitlyConstructed default_instance_; }; // ------------------------------------------------------------------- @@ -300,6 +307,10 @@ class LIBPROTOBUF_EXPORT FileDescriptorProto : public ::google::protobuf::Messag static const ::google::protobuf::Descriptor* descriptor(); static const FileDescriptorProto& default_instance(); + static inline const FileDescriptorProto* internal_default_instance() { + return &default_instance_.get(); + } + void Swap(FileDescriptorProto* other); // implements Message ---------------------------------------------- @@ -314,7 +325,7 @@ class LIBPROTOBUF_EXPORT FileDescriptorProto : public ::google::protobuf::Messag void Clear(); bool IsInitialized() const; - int ByteSize() const; + size_t ByteSizeLong() const; bool MergePartialFromCodedStream( ::google::protobuf::io::CodedInputStream* input); void SerializeWithCachedSizes( @@ -330,6 +341,7 @@ class LIBPROTOBUF_EXPORT FileDescriptorProto : public ::google::protobuf::Messag void SharedDtor(); void SetCachedSize(int size) const; void InternalSwap(FileDescriptorProto* other); + void UnsafeMergeFrom(const FileDescriptorProto& from); private: inline ::google::protobuf::Arena* GetArenaNoVirtual() const { return _internal_metadata_.arena(); @@ -501,10 +513,8 @@ class LIBPROTOBUF_EXPORT FileDescriptorProto : public ::google::protobuf::Messag inline void clear_has_syntax(); ::google::protobuf::internal::InternalMetadataWithArena _internal_metadata_; - ::google::protobuf::uint32 _has_bits_[1]; + ::google::protobuf::internal::HasBits<1> _has_bits_; mutable int _cached_size_; - ::google::protobuf::internal::ArenaStringPtr name_; - ::google::protobuf::internal::ArenaStringPtr package_; ::google::protobuf::RepeatedPtrField< ::std::string> dependency_; ::google::protobuf::RepeatedField< ::google::protobuf::int32 > public_dependency_; ::google::protobuf::RepeatedField< ::google::protobuf::int32 > weak_dependency_; @@ -512,15 +522,18 @@ class LIBPROTOBUF_EXPORT FileDescriptorProto : public ::google::protobuf::Messag ::google::protobuf::RepeatedPtrField< ::google::protobuf::EnumDescriptorProto > enum_type_; ::google::protobuf::RepeatedPtrField< ::google::protobuf::ServiceDescriptorProto > service_; ::google::protobuf::RepeatedPtrField< ::google::protobuf::FieldDescriptorProto > extension_; + ::google::protobuf::internal::ArenaStringPtr name_; + ::google::protobuf::internal::ArenaStringPtr package_; + ::google::protobuf::internal::ArenaStringPtr syntax_; ::google::protobuf::FileOptions* options_; ::google::protobuf::SourceCodeInfo* source_code_info_; - ::google::protobuf::internal::ArenaStringPtr syntax_; - friend void LIBPROTOBUF_EXPORT protobuf_AddDesc_google_2fprotobuf_2fdescriptor_2eproto(); + friend void LIBPROTOBUF_EXPORT protobuf_InitDefaults_google_2fprotobuf_2fdescriptor_2eproto_impl(); + friend void LIBPROTOBUF_EXPORT protobuf_AddDesc_google_2fprotobuf_2fdescriptor_2eproto_impl(); friend void protobuf_AssignDesc_google_2fprotobuf_2fdescriptor_2eproto(); friend void protobuf_ShutdownFile_google_2fprotobuf_2fdescriptor_2eproto(); void InitAsDefaultInstance(); - static FileDescriptorProto* default_instance_; + static ::google::protobuf::internal::ExplicitlyConstructed default_instance_; }; // ------------------------------------------------------------------- @@ -547,6 +560,10 @@ class LIBPROTOBUF_EXPORT DescriptorProto_ExtensionRange : public ::google::proto static const ::google::protobuf::Descriptor* descriptor(); static const DescriptorProto_ExtensionRange& default_instance(); + static inline const DescriptorProto_ExtensionRange* internal_default_instance() { + return &default_instance_.get(); + } + void Swap(DescriptorProto_ExtensionRange* other); // implements Message ---------------------------------------------- @@ -561,7 +578,7 @@ class LIBPROTOBUF_EXPORT DescriptorProto_ExtensionRange : public ::google::proto void Clear(); bool IsInitialized() const; - int ByteSize() const; + size_t ByteSizeLong() const; bool MergePartialFromCodedStream( ::google::protobuf::io::CodedInputStream* input); void SerializeWithCachedSizes( @@ -577,6 +594,7 @@ class LIBPROTOBUF_EXPORT DescriptorProto_ExtensionRange : public ::google::proto void SharedDtor(); void SetCachedSize(int size) const; void InternalSwap(DescriptorProto_ExtensionRange* other); + void UnsafeMergeFrom(const DescriptorProto_ExtensionRange& from); private: inline ::google::protobuf::Arena* GetArenaNoVirtual() const { return _internal_metadata_.arena(); @@ -614,16 +632,17 @@ class LIBPROTOBUF_EXPORT DescriptorProto_ExtensionRange : public ::google::proto inline void clear_has_end(); ::google::protobuf::internal::InternalMetadataWithArena _internal_metadata_; - ::google::protobuf::uint32 _has_bits_[1]; + ::google::protobuf::internal::HasBits<1> _has_bits_; mutable int _cached_size_; ::google::protobuf::int32 start_; ::google::protobuf::int32 end_; - friend void LIBPROTOBUF_EXPORT protobuf_AddDesc_google_2fprotobuf_2fdescriptor_2eproto(); + friend void LIBPROTOBUF_EXPORT protobuf_InitDefaults_google_2fprotobuf_2fdescriptor_2eproto_impl(); + friend void LIBPROTOBUF_EXPORT protobuf_AddDesc_google_2fprotobuf_2fdescriptor_2eproto_impl(); friend void protobuf_AssignDesc_google_2fprotobuf_2fdescriptor_2eproto(); friend void protobuf_ShutdownFile_google_2fprotobuf_2fdescriptor_2eproto(); void InitAsDefaultInstance(); - static DescriptorProto_ExtensionRange* default_instance_; + static ::google::protobuf::internal::ExplicitlyConstructed default_instance_; }; // ------------------------------------------------------------------- @@ -650,6 +669,10 @@ class LIBPROTOBUF_EXPORT DescriptorProto_ReservedRange : public ::google::protob static const ::google::protobuf::Descriptor* descriptor(); static const DescriptorProto_ReservedRange& default_instance(); + static inline const DescriptorProto_ReservedRange* internal_default_instance() { + return &default_instance_.get(); + } + void Swap(DescriptorProto_ReservedRange* other); // implements Message ---------------------------------------------- @@ -664,7 +687,7 @@ class LIBPROTOBUF_EXPORT DescriptorProto_ReservedRange : public ::google::protob void Clear(); bool IsInitialized() const; - int ByteSize() const; + size_t ByteSizeLong() const; bool MergePartialFromCodedStream( ::google::protobuf::io::CodedInputStream* input); void SerializeWithCachedSizes( @@ -680,6 +703,7 @@ class LIBPROTOBUF_EXPORT DescriptorProto_ReservedRange : public ::google::protob void SharedDtor(); void SetCachedSize(int size) const; void InternalSwap(DescriptorProto_ReservedRange* other); + void UnsafeMergeFrom(const DescriptorProto_ReservedRange& from); private: inline ::google::protobuf::Arena* GetArenaNoVirtual() const { return _internal_metadata_.arena(); @@ -717,16 +741,17 @@ class LIBPROTOBUF_EXPORT DescriptorProto_ReservedRange : public ::google::protob inline void clear_has_end(); ::google::protobuf::internal::InternalMetadataWithArena _internal_metadata_; - ::google::protobuf::uint32 _has_bits_[1]; + ::google::protobuf::internal::HasBits<1> _has_bits_; mutable int _cached_size_; ::google::protobuf::int32 start_; ::google::protobuf::int32 end_; - friend void LIBPROTOBUF_EXPORT protobuf_AddDesc_google_2fprotobuf_2fdescriptor_2eproto(); + friend void LIBPROTOBUF_EXPORT protobuf_InitDefaults_google_2fprotobuf_2fdescriptor_2eproto_impl(); + friend void LIBPROTOBUF_EXPORT protobuf_AddDesc_google_2fprotobuf_2fdescriptor_2eproto_impl(); friend void protobuf_AssignDesc_google_2fprotobuf_2fdescriptor_2eproto(); friend void protobuf_ShutdownFile_google_2fprotobuf_2fdescriptor_2eproto(); void InitAsDefaultInstance(); - static DescriptorProto_ReservedRange* default_instance_; + static ::google::protobuf::internal::ExplicitlyConstructed default_instance_; }; // ------------------------------------------------------------------- @@ -753,6 +778,10 @@ class LIBPROTOBUF_EXPORT DescriptorProto : public ::google::protobuf::Message /* static const ::google::protobuf::Descriptor* descriptor(); static const DescriptorProto& default_instance(); + static inline const DescriptorProto* internal_default_instance() { + return &default_instance_.get(); + } + void Swap(DescriptorProto* other); // implements Message ---------------------------------------------- @@ -767,7 +796,7 @@ class LIBPROTOBUF_EXPORT DescriptorProto : public ::google::protobuf::Message /* void Clear(); bool IsInitialized() const; - int ByteSize() const; + size_t ByteSizeLong() const; bool MergePartialFromCodedStream( ::google::protobuf::io::CodedInputStream* input); void SerializeWithCachedSizes( @@ -783,6 +812,7 @@ class LIBPROTOBUF_EXPORT DescriptorProto : public ::google::protobuf::Message /* void SharedDtor(); void SetCachedSize(int size) const; void InternalSwap(DescriptorProto* other); + void UnsafeMergeFrom(const DescriptorProto& from); private: inline ::google::protobuf::Arena* GetArenaNoVirtual() const { return _internal_metadata_.arena(); @@ -930,24 +960,25 @@ class LIBPROTOBUF_EXPORT DescriptorProto : public ::google::protobuf::Message /* inline void clear_has_options(); ::google::protobuf::internal::InternalMetadataWithArena _internal_metadata_; - ::google::protobuf::uint32 _has_bits_[1]; + ::google::protobuf::internal::HasBits<1> _has_bits_; mutable int _cached_size_; - ::google::protobuf::internal::ArenaStringPtr name_; ::google::protobuf::RepeatedPtrField< ::google::protobuf::FieldDescriptorProto > field_; ::google::protobuf::RepeatedPtrField< ::google::protobuf::FieldDescriptorProto > extension_; ::google::protobuf::RepeatedPtrField< ::google::protobuf::DescriptorProto > nested_type_; ::google::protobuf::RepeatedPtrField< ::google::protobuf::EnumDescriptorProto > enum_type_; ::google::protobuf::RepeatedPtrField< ::google::protobuf::DescriptorProto_ExtensionRange > extension_range_; ::google::protobuf::RepeatedPtrField< ::google::protobuf::OneofDescriptorProto > oneof_decl_; - ::google::protobuf::MessageOptions* options_; ::google::protobuf::RepeatedPtrField< ::google::protobuf::DescriptorProto_ReservedRange > reserved_range_; ::google::protobuf::RepeatedPtrField< ::std::string> reserved_name_; - friend void LIBPROTOBUF_EXPORT protobuf_AddDesc_google_2fprotobuf_2fdescriptor_2eproto(); + ::google::protobuf::internal::ArenaStringPtr name_; + ::google::protobuf::MessageOptions* options_; + friend void LIBPROTOBUF_EXPORT protobuf_InitDefaults_google_2fprotobuf_2fdescriptor_2eproto_impl(); + friend void LIBPROTOBUF_EXPORT protobuf_AddDesc_google_2fprotobuf_2fdescriptor_2eproto_impl(); friend void protobuf_AssignDesc_google_2fprotobuf_2fdescriptor_2eproto(); friend void protobuf_ShutdownFile_google_2fprotobuf_2fdescriptor_2eproto(); void InitAsDefaultInstance(); - static DescriptorProto* default_instance_; + static ::google::protobuf::internal::ExplicitlyConstructed default_instance_; }; // ------------------------------------------------------------------- @@ -974,6 +1005,10 @@ class LIBPROTOBUF_EXPORT FieldDescriptorProto : public ::google::protobuf::Messa static const ::google::protobuf::Descriptor* descriptor(); static const FieldDescriptorProto& default_instance(); + static inline const FieldDescriptorProto* internal_default_instance() { + return &default_instance_.get(); + } + void Swap(FieldDescriptorProto* other); // implements Message ---------------------------------------------- @@ -988,7 +1023,7 @@ class LIBPROTOBUF_EXPORT FieldDescriptorProto : public ::google::protobuf::Messa void Clear(); bool IsInitialized() const; - int ByteSize() const; + size_t ByteSizeLong() const; bool MergePartialFromCodedStream( ::google::protobuf::io::CodedInputStream* input); void SerializeWithCachedSizes( @@ -1004,6 +1039,7 @@ class LIBPROTOBUF_EXPORT FieldDescriptorProto : public ::google::protobuf::Messa void SharedDtor(); void SetCachedSize(int size) const; void InternalSwap(FieldDescriptorProto* other); + void UnsafeMergeFrom(const FieldDescriptorProto& from); private: inline ::google::protobuf::Arena* GetArenaNoVirtual() const { return _internal_metadata_.arena(); @@ -1226,24 +1262,25 @@ class LIBPROTOBUF_EXPORT FieldDescriptorProto : public ::google::protobuf::Messa inline void clear_has_options(); ::google::protobuf::internal::InternalMetadataWithArena _internal_metadata_; - ::google::protobuf::uint32 _has_bits_[1]; + ::google::protobuf::internal::HasBits<1> _has_bits_; mutable int _cached_size_; ::google::protobuf::internal::ArenaStringPtr name_; - ::google::protobuf::int32 number_; - int label_; ::google::protobuf::internal::ArenaStringPtr type_name_; ::google::protobuf::internal::ArenaStringPtr extendee_; - int type_; - ::google::protobuf::int32 oneof_index_; ::google::protobuf::internal::ArenaStringPtr default_value_; ::google::protobuf::internal::ArenaStringPtr json_name_; ::google::protobuf::FieldOptions* options_; - friend void LIBPROTOBUF_EXPORT protobuf_AddDesc_google_2fprotobuf_2fdescriptor_2eproto(); + ::google::protobuf::int32 number_; + ::google::protobuf::int32 oneof_index_; + int label_; + int type_; + friend void LIBPROTOBUF_EXPORT protobuf_InitDefaults_google_2fprotobuf_2fdescriptor_2eproto_impl(); + friend void LIBPROTOBUF_EXPORT protobuf_AddDesc_google_2fprotobuf_2fdescriptor_2eproto_impl(); friend void protobuf_AssignDesc_google_2fprotobuf_2fdescriptor_2eproto(); friend void protobuf_ShutdownFile_google_2fprotobuf_2fdescriptor_2eproto(); void InitAsDefaultInstance(); - static FieldDescriptorProto* default_instance_; + static ::google::protobuf::internal::ExplicitlyConstructed default_instance_; }; // ------------------------------------------------------------------- @@ -1270,6 +1307,10 @@ class LIBPROTOBUF_EXPORT OneofDescriptorProto : public ::google::protobuf::Messa static const ::google::protobuf::Descriptor* descriptor(); static const OneofDescriptorProto& default_instance(); + static inline const OneofDescriptorProto* internal_default_instance() { + return &default_instance_.get(); + } + void Swap(OneofDescriptorProto* other); // implements Message ---------------------------------------------- @@ -1284,7 +1325,7 @@ class LIBPROTOBUF_EXPORT OneofDescriptorProto : public ::google::protobuf::Messa void Clear(); bool IsInitialized() const; - int ByteSize() const; + size_t ByteSizeLong() const; bool MergePartialFromCodedStream( ::google::protobuf::io::CodedInputStream* input); void SerializeWithCachedSizes( @@ -1300,6 +1341,7 @@ class LIBPROTOBUF_EXPORT OneofDescriptorProto : public ::google::protobuf::Messa void SharedDtor(); void SetCachedSize(int size) const; void InternalSwap(OneofDescriptorProto* other); + void UnsafeMergeFrom(const OneofDescriptorProto& from); private: inline ::google::protobuf::Arena* GetArenaNoVirtual() const { return _internal_metadata_.arena(); @@ -1344,16 +1386,17 @@ class LIBPROTOBUF_EXPORT OneofDescriptorProto : public ::google::protobuf::Messa inline void clear_has_options(); ::google::protobuf::internal::InternalMetadataWithArena _internal_metadata_; - ::google::protobuf::uint32 _has_bits_[1]; + ::google::protobuf::internal::HasBits<1> _has_bits_; mutable int _cached_size_; ::google::protobuf::internal::ArenaStringPtr name_; ::google::protobuf::OneofOptions* options_; - friend void LIBPROTOBUF_EXPORT protobuf_AddDesc_google_2fprotobuf_2fdescriptor_2eproto(); + friend void LIBPROTOBUF_EXPORT protobuf_InitDefaults_google_2fprotobuf_2fdescriptor_2eproto_impl(); + friend void LIBPROTOBUF_EXPORT protobuf_AddDesc_google_2fprotobuf_2fdescriptor_2eproto_impl(); friend void protobuf_AssignDesc_google_2fprotobuf_2fdescriptor_2eproto(); friend void protobuf_ShutdownFile_google_2fprotobuf_2fdescriptor_2eproto(); void InitAsDefaultInstance(); - static OneofDescriptorProto* default_instance_; + static ::google::protobuf::internal::ExplicitlyConstructed default_instance_; }; // ------------------------------------------------------------------- @@ -1380,6 +1423,10 @@ class LIBPROTOBUF_EXPORT EnumDescriptorProto : public ::google::protobuf::Messag static const ::google::protobuf::Descriptor* descriptor(); static const EnumDescriptorProto& default_instance(); + static inline const EnumDescriptorProto* internal_default_instance() { + return &default_instance_.get(); + } + void Swap(EnumDescriptorProto* other); // implements Message ---------------------------------------------- @@ -1394,7 +1441,7 @@ class LIBPROTOBUF_EXPORT EnumDescriptorProto : public ::google::protobuf::Messag void Clear(); bool IsInitialized() const; - int ByteSize() const; + size_t ByteSizeLong() const; bool MergePartialFromCodedStream( ::google::protobuf::io::CodedInputStream* input); void SerializeWithCachedSizes( @@ -1410,6 +1457,7 @@ class LIBPROTOBUF_EXPORT EnumDescriptorProto : public ::google::protobuf::Messag void SharedDtor(); void SetCachedSize(int size) const; void InternalSwap(EnumDescriptorProto* other); + void UnsafeMergeFrom(const EnumDescriptorProto& from); private: inline ::google::protobuf::Arena* GetArenaNoVirtual() const { return _internal_metadata_.arena(); @@ -1466,17 +1514,18 @@ class LIBPROTOBUF_EXPORT EnumDescriptorProto : public ::google::protobuf::Messag inline void clear_has_options(); ::google::protobuf::internal::InternalMetadataWithArena _internal_metadata_; - ::google::protobuf::uint32 _has_bits_[1]; + ::google::protobuf::internal::HasBits<1> _has_bits_; mutable int _cached_size_; - ::google::protobuf::internal::ArenaStringPtr name_; ::google::protobuf::RepeatedPtrField< ::google::protobuf::EnumValueDescriptorProto > value_; + ::google::protobuf::internal::ArenaStringPtr name_; ::google::protobuf::EnumOptions* options_; - friend void LIBPROTOBUF_EXPORT protobuf_AddDesc_google_2fprotobuf_2fdescriptor_2eproto(); + friend void LIBPROTOBUF_EXPORT protobuf_InitDefaults_google_2fprotobuf_2fdescriptor_2eproto_impl(); + friend void LIBPROTOBUF_EXPORT protobuf_AddDesc_google_2fprotobuf_2fdescriptor_2eproto_impl(); friend void protobuf_AssignDesc_google_2fprotobuf_2fdescriptor_2eproto(); friend void protobuf_ShutdownFile_google_2fprotobuf_2fdescriptor_2eproto(); void InitAsDefaultInstance(); - static EnumDescriptorProto* default_instance_; + static ::google::protobuf::internal::ExplicitlyConstructed default_instance_; }; // ------------------------------------------------------------------- @@ -1503,6 +1552,10 @@ class LIBPROTOBUF_EXPORT EnumValueDescriptorProto : public ::google::protobuf::M static const ::google::protobuf::Descriptor* descriptor(); static const EnumValueDescriptorProto& default_instance(); + static inline const EnumValueDescriptorProto* internal_default_instance() { + return &default_instance_.get(); + } + void Swap(EnumValueDescriptorProto* other); // implements Message ---------------------------------------------- @@ -1517,7 +1570,7 @@ class LIBPROTOBUF_EXPORT EnumValueDescriptorProto : public ::google::protobuf::M void Clear(); bool IsInitialized() const; - int ByteSize() const; + size_t ByteSizeLong() const; bool MergePartialFromCodedStream( ::google::protobuf::io::CodedInputStream* input); void SerializeWithCachedSizes( @@ -1533,6 +1586,7 @@ class LIBPROTOBUF_EXPORT EnumValueDescriptorProto : public ::google::protobuf::M void SharedDtor(); void SetCachedSize(int size) const; void InternalSwap(EnumValueDescriptorProto* other); + void UnsafeMergeFrom(const EnumValueDescriptorProto& from); private: inline ::google::protobuf::Arena* GetArenaNoVirtual() const { return _internal_metadata_.arena(); @@ -1586,17 +1640,18 @@ class LIBPROTOBUF_EXPORT EnumValueDescriptorProto : public ::google::protobuf::M inline void clear_has_options(); ::google::protobuf::internal::InternalMetadataWithArena _internal_metadata_; - ::google::protobuf::uint32 _has_bits_[1]; + ::google::protobuf::internal::HasBits<1> _has_bits_; mutable int _cached_size_; ::google::protobuf::internal::ArenaStringPtr name_; ::google::protobuf::EnumValueOptions* options_; ::google::protobuf::int32 number_; - friend void LIBPROTOBUF_EXPORT protobuf_AddDesc_google_2fprotobuf_2fdescriptor_2eproto(); + friend void LIBPROTOBUF_EXPORT protobuf_InitDefaults_google_2fprotobuf_2fdescriptor_2eproto_impl(); + friend void LIBPROTOBUF_EXPORT protobuf_AddDesc_google_2fprotobuf_2fdescriptor_2eproto_impl(); friend void protobuf_AssignDesc_google_2fprotobuf_2fdescriptor_2eproto(); friend void protobuf_ShutdownFile_google_2fprotobuf_2fdescriptor_2eproto(); void InitAsDefaultInstance(); - static EnumValueDescriptorProto* default_instance_; + static ::google::protobuf::internal::ExplicitlyConstructed default_instance_; }; // ------------------------------------------------------------------- @@ -1623,6 +1678,10 @@ class LIBPROTOBUF_EXPORT ServiceDescriptorProto : public ::google::protobuf::Mes static const ::google::protobuf::Descriptor* descriptor(); static const ServiceDescriptorProto& default_instance(); + static inline const ServiceDescriptorProto* internal_default_instance() { + return &default_instance_.get(); + } + void Swap(ServiceDescriptorProto* other); // implements Message ---------------------------------------------- @@ -1637,7 +1696,7 @@ class LIBPROTOBUF_EXPORT ServiceDescriptorProto : public ::google::protobuf::Mes void Clear(); bool IsInitialized() const; - int ByteSize() const; + size_t ByteSizeLong() const; bool MergePartialFromCodedStream( ::google::protobuf::io::CodedInputStream* input); void SerializeWithCachedSizes( @@ -1653,6 +1712,7 @@ class LIBPROTOBUF_EXPORT ServiceDescriptorProto : public ::google::protobuf::Mes void SharedDtor(); void SetCachedSize(int size) const; void InternalSwap(ServiceDescriptorProto* other); + void UnsafeMergeFrom(const ServiceDescriptorProto& from); private: inline ::google::protobuf::Arena* GetArenaNoVirtual() const { return _internal_metadata_.arena(); @@ -1709,17 +1769,18 @@ class LIBPROTOBUF_EXPORT ServiceDescriptorProto : public ::google::protobuf::Mes inline void clear_has_options(); ::google::protobuf::internal::InternalMetadataWithArena _internal_metadata_; - ::google::protobuf::uint32 _has_bits_[1]; + ::google::protobuf::internal::HasBits<1> _has_bits_; mutable int _cached_size_; - ::google::protobuf::internal::ArenaStringPtr name_; ::google::protobuf::RepeatedPtrField< ::google::protobuf::MethodDescriptorProto > method_; + ::google::protobuf::internal::ArenaStringPtr name_; ::google::protobuf::ServiceOptions* options_; - friend void LIBPROTOBUF_EXPORT protobuf_AddDesc_google_2fprotobuf_2fdescriptor_2eproto(); + friend void LIBPROTOBUF_EXPORT protobuf_InitDefaults_google_2fprotobuf_2fdescriptor_2eproto_impl(); + friend void LIBPROTOBUF_EXPORT protobuf_AddDesc_google_2fprotobuf_2fdescriptor_2eproto_impl(); friend void protobuf_AssignDesc_google_2fprotobuf_2fdescriptor_2eproto(); friend void protobuf_ShutdownFile_google_2fprotobuf_2fdescriptor_2eproto(); void InitAsDefaultInstance(); - static ServiceDescriptorProto* default_instance_; + static ::google::protobuf::internal::ExplicitlyConstructed default_instance_; }; // ------------------------------------------------------------------- @@ -1746,6 +1807,10 @@ class LIBPROTOBUF_EXPORT MethodDescriptorProto : public ::google::protobuf::Mess static const ::google::protobuf::Descriptor* descriptor(); static const MethodDescriptorProto& default_instance(); + static inline const MethodDescriptorProto* internal_default_instance() { + return &default_instance_.get(); + } + void Swap(MethodDescriptorProto* other); // implements Message ---------------------------------------------- @@ -1760,7 +1825,7 @@ class LIBPROTOBUF_EXPORT MethodDescriptorProto : public ::google::protobuf::Mess void Clear(); bool IsInitialized() const; - int ByteSize() const; + size_t ByteSizeLong() const; bool MergePartialFromCodedStream( ::google::protobuf::io::CodedInputStream* input); void SerializeWithCachedSizes( @@ -1776,6 +1841,7 @@ class LIBPROTOBUF_EXPORT MethodDescriptorProto : public ::google::protobuf::Mess void SharedDtor(); void SetCachedSize(int size) const; void InternalSwap(MethodDescriptorProto* other); + void UnsafeMergeFrom(const MethodDescriptorProto& from); private: inline ::google::protobuf::Arena* GetArenaNoVirtual() const { return _internal_metadata_.arena(); @@ -1866,7 +1932,7 @@ class LIBPROTOBUF_EXPORT MethodDescriptorProto : public ::google::protobuf::Mess inline void clear_has_server_streaming(); ::google::protobuf::internal::InternalMetadataWithArena _internal_metadata_; - ::google::protobuf::uint32 _has_bits_[1]; + ::google::protobuf::internal::HasBits<1> _has_bits_; mutable int _cached_size_; ::google::protobuf::internal::ArenaStringPtr name_; ::google::protobuf::internal::ArenaStringPtr input_type_; @@ -1874,12 +1940,13 @@ class LIBPROTOBUF_EXPORT MethodDescriptorProto : public ::google::protobuf::Mess ::google::protobuf::MethodOptions* options_; bool client_streaming_; bool server_streaming_; - friend void LIBPROTOBUF_EXPORT protobuf_AddDesc_google_2fprotobuf_2fdescriptor_2eproto(); + friend void LIBPROTOBUF_EXPORT protobuf_InitDefaults_google_2fprotobuf_2fdescriptor_2eproto_impl(); + friend void LIBPROTOBUF_EXPORT protobuf_AddDesc_google_2fprotobuf_2fdescriptor_2eproto_impl(); friend void protobuf_AssignDesc_google_2fprotobuf_2fdescriptor_2eproto(); friend void protobuf_ShutdownFile_google_2fprotobuf_2fdescriptor_2eproto(); void InitAsDefaultInstance(); - static MethodDescriptorProto* default_instance_; + static ::google::protobuf::internal::ExplicitlyConstructed default_instance_; }; // ------------------------------------------------------------------- @@ -1906,6 +1973,10 @@ class LIBPROTOBUF_EXPORT FileOptions : public ::google::protobuf::Message /* @@p static const ::google::protobuf::Descriptor* descriptor(); static const FileOptions& default_instance(); + static inline const FileOptions* internal_default_instance() { + return &default_instance_.get(); + } + void Swap(FileOptions* other); // implements Message ---------------------------------------------- @@ -1920,7 +1991,7 @@ class LIBPROTOBUF_EXPORT FileOptions : public ::google::protobuf::Message /* @@p void Clear(); bool IsInitialized() const; - int ByteSize() const; + size_t ByteSizeLong() const; bool MergePartialFromCodedStream( ::google::protobuf::io::CodedInputStream* input); void SerializeWithCachedSizes( @@ -1936,6 +2007,7 @@ class LIBPROTOBUF_EXPORT FileOptions : public ::google::protobuf::Message /* @@p void SharedDtor(); void SetCachedSize(int size) const; void InternalSwap(FileOptions* other); + void UnsafeMergeFrom(const FileOptions& from); private: inline ::google::protobuf::Arena* GetArenaNoVirtual() const { return _internal_metadata_.arena(); @@ -2010,13 +2082,6 @@ class LIBPROTOBUF_EXPORT FileOptions : public ::google::protobuf::Message /* @@p bool java_multiple_files() const; void set_java_multiple_files(bool value); - // optional bool java_generate_equals_and_hash = 20 [default = false]; - bool has_java_generate_equals_and_hash() const; - void clear_java_generate_equals_and_hash(); - static const int kJavaGenerateEqualsAndHashFieldNumber = 20; - bool java_generate_equals_and_hash() const; - void set_java_generate_equals_and_hash(bool value); - // optional bool java_string_check_utf8 = 27 [default = false]; bool has_java_string_check_utf8() const; void clear_java_string_check_utf8(); @@ -2123,8 +2188,6 @@ class LIBPROTOBUF_EXPORT FileOptions : public ::google::protobuf::Message /* @@p inline void clear_has_java_outer_classname(); inline void set_has_java_multiple_files(); inline void clear_has_java_multiple_files(); - inline void set_has_java_generate_equals_and_hash(); - inline void clear_has_java_generate_equals_and_hash(); inline void set_has_java_string_check_utf8(); inline void clear_has_java_string_check_utf8(); inline void set_has_optimize_for(); @@ -2149,29 +2212,29 @@ class LIBPROTOBUF_EXPORT FileOptions : public ::google::protobuf::Message /* @@p ::google::protobuf::internal::ExtensionSet _extensions_; ::google::protobuf::internal::InternalMetadataWithArena _internal_metadata_; - ::google::protobuf::uint32 _has_bits_[1]; + ::google::protobuf::internal::HasBits<1> _has_bits_; mutable int _cached_size_; + ::google::protobuf::RepeatedPtrField< ::google::protobuf::UninterpretedOption > uninterpreted_option_; ::google::protobuf::internal::ArenaStringPtr java_package_; ::google::protobuf::internal::ArenaStringPtr java_outer_classname_; - bool java_multiple_files_; - bool java_generate_equals_and_hash_; - bool java_string_check_utf8_; - bool cc_generic_services_; - int optimize_for_; ::google::protobuf::internal::ArenaStringPtr go_package_; ::google::protobuf::internal::ArenaStringPtr objc_class_prefix_; ::google::protobuf::internal::ArenaStringPtr csharp_namespace_; - ::google::protobuf::RepeatedPtrField< ::google::protobuf::UninterpretedOption > uninterpreted_option_; + bool java_multiple_files_; + bool java_string_check_utf8_; + bool cc_generic_services_; bool java_generic_services_; bool py_generic_services_; bool deprecated_; bool cc_enable_arenas_; - friend void LIBPROTOBUF_EXPORT protobuf_AddDesc_google_2fprotobuf_2fdescriptor_2eproto(); + int optimize_for_; + friend void LIBPROTOBUF_EXPORT protobuf_InitDefaults_google_2fprotobuf_2fdescriptor_2eproto_impl(); + friend void LIBPROTOBUF_EXPORT protobuf_AddDesc_google_2fprotobuf_2fdescriptor_2eproto_impl(); friend void protobuf_AssignDesc_google_2fprotobuf_2fdescriptor_2eproto(); friend void protobuf_ShutdownFile_google_2fprotobuf_2fdescriptor_2eproto(); void InitAsDefaultInstance(); - static FileOptions* default_instance_; + static ::google::protobuf::internal::ExplicitlyConstructed default_instance_; }; // ------------------------------------------------------------------- @@ -2198,6 +2261,10 @@ class LIBPROTOBUF_EXPORT MessageOptions : public ::google::protobuf::Message /* static const ::google::protobuf::Descriptor* descriptor(); static const MessageOptions& default_instance(); + static inline const MessageOptions* internal_default_instance() { + return &default_instance_.get(); + } + void Swap(MessageOptions* other); // implements Message ---------------------------------------------- @@ -2212,7 +2279,7 @@ class LIBPROTOBUF_EXPORT MessageOptions : public ::google::protobuf::Message /* void Clear(); bool IsInitialized() const; - int ByteSize() const; + size_t ByteSizeLong() const; bool MergePartialFromCodedStream( ::google::protobuf::io::CodedInputStream* input); void SerializeWithCachedSizes( @@ -2228,6 +2295,7 @@ class LIBPROTOBUF_EXPORT MessageOptions : public ::google::protobuf::Message /* void SharedDtor(); void SetCachedSize(int size) const; void InternalSwap(MessageOptions* other); + void UnsafeMergeFrom(const MessageOptions& from); private: inline ::google::protobuf::Arena* GetArenaNoVirtual() const { return _internal_metadata_.arena(); @@ -2298,19 +2366,20 @@ class LIBPROTOBUF_EXPORT MessageOptions : public ::google::protobuf::Message /* ::google::protobuf::internal::ExtensionSet _extensions_; ::google::protobuf::internal::InternalMetadataWithArena _internal_metadata_; - ::google::protobuf::uint32 _has_bits_[1]; + ::google::protobuf::internal::HasBits<1> _has_bits_; mutable int _cached_size_; ::google::protobuf::RepeatedPtrField< ::google::protobuf::UninterpretedOption > uninterpreted_option_; bool message_set_wire_format_; bool no_standard_descriptor_accessor_; bool deprecated_; bool map_entry_; - friend void LIBPROTOBUF_EXPORT protobuf_AddDesc_google_2fprotobuf_2fdescriptor_2eproto(); + friend void LIBPROTOBUF_EXPORT protobuf_InitDefaults_google_2fprotobuf_2fdescriptor_2eproto_impl(); + friend void LIBPROTOBUF_EXPORT protobuf_AddDesc_google_2fprotobuf_2fdescriptor_2eproto_impl(); friend void protobuf_AssignDesc_google_2fprotobuf_2fdescriptor_2eproto(); friend void protobuf_ShutdownFile_google_2fprotobuf_2fdescriptor_2eproto(); void InitAsDefaultInstance(); - static MessageOptions* default_instance_; + static ::google::protobuf::internal::ExplicitlyConstructed default_instance_; }; // ------------------------------------------------------------------- @@ -2337,6 +2406,10 @@ class LIBPROTOBUF_EXPORT FieldOptions : public ::google::protobuf::Message /* @@ static const ::google::protobuf::Descriptor* descriptor(); static const FieldOptions& default_instance(); + static inline const FieldOptions* internal_default_instance() { + return &default_instance_.get(); + } + void Swap(FieldOptions* other); // implements Message ---------------------------------------------- @@ -2351,7 +2424,7 @@ class LIBPROTOBUF_EXPORT FieldOptions : public ::google::protobuf::Message /* @@ void Clear(); bool IsInitialized() const; - int ByteSize() const; + size_t ByteSizeLong() const; bool MergePartialFromCodedStream( ::google::protobuf::io::CodedInputStream* input); void SerializeWithCachedSizes( @@ -2367,6 +2440,7 @@ class LIBPROTOBUF_EXPORT FieldOptions : public ::google::protobuf::Message /* @@ void SharedDtor(); void SetCachedSize(int size) const; void InternalSwap(FieldOptions* other); + void UnsafeMergeFrom(const FieldOptions& from); private: inline ::google::protobuf::Arena* GetArenaNoVirtual() const { return _internal_metadata_.arena(); @@ -2511,21 +2585,22 @@ class LIBPROTOBUF_EXPORT FieldOptions : public ::google::protobuf::Message /* @@ ::google::protobuf::internal::ExtensionSet _extensions_; ::google::protobuf::internal::InternalMetadataWithArena _internal_metadata_; - ::google::protobuf::uint32 _has_bits_[1]; + ::google::protobuf::internal::HasBits<1> _has_bits_; mutable int _cached_size_; + ::google::protobuf::RepeatedPtrField< ::google::protobuf::UninterpretedOption > uninterpreted_option_; int ctype_; int jstype_; - ::google::protobuf::RepeatedPtrField< ::google::protobuf::UninterpretedOption > uninterpreted_option_; bool packed_; bool lazy_; bool deprecated_; bool weak_; - friend void LIBPROTOBUF_EXPORT protobuf_AddDesc_google_2fprotobuf_2fdescriptor_2eproto(); + friend void LIBPROTOBUF_EXPORT protobuf_InitDefaults_google_2fprotobuf_2fdescriptor_2eproto_impl(); + friend void LIBPROTOBUF_EXPORT protobuf_AddDesc_google_2fprotobuf_2fdescriptor_2eproto_impl(); friend void protobuf_AssignDesc_google_2fprotobuf_2fdescriptor_2eproto(); friend void protobuf_ShutdownFile_google_2fprotobuf_2fdescriptor_2eproto(); void InitAsDefaultInstance(); - static FieldOptions* default_instance_; + static ::google::protobuf::internal::ExplicitlyConstructed default_instance_; }; // ------------------------------------------------------------------- @@ -2552,6 +2627,10 @@ class LIBPROTOBUF_EXPORT OneofOptions : public ::google::protobuf::Message /* @@ static const ::google::protobuf::Descriptor* descriptor(); static const OneofOptions& default_instance(); + static inline const OneofOptions* internal_default_instance() { + return &default_instance_.get(); + } + void Swap(OneofOptions* other); // implements Message ---------------------------------------------- @@ -2566,7 +2645,7 @@ class LIBPROTOBUF_EXPORT OneofOptions : public ::google::protobuf::Message /* @@ void Clear(); bool IsInitialized() const; - int ByteSize() const; + size_t ByteSizeLong() const; bool MergePartialFromCodedStream( ::google::protobuf::io::CodedInputStream* input); void SerializeWithCachedSizes( @@ -2582,6 +2661,7 @@ class LIBPROTOBUF_EXPORT OneofOptions : public ::google::protobuf::Message /* @@ void SharedDtor(); void SetCachedSize(int size) const; void InternalSwap(OneofOptions* other); + void UnsafeMergeFrom(const OneofOptions& from); private: inline ::google::protobuf::Arena* GetArenaNoVirtual() const { return _internal_metadata_.arena(); @@ -2616,15 +2696,16 @@ class LIBPROTOBUF_EXPORT OneofOptions : public ::google::protobuf::Message /* @@ ::google::protobuf::internal::ExtensionSet _extensions_; ::google::protobuf::internal::InternalMetadataWithArena _internal_metadata_; - ::google::protobuf::uint32 _has_bits_[1]; + ::google::protobuf::internal::HasBits<1> _has_bits_; mutable int _cached_size_; ::google::protobuf::RepeatedPtrField< ::google::protobuf::UninterpretedOption > uninterpreted_option_; - friend void LIBPROTOBUF_EXPORT protobuf_AddDesc_google_2fprotobuf_2fdescriptor_2eproto(); + friend void LIBPROTOBUF_EXPORT protobuf_InitDefaults_google_2fprotobuf_2fdescriptor_2eproto_impl(); + friend void LIBPROTOBUF_EXPORT protobuf_AddDesc_google_2fprotobuf_2fdescriptor_2eproto_impl(); friend void protobuf_AssignDesc_google_2fprotobuf_2fdescriptor_2eproto(); friend void protobuf_ShutdownFile_google_2fprotobuf_2fdescriptor_2eproto(); void InitAsDefaultInstance(); - static OneofOptions* default_instance_; + static ::google::protobuf::internal::ExplicitlyConstructed default_instance_; }; // ------------------------------------------------------------------- @@ -2651,6 +2732,10 @@ class LIBPROTOBUF_EXPORT EnumOptions : public ::google::protobuf::Message /* @@p static const ::google::protobuf::Descriptor* descriptor(); static const EnumOptions& default_instance(); + static inline const EnumOptions* internal_default_instance() { + return &default_instance_.get(); + } + void Swap(EnumOptions* other); // implements Message ---------------------------------------------- @@ -2665,7 +2750,7 @@ class LIBPROTOBUF_EXPORT EnumOptions : public ::google::protobuf::Message /* @@p void Clear(); bool IsInitialized() const; - int ByteSize() const; + size_t ByteSizeLong() const; bool MergePartialFromCodedStream( ::google::protobuf::io::CodedInputStream* input); void SerializeWithCachedSizes( @@ -2681,6 +2766,7 @@ class LIBPROTOBUF_EXPORT EnumOptions : public ::google::protobuf::Message /* @@p void SharedDtor(); void SetCachedSize(int size) const; void InternalSwap(EnumOptions* other); + void UnsafeMergeFrom(const EnumOptions& from); private: inline ::google::protobuf::Arena* GetArenaNoVirtual() const { return _internal_metadata_.arena(); @@ -2733,17 +2819,18 @@ class LIBPROTOBUF_EXPORT EnumOptions : public ::google::protobuf::Message /* @@p ::google::protobuf::internal::ExtensionSet _extensions_; ::google::protobuf::internal::InternalMetadataWithArena _internal_metadata_; - ::google::protobuf::uint32 _has_bits_[1]; + ::google::protobuf::internal::HasBits<1> _has_bits_; mutable int _cached_size_; ::google::protobuf::RepeatedPtrField< ::google::protobuf::UninterpretedOption > uninterpreted_option_; bool allow_alias_; bool deprecated_; - friend void LIBPROTOBUF_EXPORT protobuf_AddDesc_google_2fprotobuf_2fdescriptor_2eproto(); + friend void LIBPROTOBUF_EXPORT protobuf_InitDefaults_google_2fprotobuf_2fdescriptor_2eproto_impl(); + friend void LIBPROTOBUF_EXPORT protobuf_AddDesc_google_2fprotobuf_2fdescriptor_2eproto_impl(); friend void protobuf_AssignDesc_google_2fprotobuf_2fdescriptor_2eproto(); friend void protobuf_ShutdownFile_google_2fprotobuf_2fdescriptor_2eproto(); void InitAsDefaultInstance(); - static EnumOptions* default_instance_; + static ::google::protobuf::internal::ExplicitlyConstructed default_instance_; }; // ------------------------------------------------------------------- @@ -2770,6 +2857,10 @@ class LIBPROTOBUF_EXPORT EnumValueOptions : public ::google::protobuf::Message / static const ::google::protobuf::Descriptor* descriptor(); static const EnumValueOptions& default_instance(); + static inline const EnumValueOptions* internal_default_instance() { + return &default_instance_.get(); + } + void Swap(EnumValueOptions* other); // implements Message ---------------------------------------------- @@ -2784,7 +2875,7 @@ class LIBPROTOBUF_EXPORT EnumValueOptions : public ::google::protobuf::Message / void Clear(); bool IsInitialized() const; - int ByteSize() const; + size_t ByteSizeLong() const; bool MergePartialFromCodedStream( ::google::protobuf::io::CodedInputStream* input); void SerializeWithCachedSizes( @@ -2800,6 +2891,7 @@ class LIBPROTOBUF_EXPORT EnumValueOptions : public ::google::protobuf::Message / void SharedDtor(); void SetCachedSize(int size) const; void InternalSwap(EnumValueOptions* other); + void UnsafeMergeFrom(const EnumValueOptions& from); private: inline ::google::protobuf::Arena* GetArenaNoVirtual() const { return _internal_metadata_.arena(); @@ -2843,16 +2935,17 @@ class LIBPROTOBUF_EXPORT EnumValueOptions : public ::google::protobuf::Message / ::google::protobuf::internal::ExtensionSet _extensions_; ::google::protobuf::internal::InternalMetadataWithArena _internal_metadata_; - ::google::protobuf::uint32 _has_bits_[1]; + ::google::protobuf::internal::HasBits<1> _has_bits_; mutable int _cached_size_; ::google::protobuf::RepeatedPtrField< ::google::protobuf::UninterpretedOption > uninterpreted_option_; bool deprecated_; - friend void LIBPROTOBUF_EXPORT protobuf_AddDesc_google_2fprotobuf_2fdescriptor_2eproto(); + friend void LIBPROTOBUF_EXPORT protobuf_InitDefaults_google_2fprotobuf_2fdescriptor_2eproto_impl(); + friend void LIBPROTOBUF_EXPORT protobuf_AddDesc_google_2fprotobuf_2fdescriptor_2eproto_impl(); friend void protobuf_AssignDesc_google_2fprotobuf_2fdescriptor_2eproto(); friend void protobuf_ShutdownFile_google_2fprotobuf_2fdescriptor_2eproto(); void InitAsDefaultInstance(); - static EnumValueOptions* default_instance_; + static ::google::protobuf::internal::ExplicitlyConstructed default_instance_; }; // ------------------------------------------------------------------- @@ -2879,6 +2972,10 @@ class LIBPROTOBUF_EXPORT ServiceOptions : public ::google::protobuf::Message /* static const ::google::protobuf::Descriptor* descriptor(); static const ServiceOptions& default_instance(); + static inline const ServiceOptions* internal_default_instance() { + return &default_instance_.get(); + } + void Swap(ServiceOptions* other); // implements Message ---------------------------------------------- @@ -2893,7 +2990,7 @@ class LIBPROTOBUF_EXPORT ServiceOptions : public ::google::protobuf::Message /* void Clear(); bool IsInitialized() const; - int ByteSize() const; + size_t ByteSizeLong() const; bool MergePartialFromCodedStream( ::google::protobuf::io::CodedInputStream* input); void SerializeWithCachedSizes( @@ -2909,6 +3006,7 @@ class LIBPROTOBUF_EXPORT ServiceOptions : public ::google::protobuf::Message /* void SharedDtor(); void SetCachedSize(int size) const; void InternalSwap(ServiceOptions* other); + void UnsafeMergeFrom(const ServiceOptions& from); private: inline ::google::protobuf::Arena* GetArenaNoVirtual() const { return _internal_metadata_.arena(); @@ -2952,16 +3050,17 @@ class LIBPROTOBUF_EXPORT ServiceOptions : public ::google::protobuf::Message /* ::google::protobuf::internal::ExtensionSet _extensions_; ::google::protobuf::internal::InternalMetadataWithArena _internal_metadata_; - ::google::protobuf::uint32 _has_bits_[1]; + ::google::protobuf::internal::HasBits<1> _has_bits_; mutable int _cached_size_; ::google::protobuf::RepeatedPtrField< ::google::protobuf::UninterpretedOption > uninterpreted_option_; bool deprecated_; - friend void LIBPROTOBUF_EXPORT protobuf_AddDesc_google_2fprotobuf_2fdescriptor_2eproto(); + friend void LIBPROTOBUF_EXPORT protobuf_InitDefaults_google_2fprotobuf_2fdescriptor_2eproto_impl(); + friend void LIBPROTOBUF_EXPORT protobuf_AddDesc_google_2fprotobuf_2fdescriptor_2eproto_impl(); friend void protobuf_AssignDesc_google_2fprotobuf_2fdescriptor_2eproto(); friend void protobuf_ShutdownFile_google_2fprotobuf_2fdescriptor_2eproto(); void InitAsDefaultInstance(); - static ServiceOptions* default_instance_; + static ::google::protobuf::internal::ExplicitlyConstructed default_instance_; }; // ------------------------------------------------------------------- @@ -2988,6 +3087,10 @@ class LIBPROTOBUF_EXPORT MethodOptions : public ::google::protobuf::Message /* @ static const ::google::protobuf::Descriptor* descriptor(); static const MethodOptions& default_instance(); + static inline const MethodOptions* internal_default_instance() { + return &default_instance_.get(); + } + void Swap(MethodOptions* other); // implements Message ---------------------------------------------- @@ -3002,7 +3105,7 @@ class LIBPROTOBUF_EXPORT MethodOptions : public ::google::protobuf::Message /* @ void Clear(); bool IsInitialized() const; - int ByteSize() const; + size_t ByteSizeLong() const; bool MergePartialFromCodedStream( ::google::protobuf::io::CodedInputStream* input); void SerializeWithCachedSizes( @@ -3018,6 +3121,7 @@ class LIBPROTOBUF_EXPORT MethodOptions : public ::google::protobuf::Message /* @ void SharedDtor(); void SetCachedSize(int size) const; void InternalSwap(MethodOptions* other); + void UnsafeMergeFrom(const MethodOptions& from); private: inline ::google::protobuf::Arena* GetArenaNoVirtual() const { return _internal_metadata_.arena(); @@ -3061,16 +3165,17 @@ class LIBPROTOBUF_EXPORT MethodOptions : public ::google::protobuf::Message /* @ ::google::protobuf::internal::ExtensionSet _extensions_; ::google::protobuf::internal::InternalMetadataWithArena _internal_metadata_; - ::google::protobuf::uint32 _has_bits_[1]; + ::google::protobuf::internal::HasBits<1> _has_bits_; mutable int _cached_size_; ::google::protobuf::RepeatedPtrField< ::google::protobuf::UninterpretedOption > uninterpreted_option_; bool deprecated_; - friend void LIBPROTOBUF_EXPORT protobuf_AddDesc_google_2fprotobuf_2fdescriptor_2eproto(); + friend void LIBPROTOBUF_EXPORT protobuf_InitDefaults_google_2fprotobuf_2fdescriptor_2eproto_impl(); + friend void LIBPROTOBUF_EXPORT protobuf_AddDesc_google_2fprotobuf_2fdescriptor_2eproto_impl(); friend void protobuf_AssignDesc_google_2fprotobuf_2fdescriptor_2eproto(); friend void protobuf_ShutdownFile_google_2fprotobuf_2fdescriptor_2eproto(); void InitAsDefaultInstance(); - static MethodOptions* default_instance_; + static ::google::protobuf::internal::ExplicitlyConstructed default_instance_; }; // ------------------------------------------------------------------- @@ -3097,6 +3202,10 @@ class LIBPROTOBUF_EXPORT UninterpretedOption_NamePart : public ::google::protobu static const ::google::protobuf::Descriptor* descriptor(); static const UninterpretedOption_NamePart& default_instance(); + static inline const UninterpretedOption_NamePart* internal_default_instance() { + return &default_instance_.get(); + } + void Swap(UninterpretedOption_NamePart* other); // implements Message ---------------------------------------------- @@ -3111,7 +3220,7 @@ class LIBPROTOBUF_EXPORT UninterpretedOption_NamePart : public ::google::protobu void Clear(); bool IsInitialized() const; - int ByteSize() const; + size_t ByteSizeLong() const; bool MergePartialFromCodedStream( ::google::protobuf::io::CodedInputStream* input); void SerializeWithCachedSizes( @@ -3127,6 +3236,7 @@ class LIBPROTOBUF_EXPORT UninterpretedOption_NamePart : public ::google::protobu void SharedDtor(); void SetCachedSize(int size) const; void InternalSwap(UninterpretedOption_NamePart* other); + void UnsafeMergeFrom(const UninterpretedOption_NamePart& from); private: inline ::google::protobuf::Arena* GetArenaNoVirtual() const { return _internal_metadata_.arena(); @@ -3168,20 +3278,21 @@ class LIBPROTOBUF_EXPORT UninterpretedOption_NamePart : public ::google::protobu inline void set_has_is_extension(); inline void clear_has_is_extension(); - // helper for ByteSize() - int RequiredFieldsByteSizeFallback() const; + // helper for ByteSizeLong() + size_t RequiredFieldsByteSizeFallback() const; ::google::protobuf::internal::InternalMetadataWithArena _internal_metadata_; - ::google::protobuf::uint32 _has_bits_[1]; + ::google::protobuf::internal::HasBits<1> _has_bits_; mutable int _cached_size_; ::google::protobuf::internal::ArenaStringPtr name_part_; bool is_extension_; - friend void LIBPROTOBUF_EXPORT protobuf_AddDesc_google_2fprotobuf_2fdescriptor_2eproto(); + friend void LIBPROTOBUF_EXPORT protobuf_InitDefaults_google_2fprotobuf_2fdescriptor_2eproto_impl(); + friend void LIBPROTOBUF_EXPORT protobuf_AddDesc_google_2fprotobuf_2fdescriptor_2eproto_impl(); friend void protobuf_AssignDesc_google_2fprotobuf_2fdescriptor_2eproto(); friend void protobuf_ShutdownFile_google_2fprotobuf_2fdescriptor_2eproto(); void InitAsDefaultInstance(); - static UninterpretedOption_NamePart* default_instance_; + static ::google::protobuf::internal::ExplicitlyConstructed default_instance_; }; // ------------------------------------------------------------------- @@ -3208,6 +3319,10 @@ class LIBPROTOBUF_EXPORT UninterpretedOption : public ::google::protobuf::Messag static const ::google::protobuf::Descriptor* descriptor(); static const UninterpretedOption& default_instance(); + static inline const UninterpretedOption* internal_default_instance() { + return &default_instance_.get(); + } + void Swap(UninterpretedOption* other); // implements Message ---------------------------------------------- @@ -3222,7 +3337,7 @@ class LIBPROTOBUF_EXPORT UninterpretedOption : public ::google::protobuf::Messag void Clear(); bool IsInitialized() const; - int ByteSize() const; + size_t ByteSizeLong() const; bool MergePartialFromCodedStream( ::google::protobuf::io::CodedInputStream* input); void SerializeWithCachedSizes( @@ -3238,6 +3353,7 @@ class LIBPROTOBUF_EXPORT UninterpretedOption : public ::google::protobuf::Messag void SharedDtor(); void SetCachedSize(int size) const; void InternalSwap(UninterpretedOption* other); + void UnsafeMergeFrom(const UninterpretedOption& from); private: inline ::google::protobuf::Arena* GetArenaNoVirtual() const { return _internal_metadata_.arena(); @@ -3340,21 +3456,22 @@ class LIBPROTOBUF_EXPORT UninterpretedOption : public ::google::protobuf::Messag inline void clear_has_aggregate_value(); ::google::protobuf::internal::InternalMetadataWithArena _internal_metadata_; - ::google::protobuf::uint32 _has_bits_[1]; + ::google::protobuf::internal::HasBits<1> _has_bits_; mutable int _cached_size_; ::google::protobuf::RepeatedPtrField< ::google::protobuf::UninterpretedOption_NamePart > name_; ::google::protobuf::internal::ArenaStringPtr identifier_value_; + ::google::protobuf::internal::ArenaStringPtr string_value_; + ::google::protobuf::internal::ArenaStringPtr aggregate_value_; ::google::protobuf::uint64 positive_int_value_; ::google::protobuf::int64 negative_int_value_; double double_value_; - ::google::protobuf::internal::ArenaStringPtr string_value_; - ::google::protobuf::internal::ArenaStringPtr aggregate_value_; - friend void LIBPROTOBUF_EXPORT protobuf_AddDesc_google_2fprotobuf_2fdescriptor_2eproto(); + friend void LIBPROTOBUF_EXPORT protobuf_InitDefaults_google_2fprotobuf_2fdescriptor_2eproto_impl(); + friend void LIBPROTOBUF_EXPORT protobuf_AddDesc_google_2fprotobuf_2fdescriptor_2eproto_impl(); friend void protobuf_AssignDesc_google_2fprotobuf_2fdescriptor_2eproto(); friend void protobuf_ShutdownFile_google_2fprotobuf_2fdescriptor_2eproto(); void InitAsDefaultInstance(); - static UninterpretedOption* default_instance_; + static ::google::protobuf::internal::ExplicitlyConstructed default_instance_; }; // ------------------------------------------------------------------- @@ -3381,6 +3498,10 @@ class LIBPROTOBUF_EXPORT SourceCodeInfo_Location : public ::google::protobuf::Me static const ::google::protobuf::Descriptor* descriptor(); static const SourceCodeInfo_Location& default_instance(); + static inline const SourceCodeInfo_Location* internal_default_instance() { + return &default_instance_.get(); + } + void Swap(SourceCodeInfo_Location* other); // implements Message ---------------------------------------------- @@ -3395,7 +3516,7 @@ class LIBPROTOBUF_EXPORT SourceCodeInfo_Location : public ::google::protobuf::Me void Clear(); bool IsInitialized() const; - int ByteSize() const; + size_t ByteSizeLong() const; bool MergePartialFromCodedStream( ::google::protobuf::io::CodedInputStream* input); void SerializeWithCachedSizes( @@ -3411,6 +3532,7 @@ class LIBPROTOBUF_EXPORT SourceCodeInfo_Location : public ::google::protobuf::Me void SharedDtor(); void SetCachedSize(int size) const; void InternalSwap(SourceCodeInfo_Location* other); + void UnsafeMergeFrom(const SourceCodeInfo_Location& from); private: inline ::google::protobuf::Arena* GetArenaNoVirtual() const { return _internal_metadata_.arena(); @@ -3498,21 +3620,22 @@ class LIBPROTOBUF_EXPORT SourceCodeInfo_Location : public ::google::protobuf::Me inline void clear_has_trailing_comments(); ::google::protobuf::internal::InternalMetadataWithArena _internal_metadata_; - ::google::protobuf::uint32 _has_bits_[1]; + ::google::protobuf::internal::HasBits<1> _has_bits_; mutable int _cached_size_; ::google::protobuf::RepeatedField< ::google::protobuf::int32 > path_; mutable int _path_cached_byte_size_; ::google::protobuf::RepeatedField< ::google::protobuf::int32 > span_; mutable int _span_cached_byte_size_; + ::google::protobuf::RepeatedPtrField< ::std::string> leading_detached_comments_; ::google::protobuf::internal::ArenaStringPtr leading_comments_; ::google::protobuf::internal::ArenaStringPtr trailing_comments_; - ::google::protobuf::RepeatedPtrField< ::std::string> leading_detached_comments_; - friend void LIBPROTOBUF_EXPORT protobuf_AddDesc_google_2fprotobuf_2fdescriptor_2eproto(); + friend void LIBPROTOBUF_EXPORT protobuf_InitDefaults_google_2fprotobuf_2fdescriptor_2eproto_impl(); + friend void LIBPROTOBUF_EXPORT protobuf_AddDesc_google_2fprotobuf_2fdescriptor_2eproto_impl(); friend void protobuf_AssignDesc_google_2fprotobuf_2fdescriptor_2eproto(); friend void protobuf_ShutdownFile_google_2fprotobuf_2fdescriptor_2eproto(); void InitAsDefaultInstance(); - static SourceCodeInfo_Location* default_instance_; + static ::google::protobuf::internal::ExplicitlyConstructed default_instance_; }; // ------------------------------------------------------------------- @@ -3539,6 +3662,10 @@ class LIBPROTOBUF_EXPORT SourceCodeInfo : public ::google::protobuf::Message /* static const ::google::protobuf::Descriptor* descriptor(); static const SourceCodeInfo& default_instance(); + static inline const SourceCodeInfo* internal_default_instance() { + return &default_instance_.get(); + } + void Swap(SourceCodeInfo* other); // implements Message ---------------------------------------------- @@ -3553,7 +3680,7 @@ class LIBPROTOBUF_EXPORT SourceCodeInfo : public ::google::protobuf::Message /* void Clear(); bool IsInitialized() const; - int ByteSize() const; + size_t ByteSizeLong() const; bool MergePartialFromCodedStream( ::google::protobuf::io::CodedInputStream* input); void SerializeWithCachedSizes( @@ -3569,6 +3696,7 @@ class LIBPROTOBUF_EXPORT SourceCodeInfo : public ::google::protobuf::Message /* void SharedDtor(); void SetCachedSize(int size) const; void InternalSwap(SourceCodeInfo* other); + void UnsafeMergeFrom(const SourceCodeInfo& from); private: inline ::google::protobuf::Arena* GetArenaNoVirtual() const { return _internal_metadata_.arena(); @@ -3602,15 +3730,16 @@ class LIBPROTOBUF_EXPORT SourceCodeInfo : public ::google::protobuf::Message /* private: ::google::protobuf::internal::InternalMetadataWithArena _internal_metadata_; - ::google::protobuf::uint32 _has_bits_[1]; + ::google::protobuf::internal::HasBits<1> _has_bits_; mutable int _cached_size_; ::google::protobuf::RepeatedPtrField< ::google::protobuf::SourceCodeInfo_Location > location_; - friend void LIBPROTOBUF_EXPORT protobuf_AddDesc_google_2fprotobuf_2fdescriptor_2eproto(); + friend void LIBPROTOBUF_EXPORT protobuf_InitDefaults_google_2fprotobuf_2fdescriptor_2eproto_impl(); + friend void LIBPROTOBUF_EXPORT protobuf_AddDesc_google_2fprotobuf_2fdescriptor_2eproto_impl(); friend void protobuf_AssignDesc_google_2fprotobuf_2fdescriptor_2eproto(); friend void protobuf_ShutdownFile_google_2fprotobuf_2fdescriptor_2eproto(); void InitAsDefaultInstance(); - static SourceCodeInfo* default_instance_; + static ::google::protobuf::internal::ExplicitlyConstructed default_instance_; }; // ------------------------------------------------------------------- @@ -3637,6 +3766,10 @@ class LIBPROTOBUF_EXPORT GeneratedCodeInfo_Annotation : public ::google::protobu static const ::google::protobuf::Descriptor* descriptor(); static const GeneratedCodeInfo_Annotation& default_instance(); + static inline const GeneratedCodeInfo_Annotation* internal_default_instance() { + return &default_instance_.get(); + } + void Swap(GeneratedCodeInfo_Annotation* other); // implements Message ---------------------------------------------- @@ -3651,7 +3784,7 @@ class LIBPROTOBUF_EXPORT GeneratedCodeInfo_Annotation : public ::google::protobu void Clear(); bool IsInitialized() const; - int ByteSize() const; + size_t ByteSizeLong() const; bool MergePartialFromCodedStream( ::google::protobuf::io::CodedInputStream* input); void SerializeWithCachedSizes( @@ -3667,6 +3800,7 @@ class LIBPROTOBUF_EXPORT GeneratedCodeInfo_Annotation : public ::google::protobu void SharedDtor(); void SetCachedSize(int size) const; void InternalSwap(GeneratedCodeInfo_Annotation* other); + void UnsafeMergeFrom(const GeneratedCodeInfo_Annotation& from); private: inline ::google::protobuf::Arena* GetArenaNoVirtual() const { return _internal_metadata_.arena(); @@ -3730,19 +3864,20 @@ class LIBPROTOBUF_EXPORT GeneratedCodeInfo_Annotation : public ::google::protobu inline void clear_has_end(); ::google::protobuf::internal::InternalMetadataWithArena _internal_metadata_; - ::google::protobuf::uint32 _has_bits_[1]; + ::google::protobuf::internal::HasBits<1> _has_bits_; mutable int _cached_size_; ::google::protobuf::RepeatedField< ::google::protobuf::int32 > path_; mutable int _path_cached_byte_size_; ::google::protobuf::internal::ArenaStringPtr source_file_; ::google::protobuf::int32 begin_; ::google::protobuf::int32 end_; - friend void LIBPROTOBUF_EXPORT protobuf_AddDesc_google_2fprotobuf_2fdescriptor_2eproto(); + friend void LIBPROTOBUF_EXPORT protobuf_InitDefaults_google_2fprotobuf_2fdescriptor_2eproto_impl(); + friend void LIBPROTOBUF_EXPORT protobuf_AddDesc_google_2fprotobuf_2fdescriptor_2eproto_impl(); friend void protobuf_AssignDesc_google_2fprotobuf_2fdescriptor_2eproto(); friend void protobuf_ShutdownFile_google_2fprotobuf_2fdescriptor_2eproto(); void InitAsDefaultInstance(); - static GeneratedCodeInfo_Annotation* default_instance_; + static ::google::protobuf::internal::ExplicitlyConstructed default_instance_; }; // ------------------------------------------------------------------- @@ -3769,6 +3904,10 @@ class LIBPROTOBUF_EXPORT GeneratedCodeInfo : public ::google::protobuf::Message static const ::google::protobuf::Descriptor* descriptor(); static const GeneratedCodeInfo& default_instance(); + static inline const GeneratedCodeInfo* internal_default_instance() { + return &default_instance_.get(); + } + void Swap(GeneratedCodeInfo* other); // implements Message ---------------------------------------------- @@ -3783,7 +3922,7 @@ class LIBPROTOBUF_EXPORT GeneratedCodeInfo : public ::google::protobuf::Message void Clear(); bool IsInitialized() const; - int ByteSize() const; + size_t ByteSizeLong() const; bool MergePartialFromCodedStream( ::google::protobuf::io::CodedInputStream* input); void SerializeWithCachedSizes( @@ -3799,6 +3938,7 @@ class LIBPROTOBUF_EXPORT GeneratedCodeInfo : public ::google::protobuf::Message void SharedDtor(); void SetCachedSize(int size) const; void InternalSwap(GeneratedCodeInfo* other); + void UnsafeMergeFrom(const GeneratedCodeInfo& from); private: inline ::google::protobuf::Arena* GetArenaNoVirtual() const { return _internal_metadata_.arena(); @@ -3832,15 +3972,16 @@ class LIBPROTOBUF_EXPORT GeneratedCodeInfo : public ::google::protobuf::Message private: ::google::protobuf::internal::InternalMetadataWithArena _internal_metadata_; - ::google::protobuf::uint32 _has_bits_[1]; + ::google::protobuf::internal::HasBits<1> _has_bits_; mutable int _cached_size_; ::google::protobuf::RepeatedPtrField< ::google::protobuf::GeneratedCodeInfo_Annotation > annotation_; - friend void LIBPROTOBUF_EXPORT protobuf_AddDesc_google_2fprotobuf_2fdescriptor_2eproto(); + friend void LIBPROTOBUF_EXPORT protobuf_InitDefaults_google_2fprotobuf_2fdescriptor_2eproto_impl(); + friend void LIBPROTOBUF_EXPORT protobuf_AddDesc_google_2fprotobuf_2fdescriptor_2eproto_impl(); friend void protobuf_AssignDesc_google_2fprotobuf_2fdescriptor_2eproto(); friend void protobuf_ShutdownFile_google_2fprotobuf_2fdescriptor_2eproto(); void InitAsDefaultInstance(); - static GeneratedCodeInfo* default_instance_; + static ::google::protobuf::internal::ExplicitlyConstructed default_instance_; }; // =================================================================== @@ -4243,7 +4384,8 @@ inline void FileDescriptorProto::clear_options() { } inline const ::google::protobuf::FileOptions& FileDescriptorProto::options() const { // @@protoc_insertion_point(field_get:google.protobuf.FileDescriptorProto.options) - return options_ != NULL ? *options_ : *default_instance_->options_; + return options_ != NULL ? *options_ + : *::google::protobuf::FileOptions::internal_default_instance(); } inline ::google::protobuf::FileOptions* FileDescriptorProto::mutable_options() { set_has_options(); @@ -4287,7 +4429,8 @@ inline void FileDescriptorProto::clear_source_code_info() { } inline const ::google::protobuf::SourceCodeInfo& FileDescriptorProto::source_code_info() const { // @@protoc_insertion_point(field_get:google.protobuf.FileDescriptorProto.source_code_info) - return source_code_info_ != NULL ? *source_code_info_ : *default_instance_->source_code_info_; + return source_code_info_ != NULL ? *source_code_info_ + : *::google::protobuf::SourceCodeInfo::internal_default_instance(); } inline ::google::protobuf::SourceCodeInfo* FileDescriptorProto::mutable_source_code_info() { set_has_source_code_info(); @@ -4727,7 +4870,8 @@ inline void DescriptorProto::clear_options() { } inline const ::google::protobuf::MessageOptions& DescriptorProto::options() const { // @@protoc_insertion_point(field_get:google.protobuf.DescriptorProto.options) - return options_ != NULL ? *options_ : *default_instance_->options_; + return options_ != NULL ? *options_ + : *::google::protobuf::MessageOptions::internal_default_instance(); } inline ::google::protobuf::MessageOptions* DescriptorProto::mutable_options() { set_has_options(); @@ -5228,7 +5372,8 @@ inline void FieldDescriptorProto::clear_options() { } inline const ::google::protobuf::FieldOptions& FieldDescriptorProto::options() const { // @@protoc_insertion_point(field_get:google.protobuf.FieldDescriptorProto.options) - return options_ != NULL ? *options_ : *default_instance_->options_; + return options_ != NULL ? *options_ + : *::google::protobuf::FieldOptions::internal_default_instance(); } inline ::google::protobuf::FieldOptions* FieldDescriptorProto::mutable_options() { set_has_options(); @@ -5330,7 +5475,8 @@ inline void OneofDescriptorProto::clear_options() { } inline const ::google::protobuf::OneofOptions& OneofDescriptorProto::options() const { // @@protoc_insertion_point(field_get:google.protobuf.OneofDescriptorProto.options) - return options_ != NULL ? *options_ : *default_instance_->options_; + return options_ != NULL ? *options_ + : *::google::protobuf::OneofOptions::internal_default_instance(); } inline ::google::protobuf::OneofOptions* OneofDescriptorProto::mutable_options() { set_has_options(); @@ -5462,7 +5608,8 @@ inline void EnumDescriptorProto::clear_options() { } inline const ::google::protobuf::EnumOptions& EnumDescriptorProto::options() const { // @@protoc_insertion_point(field_get:google.protobuf.EnumDescriptorProto.options) - return options_ != NULL ? *options_ : *default_instance_->options_; + return options_ != NULL ? *options_ + : *::google::protobuf::EnumOptions::internal_default_instance(); } inline ::google::protobuf::EnumOptions* EnumDescriptorProto::mutable_options() { set_has_options(); @@ -5588,7 +5735,8 @@ inline void EnumValueDescriptorProto::clear_options() { } inline const ::google::protobuf::EnumValueOptions& EnumValueDescriptorProto::options() const { // @@protoc_insertion_point(field_get:google.protobuf.EnumValueDescriptorProto.options) - return options_ != NULL ? *options_ : *default_instance_->options_; + return options_ != NULL ? *options_ + : *::google::protobuf::EnumValueOptions::internal_default_instance(); } inline ::google::protobuf::EnumValueOptions* EnumValueDescriptorProto::mutable_options() { set_has_options(); @@ -5720,7 +5868,8 @@ inline void ServiceDescriptorProto::clear_options() { } inline const ::google::protobuf::ServiceOptions& ServiceDescriptorProto::options() const { // @@protoc_insertion_point(field_get:google.protobuf.ServiceDescriptorProto.options) - return options_ != NULL ? *options_ : *default_instance_->options_; + return options_ != NULL ? *options_ + : *::google::protobuf::ServiceOptions::internal_default_instance(); } inline ::google::protobuf::ServiceOptions* ServiceDescriptorProto::mutable_options() { set_has_options(); @@ -5930,7 +6079,8 @@ inline void MethodDescriptorProto::clear_options() { } inline const ::google::protobuf::MethodOptions& MethodDescriptorProto::options() const { // @@protoc_insertion_point(field_get:google.protobuf.MethodDescriptorProto.options) - return options_ != NULL ? *options_ : *default_instance_->options_; + return options_ != NULL ? *options_ + : *::google::protobuf::MethodOptions::internal_default_instance(); } inline ::google::protobuf::MethodOptions* MethodDescriptorProto::mutable_options() { set_has_options(); @@ -6142,39 +6292,15 @@ inline void FileOptions::set_java_multiple_files(bool value) { // @@protoc_insertion_point(field_set:google.protobuf.FileOptions.java_multiple_files) } -// optional bool java_generate_equals_and_hash = 20 [default = false]; -inline bool FileOptions::has_java_generate_equals_and_hash() const { - return (_has_bits_[0] & 0x00000008u) != 0; -} -inline void FileOptions::set_has_java_generate_equals_and_hash() { - _has_bits_[0] |= 0x00000008u; -} -inline void FileOptions::clear_has_java_generate_equals_and_hash() { - _has_bits_[0] &= ~0x00000008u; -} -inline void FileOptions::clear_java_generate_equals_and_hash() { - java_generate_equals_and_hash_ = false; - clear_has_java_generate_equals_and_hash(); -} -inline bool FileOptions::java_generate_equals_and_hash() const { - // @@protoc_insertion_point(field_get:google.protobuf.FileOptions.java_generate_equals_and_hash) - return java_generate_equals_and_hash_; -} -inline void FileOptions::set_java_generate_equals_and_hash(bool value) { - set_has_java_generate_equals_and_hash(); - java_generate_equals_and_hash_ = value; - // @@protoc_insertion_point(field_set:google.protobuf.FileOptions.java_generate_equals_and_hash) -} - // optional bool java_string_check_utf8 = 27 [default = false]; inline bool FileOptions::has_java_string_check_utf8() const { - return (_has_bits_[0] & 0x00000010u) != 0; + return (_has_bits_[0] & 0x00000008u) != 0; } inline void FileOptions::set_has_java_string_check_utf8() { - _has_bits_[0] |= 0x00000010u; + _has_bits_[0] |= 0x00000008u; } inline void FileOptions::clear_has_java_string_check_utf8() { - _has_bits_[0] &= ~0x00000010u; + _has_bits_[0] &= ~0x00000008u; } inline void FileOptions::clear_java_string_check_utf8() { java_string_check_utf8_ = false; @@ -6192,13 +6318,13 @@ inline void FileOptions::set_java_string_check_utf8(bool value) { // optional .google.protobuf.FileOptions.OptimizeMode optimize_for = 9 [default = SPEED]; inline bool FileOptions::has_optimize_for() const { - return (_has_bits_[0] & 0x00000020u) != 0; + return (_has_bits_[0] & 0x00000010u) != 0; } inline void FileOptions::set_has_optimize_for() { - _has_bits_[0] |= 0x00000020u; + _has_bits_[0] |= 0x00000010u; } inline void FileOptions::clear_has_optimize_for() { - _has_bits_[0] &= ~0x00000020u; + _has_bits_[0] &= ~0x00000010u; } inline void FileOptions::clear_optimize_for() { optimize_for_ = 1; @@ -6217,13 +6343,13 @@ inline void FileOptions::set_optimize_for(::google::protobuf::FileOptions_Optimi // optional string go_package = 11; inline bool FileOptions::has_go_package() const { - return (_has_bits_[0] & 0x00000040u) != 0; + return (_has_bits_[0] & 0x00000020u) != 0; } inline void FileOptions::set_has_go_package() { - _has_bits_[0] |= 0x00000040u; + _has_bits_[0] |= 0x00000020u; } inline void FileOptions::clear_has_go_package() { - _has_bits_[0] &= ~0x00000040u; + _has_bits_[0] &= ~0x00000020u; } inline void FileOptions::clear_go_package() { go_package_.ClearToEmptyNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); @@ -6271,13 +6397,13 @@ inline void FileOptions::set_allocated_go_package(::std::string* go_package) { // optional bool cc_generic_services = 16 [default = false]; inline bool FileOptions::has_cc_generic_services() const { - return (_has_bits_[0] & 0x00000080u) != 0; + return (_has_bits_[0] & 0x00000040u) != 0; } inline void FileOptions::set_has_cc_generic_services() { - _has_bits_[0] |= 0x00000080u; + _has_bits_[0] |= 0x00000040u; } inline void FileOptions::clear_has_cc_generic_services() { - _has_bits_[0] &= ~0x00000080u; + _has_bits_[0] &= ~0x00000040u; } inline void FileOptions::clear_cc_generic_services() { cc_generic_services_ = false; @@ -6295,13 +6421,13 @@ inline void FileOptions::set_cc_generic_services(bool value) { // optional bool java_generic_services = 17 [default = false]; inline bool FileOptions::has_java_generic_services() const { - return (_has_bits_[0] & 0x00000100u) != 0; + return (_has_bits_[0] & 0x00000080u) != 0; } inline void FileOptions::set_has_java_generic_services() { - _has_bits_[0] |= 0x00000100u; + _has_bits_[0] |= 0x00000080u; } inline void FileOptions::clear_has_java_generic_services() { - _has_bits_[0] &= ~0x00000100u; + _has_bits_[0] &= ~0x00000080u; } inline void FileOptions::clear_java_generic_services() { java_generic_services_ = false; @@ -6319,13 +6445,13 @@ inline void FileOptions::set_java_generic_services(bool value) { // optional bool py_generic_services = 18 [default = false]; inline bool FileOptions::has_py_generic_services() const { - return (_has_bits_[0] & 0x00000200u) != 0; + return (_has_bits_[0] & 0x00000100u) != 0; } inline void FileOptions::set_has_py_generic_services() { - _has_bits_[0] |= 0x00000200u; + _has_bits_[0] |= 0x00000100u; } inline void FileOptions::clear_has_py_generic_services() { - _has_bits_[0] &= ~0x00000200u; + _has_bits_[0] &= ~0x00000100u; } inline void FileOptions::clear_py_generic_services() { py_generic_services_ = false; @@ -6343,13 +6469,13 @@ inline void FileOptions::set_py_generic_services(bool value) { // optional bool deprecated = 23 [default = false]; inline bool FileOptions::has_deprecated() const { - return (_has_bits_[0] & 0x00000400u) != 0; + return (_has_bits_[0] & 0x00000200u) != 0; } inline void FileOptions::set_has_deprecated() { - _has_bits_[0] |= 0x00000400u; + _has_bits_[0] |= 0x00000200u; } inline void FileOptions::clear_has_deprecated() { - _has_bits_[0] &= ~0x00000400u; + _has_bits_[0] &= ~0x00000200u; } inline void FileOptions::clear_deprecated() { deprecated_ = false; @@ -6367,13 +6493,13 @@ inline void FileOptions::set_deprecated(bool value) { // optional bool cc_enable_arenas = 31 [default = false]; inline bool FileOptions::has_cc_enable_arenas() const { - return (_has_bits_[0] & 0x00000800u) != 0; + return (_has_bits_[0] & 0x00000400u) != 0; } inline void FileOptions::set_has_cc_enable_arenas() { - _has_bits_[0] |= 0x00000800u; + _has_bits_[0] |= 0x00000400u; } inline void FileOptions::clear_has_cc_enable_arenas() { - _has_bits_[0] &= ~0x00000800u; + _has_bits_[0] &= ~0x00000400u; } inline void FileOptions::clear_cc_enable_arenas() { cc_enable_arenas_ = false; @@ -6391,13 +6517,13 @@ inline void FileOptions::set_cc_enable_arenas(bool value) { // optional string objc_class_prefix = 36; inline bool FileOptions::has_objc_class_prefix() const { - return (_has_bits_[0] & 0x00001000u) != 0; + return (_has_bits_[0] & 0x00000800u) != 0; } inline void FileOptions::set_has_objc_class_prefix() { - _has_bits_[0] |= 0x00001000u; + _has_bits_[0] |= 0x00000800u; } inline void FileOptions::clear_has_objc_class_prefix() { - _has_bits_[0] &= ~0x00001000u; + _has_bits_[0] &= ~0x00000800u; } inline void FileOptions::clear_objc_class_prefix() { objc_class_prefix_.ClearToEmptyNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); @@ -6445,13 +6571,13 @@ inline void FileOptions::set_allocated_objc_class_prefix(::std::string* objc_cla // optional string csharp_namespace = 37; inline bool FileOptions::has_csharp_namespace() const { - return (_has_bits_[0] & 0x00002000u) != 0; + return (_has_bits_[0] & 0x00001000u) != 0; } inline void FileOptions::set_has_csharp_namespace() { - _has_bits_[0] |= 0x00002000u; + _has_bits_[0] |= 0x00001000u; } inline void FileOptions::clear_has_csharp_namespace() { - _has_bits_[0] &= ~0x00002000u; + _has_bits_[0] &= ~0x00001000u; } inline void FileOptions::clear_csharp_namespace() { csharp_namespace_.ClearToEmptyNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); diff --git a/src/google/protobuf/descriptor.proto b/src/google/protobuf/descriptor.proto index 28410d4a..23a9fe92 100644 --- a/src/google/protobuf/descriptor.proto +++ b/src/google/protobuf/descriptor.proto @@ -45,7 +45,6 @@ option java_package = "com.google.protobuf"; option java_outer_classname = "DescriptorProtos"; option csharp_namespace = "Google.Protobuf.Reflection"; option objc_class_prefix = "GPB"; -option java_generate_equals_and_hash = true; // descriptor.proto must be optimized for speed because reflection-based // algorithms don't work during bootstrapping. @@ -306,19 +305,10 @@ message FileOptions { // top-level extensions defined in the file. optional bool java_multiple_files = 10 [default=false]; - // If set true, then the Java code generator will generate equals() and - // hashCode() methods for all messages defined in the .proto file. - // This increases generated code size, potentially substantially for large - // protos, which may harm a memory-constrained application. - // - In the full runtime this is a speed optimization, as the - // AbstractMessage base class includes reflection-based implementations of - // these methods. - // - In the lite runtime, setting this option changes the semantics of - // equals() and hashCode() to more closely match those of the full runtime; - // the generated methods compute their results based on field values rather - // than object identity. (Implementations should not assume that hashcodes - // will be consistent across runtimes or versions of the protocol compiler.) - optional bool java_generate_equals_and_hash = 20 [default=false]; + // BEGIN PROTOBUF-OPENSOURCE + // // This option does nothing. + // optional bool java_generate_equals_and_hash = 20 [deprecated=true]; + // END PROTOBUF-OPENSOURCE // If set true, then the Java2 code generator will generate code that // throws an exception whenever an attempt is made to assign a non-UTF-8 @@ -448,6 +438,8 @@ message MessageOptions { // Clients can define custom options in extensions of this message. See above. extensions 1000 to max; + + reserved 8; // javalite_serializable } message FieldOptions { @@ -471,7 +463,6 @@ message FieldOptions { // false will avoid using packed encoding. optional bool packed = 2; - // The jstype option determines the JavaScript type used for values of the // field. The option is permitted only for 64 bit integral and fixed types // (int64, uint64, sint64, fixed64, sfixed64). By default these types are @@ -512,7 +503,7 @@ message FieldOptions { // // // Note that implementations may choose not to check required fields within - // a lazy sub-message. That is, calling IsInitialized() on the outher message + // a lazy sub-message. That is, calling IsInitialized() on the outer message // may return true even if the inner message has missing required fields. // This is necessary because otherwise the inner message would have to be // parsed in order to perform the check, defeating the purpose of lazy @@ -538,6 +529,8 @@ message FieldOptions { // Clients can define custom options in extensions of this message. See above. extensions 1000 to max; + + reserved 4; // removed jtype } message OneofOptions { diff --git a/src/google/protobuf/descriptor_unittest.cc b/src/google/protobuf/descriptor_unittest.cc index 4183138f..07953416 100644 --- a/src/google/protobuf/descriptor_unittest.cc +++ b/src/google/protobuf/descriptor_unittest.cc @@ -773,9 +773,9 @@ TEST_F(DescriptorTest, FieldFullName) { TEST_F(DescriptorTest, FieldJsonName) { EXPECT_EQ("fieldName1", message4_->field(0)->json_name()); EXPECT_EQ("fieldName2", message4_->field(1)->json_name()); - EXPECT_EQ("fieldName3", message4_->field(2)->json_name()); - EXPECT_EQ("fieldName4", message4_->field(3)->json_name()); - EXPECT_EQ("fIELDNAME5", message4_->field(4)->json_name()); + EXPECT_EQ("FieldName3", message4_->field(2)->json_name()); + EXPECT_EQ("FieldName4", message4_->field(3)->json_name()); + EXPECT_EQ("FIELDNAME5", message4_->field(4)->json_name()); EXPECT_EQ("@type", message4_->field(5)->json_name()); DescriptorProto proto; @@ -793,10 +793,20 @@ TEST_F(DescriptorTest, FieldJsonName) { ASSERT_EQ(6, proto.field_size()); EXPECT_EQ("fieldName1", proto.field(0).json_name()); EXPECT_EQ("fieldName2", proto.field(1).json_name()); - EXPECT_EQ("fieldName3", proto.field(2).json_name()); - EXPECT_EQ("fieldName4", proto.field(3).json_name()); - EXPECT_EQ("fIELDNAME5", proto.field(4).json_name()); + EXPECT_EQ("FieldName3", proto.field(2).json_name()); + EXPECT_EQ("FieldName4", proto.field(3).json_name()); + EXPECT_EQ("FIELDNAME5", proto.field(4).json_name()); EXPECT_EQ("@type", proto.field(5).json_name()); + + // Test generated descriptor. + const Descriptor* generated = protobuf_unittest::TestJsonName::descriptor(); + ASSERT_EQ(6, generated->field_count()); + EXPECT_EQ("fieldName1", generated->field(0)->json_name()); + EXPECT_EQ("fieldName2", generated->field(1)->json_name()); + EXPECT_EQ("FieldName3", generated->field(2)->json_name()); + EXPECT_EQ("FieldName4", generated->field(3)->json_name()); + EXPECT_EQ("FIELDNAME5", generated->field(4)->json_name()); + EXPECT_EQ("@type", generated->field(5)->json_name()); } TEST_F(DescriptorTest, FieldFile) { @@ -5553,6 +5563,60 @@ TEST_F(ValidationErrorTest, MapEntryConflictsWithEnum) { "with an existing enum type.\n"); } +TEST_F(ValidationErrorTest, EnumValuesConflictWhenPrefixesStripped) { + BuildFileWithErrors( + "name: 'foo.proto' " + "enum_type {" + " name: 'FooEnum' " + " value { name: 'FOO_ENUM_BAZ' number: 0 }" + " value { name: 'BAZ' number: 1 }" + "}", + "foo.proto: BAZ: NAME: When enum name is stripped and label is " + "PascalCased (Baz), this value label conflicts with FOO_ENUM_BAZ\n"); + + BuildFileWithErrors( + "name: 'foo.proto' " + "enum_type {" + " name: 'FooEnum' " + " value { name: 'FOOENUM_BAZ' number: 0 }" + " value { name: 'BAZ' number: 1 }" + "}", + "foo.proto: BAZ: NAME: When enum name is stripped and label is " + "PascalCased (Baz), this value label conflicts with FOOENUM_BAZ\n"); + + BuildFileWithErrors( + "name: 'foo.proto' " + "enum_type {" + " name: 'FooEnum' " + " value { name: 'FOO_ENUM_BAR_BAZ' number: 0 }" + " value { name: 'BAR__BAZ' number: 1 }" + "}", + "foo.proto: BAR__BAZ: NAME: When enum name is stripped and label is " + "PascalCased (BarBaz), this value label conflicts with " + "FOO_ENUM_BAR_BAZ\n"); + + BuildFileWithErrors( + "name: 'foo.proto' " + "enum_type {" + " name: 'FooEnum' " + " value { name: 'FOO_ENUM__BAR_BAZ' number: 0 }" + " value { name: 'BAR_BAZ' number: 1 }" + "}", + "foo.proto: BAR_BAZ: NAME: When enum name is stripped and label is " + "PascalCased (BarBaz), this value label conflicts with " + "FOO_ENUM__BAR_BAZ\n"); + + // This isn't an error because the underscore will cause the PascalCase to + // differ by case (BarBaz vs. Barbaz). + BuildFile( + "name: 'foo.proto' " + "enum_type {" + " name: 'FooEnum' " + " value { name: 'BAR_BAZ' number: 0 }" + " value { name: 'BARBAZ' number: 1 }" + "}"); +} + TEST_F(ValidationErrorTest, MapEntryConflictsWithOneof) { FileDescriptorProto file_proto; FillValidMapEntry(&file_proto); diff --git a/src/google/protobuf/duration.pb.cc b/src/google/protobuf/duration.pb.cc index 884f6ccb..0e1be63c 100644 --- a/src/google/protobuf/duration.pb.cc +++ b/src/google/protobuf/duration.pb.cc @@ -44,20 +44,19 @@ void protobuf_AssignDesc_google_2fprotobuf_2fduration_2eproto() { Duration_reflection_ = ::google::protobuf::internal::GeneratedMessageReflection::NewGeneratedMessageReflection( Duration_descriptor_, - Duration::default_instance_, + Duration::internal_default_instance(), Duration_offsets_, -1, -1, -1, sizeof(Duration), - GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(Duration, _internal_metadata_), - GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(Duration, _is_default_instance_)); + GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(Duration, _internal_metadata_)); } namespace { GOOGLE_PROTOBUF_DECLARE_ONCE(protobuf_AssignDescriptors_once_); -inline void protobuf_AssignDescriptorsOnce() { +void protobuf_AssignDescriptorsOnce() { ::google::protobuf::GoogleOnceInit(&protobuf_AssignDescriptors_once_, &protobuf_AssignDesc_google_2fprotobuf_2fduration_2eproto); } @@ -66,37 +65,48 @@ void protobuf_RegisterTypes(const ::std::string&) GOOGLE_ATTRIBUTE_COLD; void protobuf_RegisterTypes(const ::std::string&) { protobuf_AssignDescriptorsOnce(); ::google::protobuf::MessageFactory::InternalRegisterGeneratedMessage( - Duration_descriptor_, &Duration::default_instance()); + Duration_descriptor_, Duration::internal_default_instance()); } } // namespace void protobuf_ShutdownFile_google_2fprotobuf_2fduration_2eproto() { - delete Duration::default_instance_; delete Duration_reflection_; } -void protobuf_AddDesc_google_2fprotobuf_2fduration_2eproto() GOOGLE_ATTRIBUTE_COLD; -void protobuf_AddDesc_google_2fprotobuf_2fduration_2eproto() { - static bool already_here = false; - if (already_here) return; - already_here = true; +void protobuf_InitDefaults_google_2fprotobuf_2fduration_2eproto_impl() { + GOOGLE_PROTOBUF_VERIFY_VERSION; + + Duration::default_instance_.DefaultConstruct(); + Duration::default_instance_.get_mutable()->InitAsDefaultInstance(); +} + +GOOGLE_PROTOBUF_DECLARE_ONCE(protobuf_InitDefaults_google_2fprotobuf_2fduration_2eproto_once_); +void protobuf_InitDefaults_google_2fprotobuf_2fduration_2eproto() { + ::google::protobuf::GoogleOnceInit(&protobuf_InitDefaults_google_2fprotobuf_2fduration_2eproto_once_, + &protobuf_InitDefaults_google_2fprotobuf_2fduration_2eproto_impl); +} +void protobuf_AddDesc_google_2fprotobuf_2fduration_2eproto_impl() { GOOGLE_PROTOBUF_VERIFY_VERSION; + protobuf_InitDefaults_google_2fprotobuf_2fduration_2eproto(); ::google::protobuf::DescriptorPool::InternalAddGeneratedFile( "\n\036google/protobuf/duration.proto\022\017google" ".protobuf\"*\n\010Duration\022\017\n\007seconds\030\001 \001(\003\022\r" "\n\005nanos\030\002 \001(\005B|\n\023com.google.protobufB\rDu" "rationProtoP\001Z*github.com/golang/protobu" - "f/ptypes/duration\240\001\001\242\002\003GPB\252\002\036Google.Prot" + "f/ptypes/duration\370\001\001\242\002\003GPB\252\002\036Google.Prot" "obuf.WellKnownTypesb\006proto3", 227); ::google::protobuf::MessageFactory::InternalRegisterGeneratedFile( "google/protobuf/duration.proto", &protobuf_RegisterTypes); - Duration::default_instance_ = new Duration(); - Duration::default_instance_->InitAsDefaultInstance(); ::google::protobuf::internal::OnShutdown(&protobuf_ShutdownFile_google_2fprotobuf_2fduration_2eproto); } +GOOGLE_PROTOBUF_DECLARE_ONCE(protobuf_AddDesc_google_2fprotobuf_2fduration_2eproto_once_); +void protobuf_AddDesc_google_2fprotobuf_2fduration_2eproto() { + ::google::protobuf::GoogleOnceInit(&protobuf_AddDesc_google_2fprotobuf_2fduration_2eproto_once_, + &protobuf_AddDesc_google_2fprotobuf_2fduration_2eproto_impl); +} // Force AddDescriptors() to be called at static initialization time. struct StaticDescriptorInitializer_google_2fprotobuf_2fduration_2eproto { StaticDescriptorInitializer_google_2fprotobuf_2fduration_2eproto() { @@ -104,6 +114,16 @@ struct StaticDescriptorInitializer_google_2fprotobuf_2fduration_2eproto { } } static_descriptor_initializer_google_2fprotobuf_2fduration_2eproto_; +namespace { + +static void MergeFromFail(int line) GOOGLE_ATTRIBUTE_COLD GOOGLE_ATTRIBUTE_NORETURN; +static void MergeFromFail(int line) { + ::google::protobuf::internal::MergeFromFail(__FILE__, line); +} + +} // namespace + + // =================================================================== #if !defined(_MSC_VER) || _MSC_VER >= 1900 @@ -113,27 +133,36 @@ const int Duration::kNanosFieldNumber; Duration::Duration() : ::google::protobuf::Message(), _internal_metadata_(NULL) { + if (this != internal_default_instance()) protobuf_InitDefaults_google_2fprotobuf_2fduration_2eproto(); SharedCtor(); // @@protoc_insertion_point(constructor:google.protobuf.Duration) } +Duration::Duration(::google::protobuf::Arena* arena) + : ::google::protobuf::Message(), + _internal_metadata_(arena) { +#ifdef GOOGLE_PROTOBUF_NO_STATIC_INITIALIZER + protobuf_InitDefaults_google_2fprotobuf_2fduration_2eproto(); +#endif // GOOGLE_PROTOBUF_NO_STATIC_INITIALIZER + SharedCtor(); + RegisterArenaDtor(arena); + // @@protoc_insertion_point(arena_constructor:google.protobuf.Duration) +} void Duration::InitAsDefaultInstance() { - _is_default_instance_ = true; } Duration::Duration(const Duration& from) : ::google::protobuf::Message(), _internal_metadata_(NULL) { SharedCtor(); - MergeFrom(from); + UnsafeMergeFrom(from); // @@protoc_insertion_point(copy_constructor:google.protobuf.Duration) } void Duration::SharedCtor() { - _is_default_instance_ = false; + ::memset(&seconds_, 0, reinterpret_cast(&nanos_) - + reinterpret_cast(&seconds_) + sizeof(nanos_)); _cached_size_ = 0; - seconds_ = GOOGLE_LONGLONG(0); - nanos_ = 0; } Duration::~Duration() { @@ -142,10 +171,19 @@ Duration::~Duration() { } void Duration::SharedDtor() { - if (this != default_instance_) { + ::google::protobuf::Arena* arena = GetArenaNoVirtual(); + if (arena != NULL) { + return; } + } +void Duration::ArenaDtor(void* object) { + Duration* _this = reinterpret_cast< Duration* >(object); + (void)_this; +} +void Duration::RegisterArenaDtor(::google::protobuf::Arena* arena) { +} void Duration::SetCachedSize(int size) const { GOOGLE_SAFE_CONCURRENT_WRITES_BEGIN(); _cached_size_ = size; @@ -157,18 +195,14 @@ const ::google::protobuf::Descriptor* Duration::descriptor() { } const Duration& Duration::default_instance() { - if (default_instance_ == NULL) protobuf_AddDesc_google_2fprotobuf_2fduration_2eproto(); - return *default_instance_; + protobuf_InitDefaults_google_2fprotobuf_2fduration_2eproto(); + return *internal_default_instance(); } -Duration* Duration::default_instance_ = NULL; +::google::protobuf::internal::ExplicitlyConstructed Duration::default_instance_; Duration* Duration::New(::google::protobuf::Arena* arena) const { - Duration* n = new Duration; - if (arena != NULL) { - arena->Own(n); - } - return n; + return ::google::protobuf::Arena::CreateMessage(arena); } void Duration::Clear() { @@ -209,10 +243,10 @@ bool Duration::MergePartialFromCodedStream( // optional int64 seconds = 1; case 1: { if (tag == 8) { + DO_((::google::protobuf::internal::WireFormatLite::ReadPrimitive< ::google::protobuf::int64, ::google::protobuf::internal::WireFormatLite::TYPE_INT64>( input, &seconds_))); - } else { goto handle_unusual; } @@ -224,10 +258,10 @@ bool Duration::MergePartialFromCodedStream( case 2: { if (tag == 16) { parse_nanos: + DO_((::google::protobuf::internal::WireFormatLite::ReadPrimitive< ::google::protobuf::int32, ::google::protobuf::internal::WireFormatLite::TYPE_INT32>( input, &nanos_))); - } else { goto handle_unusual; } @@ -290,9 +324,9 @@ void Duration::SerializeWithCachedSizes( return target; } -int Duration::ByteSize() const { +size_t Duration::ByteSizeLong() const { // @@protoc_insertion_point(message_byte_size_start:google.protobuf.Duration) - int total_size = 0; + size_t total_size = 0; // optional int64 seconds = 1; if (this->seconds() != 0) { @@ -308,18 +342,17 @@ int Duration::ByteSize() const { this->nanos()); } + int cached_size = ::google::protobuf::internal::ToCachedSize(total_size); GOOGLE_SAFE_CONCURRENT_WRITES_BEGIN(); - _cached_size_ = total_size; + _cached_size_ = cached_size; GOOGLE_SAFE_CONCURRENT_WRITES_END(); return total_size; } void Duration::MergeFrom(const ::google::protobuf::Message& from) { // @@protoc_insertion_point(generalized_merge_from_start:google.protobuf.Duration) - if (GOOGLE_PREDICT_FALSE(&from == this)) { - ::google::protobuf::internal::MergeFromFail(__FILE__, __LINE__); - } - const Duration* source = + if (GOOGLE_PREDICT_FALSE(&from == this)) MergeFromFail(__LINE__); + const Duration* source = ::google::protobuf::internal::DynamicCastToGenerated( &from); if (source == NULL) { @@ -327,15 +360,21 @@ void Duration::MergeFrom(const ::google::protobuf::Message& from) { ::google::protobuf::internal::ReflectionOps::Merge(from, this); } else { // @@protoc_insertion_point(generalized_merge_from_cast_success:google.protobuf.Duration) - MergeFrom(*source); + UnsafeMergeFrom(*source); } } void Duration::MergeFrom(const Duration& from) { // @@protoc_insertion_point(class_specific_merge_from_start:google.protobuf.Duration) - if (GOOGLE_PREDICT_FALSE(&from == this)) { - ::google::protobuf::internal::MergeFromFail(__FILE__, __LINE__); + if (GOOGLE_PREDICT_TRUE(&from != this)) { + UnsafeMergeFrom(from); + } else { + MergeFromFail(__LINE__); } +} + +void Duration::UnsafeMergeFrom(const Duration& from) { + GOOGLE_DCHECK(&from != this); if (from.seconds() != 0) { set_seconds(from.seconds()); } @@ -355,7 +394,7 @@ void Duration::CopyFrom(const Duration& from) { // @@protoc_insertion_point(class_specific_copy_from_start:google.protobuf.Duration) if (&from == this) return; Clear(); - MergeFrom(from); + UnsafeMergeFrom(from); } bool Duration::IsInitialized() const { @@ -365,6 +404,18 @@ bool Duration::IsInitialized() const { void Duration::Swap(Duration* other) { if (other == this) return; + if (GetArenaNoVirtual() == other->GetArenaNoVirtual()) { + InternalSwap(other); + } else { + Duration temp; + temp.UnsafeMergeFrom(*this); + CopyFrom(*other); + other->CopyFrom(temp); + } +} +void Duration::UnsafeArenaSwap(Duration* other) { + if (other == this) return; + GOOGLE_DCHECK(GetArenaNoVirtual() == other->GetArenaNoVirtual()); InternalSwap(other); } void Duration::InternalSwap(Duration* other) { @@ -389,11 +440,11 @@ void Duration::InternalSwap(Duration* other) { void Duration::clear_seconds() { seconds_ = GOOGLE_LONGLONG(0); } - ::google::protobuf::int64 Duration::seconds() const { +::google::protobuf::int64 Duration::seconds() const { // @@protoc_insertion_point(field_get:google.protobuf.Duration.seconds) return seconds_; } - void Duration::set_seconds(::google::protobuf::int64 value) { +void Duration::set_seconds(::google::protobuf::int64 value) { seconds_ = value; // @@protoc_insertion_point(field_set:google.protobuf.Duration.seconds) @@ -403,11 +454,11 @@ void Duration::clear_seconds() { void Duration::clear_nanos() { nanos_ = 0; } - ::google::protobuf::int32 Duration::nanos() const { +::google::protobuf::int32 Duration::nanos() const { // @@protoc_insertion_point(field_get:google.protobuf.Duration.nanos) return nanos_; } - void Duration::set_nanos(::google::protobuf::int32 value) { +void Duration::set_nanos(::google::protobuf::int32 value) { nanos_ = value; // @@protoc_insertion_point(field_set:google.protobuf.Duration.nanos) diff --git a/src/google/protobuf/duration.pb.h b/src/google/protobuf/duration.pb.h index 44307347..fe135b1e 100644 --- a/src/google/protobuf/duration.pb.h +++ b/src/google/protobuf/duration.pb.h @@ -34,6 +34,7 @@ namespace protobuf { // Internal implementation detail -- do not call these. void LIBPROTOBUF_EXPORT protobuf_AddDesc_google_2fprotobuf_2fduration_2eproto(); +void LIBPROTOBUF_EXPORT protobuf_InitDefaults_google_2fprotobuf_2fduration_2eproto(); void protobuf_AssignDesc_google_2fprotobuf_2fduration_2eproto(); void protobuf_ShutdownFile_google_2fprotobuf_2fduration_2eproto(); @@ -53,9 +54,18 @@ class LIBPROTOBUF_EXPORT Duration : public ::google::protobuf::Message /* @@prot return *this; } + inline ::google::protobuf::Arena* GetArena() const { return GetArenaNoVirtual(); } + inline void* GetMaybeArenaPointer() const { + return MaybeArenaPtr(); + } static const ::google::protobuf::Descriptor* descriptor(); static const Duration& default_instance(); + static inline const Duration* internal_default_instance() { + return &default_instance_.get(); + } + + void UnsafeArenaSwap(Duration* other); void Swap(Duration* other); // implements Message ---------------------------------------------- @@ -70,7 +80,7 @@ class LIBPROTOBUF_EXPORT Duration : public ::google::protobuf::Message /* @@prot void Clear(); bool IsInitialized() const; - int ByteSize() const; + size_t ByteSizeLong() const; bool MergePartialFromCodedStream( ::google::protobuf::io::CodedInputStream* input); void SerializeWithCachedSizes( @@ -86,6 +96,12 @@ class LIBPROTOBUF_EXPORT Duration : public ::google::protobuf::Message /* @@prot void SharedDtor(); void SetCachedSize(int size) const; void InternalSwap(Duration* other); + void UnsafeMergeFrom(const Duration& from); + protected: + explicit Duration(::google::protobuf::Arena* arena); + private: + static void ArenaDtor(void* object); + inline void RegisterArenaDtor(::google::protobuf::Arena* arena); private: inline ::google::protobuf::Arena* GetArenaNoVirtual() const { return _internal_metadata_.arena(); @@ -117,16 +133,19 @@ class LIBPROTOBUF_EXPORT Duration : public ::google::protobuf::Message /* @@prot private: ::google::protobuf::internal::InternalMetadataWithArena _internal_metadata_; - bool _is_default_instance_; + friend class ::google::protobuf::Arena; + typedef void InternalArenaConstructable_; + typedef void DestructorSkippable_; ::google::protobuf::int64 seconds_; ::google::protobuf::int32 nanos_; mutable int _cached_size_; - friend void LIBPROTOBUF_EXPORT protobuf_AddDesc_google_2fprotobuf_2fduration_2eproto(); + friend void LIBPROTOBUF_EXPORT protobuf_InitDefaults_google_2fprotobuf_2fduration_2eproto_impl(); + friend void LIBPROTOBUF_EXPORT protobuf_AddDesc_google_2fprotobuf_2fduration_2eproto_impl(); friend void protobuf_AssignDesc_google_2fprotobuf_2fduration_2eproto(); friend void protobuf_ShutdownFile_google_2fprotobuf_2fduration_2eproto(); void InitAsDefaultInstance(); - static Duration* default_instance_; + static ::google::protobuf::internal::ExplicitlyConstructed default_instance_; }; // =================================================================== diff --git a/src/google/protobuf/duration.proto b/src/google/protobuf/duration.proto index 96c1796d..7f461f40 100644 --- a/src/google/protobuf/duration.proto +++ b/src/google/protobuf/duration.proto @@ -33,11 +33,11 @@ syntax = "proto3"; package google.protobuf; option csharp_namespace = "Google.Protobuf.WellKnownTypes"; +option cc_enable_arenas = true; option go_package = "github.com/golang/protobuf/ptypes/duration"; option java_package = "com.google.protobuf"; option java_outer_classname = "DurationProto"; option java_multiple_files = true; -option java_generate_equals_and_hash = true; option objc_class_prefix = "GPB"; // A Duration represents a signed, fixed-length span of time represented @@ -81,6 +81,12 @@ option objc_class_prefix = "GPB"; // end.nanos -= 1000000000; // } // +// Example 3: Compute Duration from datetime.timedelta in Python. +// +// td = datetime.timedelta(days=3, minutes=10) +// duration = Duration() +// duration.FromTimedelta(td) +// // message Duration { diff --git a/src/google/protobuf/dynamic_message.cc b/src/google/protobuf/dynamic_message.cc index 5d914bf6..f51bc9d6 100644 --- a/src/google/protobuf/dynamic_message.cc +++ b/src/google/protobuf/dynamic_message.cc @@ -223,7 +223,6 @@ class DynamicMessage : public Message { int oneof_case_offset; int unknown_fields_offset; int extensions_offset; - int is_default_instance_offset; // Not owned by the TypeInfo. DynamicMessageFactory* factory; // The factory that created this object. @@ -332,11 +331,6 @@ void DynamicMessage::SharedCtor() { uint32(0); } - if (type_info_->is_default_instance_offset != -1) { - *reinterpret_cast( - OffsetToPointer(type_info_->is_default_instance_offset)) = false; - } - new(OffsetToPointer(type_info_->unknown_fields_offset)) UnknownFieldSet; if (type_info_->extensions_offset != -1) { @@ -556,14 +550,6 @@ void DynamicMessage::CrossLinkPrototypes() { factory->GetPrototypeNoLock(field->message_type()); } } - - // Set as the default instance -- this affects field-presence semantics for - // proto3. - if (type_info_->is_default_instance_offset != -1) { - void* is_default_instance_ptr = - OffsetToPointer(type_info_->is_default_instance_offset); - *reinterpret_cast(is_default_instance_ptr) = true; - } } Message* DynamicMessage::New() const { @@ -683,15 +669,6 @@ const Message* DynamicMessageFactory::GetPrototypeNoLock( size = AlignOffset(size); } - // The is_default_instance member, if any. - if (type->file()->syntax() == FileDescriptor::SYNTAX_PROTO3) { - type_info->is_default_instance_offset = size; - size += sizeof(bool); - size = AlignOffset(size); - } else { - type_info->is_default_instance_offset = -1; - } - // The oneof_case, if any. It is an array of uint32s. if (type->oneof_decl_count() > 0) { type_info->oneof_case_offset = size; @@ -769,35 +746,18 @@ const Message* DynamicMessageFactory::GetPrototypeNoLock( ConstructDefaultOneofInstance(type_info->type, type_info->offsets.get(), type_info->default_oneof_instance); - type_info->reflection.reset( - new GeneratedMessageReflection( - type_info->type, - type_info->prototype, - type_info->offsets.get(), - type_info->has_bits_offset, - type_info->unknown_fields_offset, - type_info->extensions_offset, - type_info->default_oneof_instance, - type_info->oneof_case_offset, - type_info->pool, - this, - type_info->size, - -1 /* arena_offset */, - type_info->is_default_instance_offset)); + type_info->reflection.reset(new GeneratedMessageReflection( + type_info->type, type_info->prototype, type_info->offsets.get(), + type_info->has_bits_offset, type_info->unknown_fields_offset, + type_info->extensions_offset, type_info->default_oneof_instance, + type_info->oneof_case_offset, type_info->pool, this, type_info->size, + -1 /* arena_offset */)); } else { - type_info->reflection.reset( - new GeneratedMessageReflection( - type_info->type, - type_info->prototype, - type_info->offsets.get(), - type_info->has_bits_offset, - type_info->unknown_fields_offset, - type_info->extensions_offset, - type_info->pool, - this, - type_info->size, - -1 /* arena_offset */, - type_info->is_default_instance_offset)); + type_info->reflection.reset(new GeneratedMessageReflection( + type_info->type, type_info->prototype, type_info->offsets.get(), + type_info->has_bits_offset, type_info->unknown_fields_offset, + type_info->extensions_offset, type_info->pool, this, type_info->size, + -1 /* arena_offset */)); } // Cross link prototypes. prototype->CrossLinkPrototypes(); diff --git a/src/google/protobuf/empty.pb.cc b/src/google/protobuf/empty.pb.cc index 7ef97790..45bba99b 100644 --- a/src/google/protobuf/empty.pb.cc +++ b/src/google/protobuf/empty.pb.cc @@ -42,20 +42,19 @@ void protobuf_AssignDesc_google_2fprotobuf_2fempty_2eproto() { Empty_reflection_ = ::google::protobuf::internal::GeneratedMessageReflection::NewGeneratedMessageReflection( Empty_descriptor_, - Empty::default_instance_, + Empty::internal_default_instance(), Empty_offsets_, -1, -1, -1, sizeof(Empty), - GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(Empty, _internal_metadata_), - GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(Empty, _is_default_instance_)); + GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(Empty, _internal_metadata_)); } namespace { GOOGLE_PROTOBUF_DECLARE_ONCE(protobuf_AssignDescriptors_once_); -inline void protobuf_AssignDescriptorsOnce() { +void protobuf_AssignDescriptorsOnce() { ::google::protobuf::GoogleOnceInit(&protobuf_AssignDescriptors_once_, &protobuf_AssignDesc_google_2fprotobuf_2fempty_2eproto); } @@ -64,36 +63,47 @@ void protobuf_RegisterTypes(const ::std::string&) GOOGLE_ATTRIBUTE_COLD; void protobuf_RegisterTypes(const ::std::string&) { protobuf_AssignDescriptorsOnce(); ::google::protobuf::MessageFactory::InternalRegisterGeneratedMessage( - Empty_descriptor_, &Empty::default_instance()); + Empty_descriptor_, Empty::internal_default_instance()); } } // namespace void protobuf_ShutdownFile_google_2fprotobuf_2fempty_2eproto() { - delete Empty::default_instance_; delete Empty_reflection_; } -void protobuf_AddDesc_google_2fprotobuf_2fempty_2eproto() GOOGLE_ATTRIBUTE_COLD; -void protobuf_AddDesc_google_2fprotobuf_2fempty_2eproto() { - static bool already_here = false; - if (already_here) return; - already_here = true; +void protobuf_InitDefaults_google_2fprotobuf_2fempty_2eproto_impl() { + GOOGLE_PROTOBUF_VERIFY_VERSION; + + Empty::default_instance_.DefaultConstruct(); + Empty::default_instance_.get_mutable()->InitAsDefaultInstance(); +} + +GOOGLE_PROTOBUF_DECLARE_ONCE(protobuf_InitDefaults_google_2fprotobuf_2fempty_2eproto_once_); +void protobuf_InitDefaults_google_2fprotobuf_2fempty_2eproto() { + ::google::protobuf::GoogleOnceInit(&protobuf_InitDefaults_google_2fprotobuf_2fempty_2eproto_once_, + &protobuf_InitDefaults_google_2fprotobuf_2fempty_2eproto_impl); +} +void protobuf_AddDesc_google_2fprotobuf_2fempty_2eproto_impl() { GOOGLE_PROTOBUF_VERIFY_VERSION; + protobuf_InitDefaults_google_2fprotobuf_2fempty_2eproto(); ::google::protobuf::DescriptorPool::InternalAddGeneratedFile( "\n\033google/protobuf/empty.proto\022\017google.pr" - "otobuf\"\007\n\005EmptyBy\n\023com.google.protobufB\n" + "otobuf\"\007\n\005EmptyBv\n\023com.google.protobufB\n" "EmptyProtoP\001Z\'github.com/golang/protobuf" - "/ptypes/empty\240\001\001\370\001\001\242\002\003GPB\252\002\036Google.Proto" - "buf.WellKnownTypesb\006proto3", 186); + "/ptypes/empty\370\001\001\242\002\003GPB\252\002\036Google.Protobuf" + ".WellKnownTypesb\006proto3", 183); ::google::protobuf::MessageFactory::InternalRegisterGeneratedFile( "google/protobuf/empty.proto", &protobuf_RegisterTypes); - Empty::default_instance_ = new Empty(); - Empty::default_instance_->InitAsDefaultInstance(); ::google::protobuf::internal::OnShutdown(&protobuf_ShutdownFile_google_2fprotobuf_2fempty_2eproto); } +GOOGLE_PROTOBUF_DECLARE_ONCE(protobuf_AddDesc_google_2fprotobuf_2fempty_2eproto_once_); +void protobuf_AddDesc_google_2fprotobuf_2fempty_2eproto() { + ::google::protobuf::GoogleOnceInit(&protobuf_AddDesc_google_2fprotobuf_2fempty_2eproto_once_, + &protobuf_AddDesc_google_2fprotobuf_2fempty_2eproto_impl); +} // Force AddDescriptors() to be called at static initialization time. struct StaticDescriptorInitializer_google_2fprotobuf_2fempty_2eproto { StaticDescriptorInitializer_google_2fprotobuf_2fempty_2eproto() { @@ -101,6 +111,16 @@ struct StaticDescriptorInitializer_google_2fprotobuf_2fempty_2eproto { } } static_descriptor_initializer_google_2fprotobuf_2fempty_2eproto_; +namespace { + +static void MergeFromFail(int line) GOOGLE_ATTRIBUTE_COLD GOOGLE_ATTRIBUTE_NORETURN; +static void MergeFromFail(int line) { + ::google::protobuf::internal::MergeFromFail(__FILE__, line); +} + +} // namespace + + // =================================================================== #if !defined(_MSC_VER) || _MSC_VER >= 1900 @@ -108,32 +128,33 @@ struct StaticDescriptorInitializer_google_2fprotobuf_2fempty_2eproto { Empty::Empty() : ::google::protobuf::Message(), _internal_metadata_(NULL) { + if (this != internal_default_instance()) protobuf_InitDefaults_google_2fprotobuf_2fempty_2eproto(); SharedCtor(); // @@protoc_insertion_point(constructor:google.protobuf.Empty) } - Empty::Empty(::google::protobuf::Arena* arena) : ::google::protobuf::Message(), _internal_metadata_(arena) { +#ifdef GOOGLE_PROTOBUF_NO_STATIC_INITIALIZER + protobuf_InitDefaults_google_2fprotobuf_2fempty_2eproto(); +#endif // GOOGLE_PROTOBUF_NO_STATIC_INITIALIZER SharedCtor(); RegisterArenaDtor(arena); // @@protoc_insertion_point(arena_constructor:google.protobuf.Empty) } void Empty::InitAsDefaultInstance() { - _is_default_instance_ = true; } Empty::Empty(const Empty& from) : ::google::protobuf::Message(), _internal_metadata_(NULL) { SharedCtor(); - MergeFrom(from); + UnsafeMergeFrom(from); // @@protoc_insertion_point(copy_constructor:google.protobuf.Empty) } void Empty::SharedCtor() { - _is_default_instance_ = false; _cached_size_ = 0; } @@ -143,12 +164,11 @@ Empty::~Empty() { } void Empty::SharedDtor() { - if (GetArenaNoVirtual() != NULL) { + ::google::protobuf::Arena* arena = GetArenaNoVirtual(); + if (arena != NULL) { return; } - if (this != default_instance_) { - } } void Empty::ArenaDtor(void* object) { @@ -168,11 +188,11 @@ const ::google::protobuf::Descriptor* Empty::descriptor() { } const Empty& Empty::default_instance() { - if (default_instance_ == NULL) protobuf_AddDesc_google_2fprotobuf_2fempty_2eproto(); - return *default_instance_; + protobuf_InitDefaults_google_2fprotobuf_2fempty_2eproto(); + return *internal_default_instance(); } -Empty* Empty::default_instance_ = NULL; +::google::protobuf::internal::ExplicitlyConstructed Empty::default_instance_; Empty* Empty::New(::google::protobuf::Arena* arena) const { return ::google::protobuf::Arena::CreateMessage(arena); @@ -222,22 +242,21 @@ void Empty::SerializeWithCachedSizes( return target; } -int Empty::ByteSize() const { +size_t Empty::ByteSizeLong() const { // @@protoc_insertion_point(message_byte_size_start:google.protobuf.Empty) - int total_size = 0; + size_t total_size = 0; + int cached_size = ::google::protobuf::internal::ToCachedSize(total_size); GOOGLE_SAFE_CONCURRENT_WRITES_BEGIN(); - _cached_size_ = total_size; + _cached_size_ = cached_size; GOOGLE_SAFE_CONCURRENT_WRITES_END(); return total_size; } void Empty::MergeFrom(const ::google::protobuf::Message& from) { // @@protoc_insertion_point(generalized_merge_from_start:google.protobuf.Empty) - if (GOOGLE_PREDICT_FALSE(&from == this)) { - ::google::protobuf::internal::MergeFromFail(__FILE__, __LINE__); - } - const Empty* source = + if (GOOGLE_PREDICT_FALSE(&from == this)) MergeFromFail(__LINE__); + const Empty* source = ::google::protobuf::internal::DynamicCastToGenerated( &from); if (source == NULL) { @@ -245,17 +264,23 @@ void Empty::MergeFrom(const ::google::protobuf::Message& from) { ::google::protobuf::internal::ReflectionOps::Merge(from, this); } else { // @@protoc_insertion_point(generalized_merge_from_cast_success:google.protobuf.Empty) - MergeFrom(*source); + UnsafeMergeFrom(*source); } } void Empty::MergeFrom(const Empty& from) { // @@protoc_insertion_point(class_specific_merge_from_start:google.protobuf.Empty) - if (GOOGLE_PREDICT_FALSE(&from == this)) { - ::google::protobuf::internal::MergeFromFail(__FILE__, __LINE__); + if (GOOGLE_PREDICT_TRUE(&from != this)) { + UnsafeMergeFrom(from); + } else { + MergeFromFail(__LINE__); } } +void Empty::UnsafeMergeFrom(const Empty& from) { + GOOGLE_DCHECK(&from != this); +} + void Empty::CopyFrom(const ::google::protobuf::Message& from) { // @@protoc_insertion_point(generalized_copy_from_start:google.protobuf.Empty) if (&from == this) return; @@ -267,7 +292,7 @@ void Empty::CopyFrom(const Empty& from) { // @@protoc_insertion_point(class_specific_copy_from_start:google.protobuf.Empty) if (&from == this) return; Clear(); - MergeFrom(from); + UnsafeMergeFrom(from); } bool Empty::IsInitialized() const { @@ -281,7 +306,7 @@ void Empty::Swap(Empty* other) { InternalSwap(other); } else { Empty temp; - temp.MergeFrom(*this); + temp.UnsafeMergeFrom(*this); CopyFrom(*other); other->CopyFrom(temp); } diff --git a/src/google/protobuf/empty.pb.h b/src/google/protobuf/empty.pb.h index a4059fac..37b0c144 100644 --- a/src/google/protobuf/empty.pb.h +++ b/src/google/protobuf/empty.pb.h @@ -34,6 +34,7 @@ namespace protobuf { // Internal implementation detail -- do not call these. void LIBPROTOBUF_EXPORT protobuf_AddDesc_google_2fprotobuf_2fempty_2eproto(); +void LIBPROTOBUF_EXPORT protobuf_InitDefaults_google_2fprotobuf_2fempty_2eproto(); void protobuf_AssignDesc_google_2fprotobuf_2fempty_2eproto(); void protobuf_ShutdownFile_google_2fprotobuf_2fempty_2eproto(); @@ -60,6 +61,10 @@ class LIBPROTOBUF_EXPORT Empty : public ::google::protobuf::Message /* @@protoc_ static const ::google::protobuf::Descriptor* descriptor(); static const Empty& default_instance(); + static inline const Empty* internal_default_instance() { + return &default_instance_.get(); + } + void UnsafeArenaSwap(Empty* other); void Swap(Empty* other); @@ -75,7 +80,7 @@ class LIBPROTOBUF_EXPORT Empty : public ::google::protobuf::Message /* @@protoc_ void Clear(); bool IsInitialized() const; - int ByteSize() const; + size_t ByteSizeLong() const; bool MergePartialFromCodedStream( ::google::protobuf::io::CodedInputStream* input); void SerializeWithCachedSizes( @@ -91,6 +96,7 @@ class LIBPROTOBUF_EXPORT Empty : public ::google::protobuf::Message /* @@protoc_ void SharedDtor(); void SetCachedSize(int size) const; void InternalSwap(Empty* other); + void UnsafeMergeFrom(const Empty& from); protected: explicit Empty(::google::protobuf::Arena* arena); private: @@ -118,14 +124,14 @@ class LIBPROTOBUF_EXPORT Empty : public ::google::protobuf::Message /* @@protoc_ friend class ::google::protobuf::Arena; typedef void InternalArenaConstructable_; typedef void DestructorSkippable_; - bool _is_default_instance_; mutable int _cached_size_; - friend void LIBPROTOBUF_EXPORT protobuf_AddDesc_google_2fprotobuf_2fempty_2eproto(); + friend void LIBPROTOBUF_EXPORT protobuf_InitDefaults_google_2fprotobuf_2fempty_2eproto_impl(); + friend void LIBPROTOBUF_EXPORT protobuf_AddDesc_google_2fprotobuf_2fempty_2eproto_impl(); friend void protobuf_AssignDesc_google_2fprotobuf_2fempty_2eproto(); friend void protobuf_ShutdownFile_google_2fprotobuf_2fempty_2eproto(); void InitAsDefaultInstance(); - static Empty* default_instance_; + static ::google::protobuf::internal::ExplicitlyConstructed default_instance_; }; // =================================================================== diff --git a/src/google/protobuf/empty.proto b/src/google/protobuf/empty.proto index 37f4cd10..03cacd23 100644 --- a/src/google/protobuf/empty.proto +++ b/src/google/protobuf/empty.proto @@ -37,7 +37,6 @@ option go_package = "github.com/golang/protobuf/ptypes/empty"; option java_package = "com.google.protobuf"; option java_outer_classname = "EmptyProto"; option java_multiple_files = true; -option java_generate_equals_and_hash = true; option objc_class_prefix = "GPB"; option cc_enable_arenas = true; diff --git a/src/google/protobuf/extension_set.cc b/src/google/protobuf/extension_set.cc index 7d20a0f8..ad164e3e 100644 --- a/src/google/protobuf/extension_set.cc +++ b/src/google/protobuf/extension_set.cc @@ -1354,8 +1354,8 @@ void ExtensionSet::SerializeWithCachedSizes( } } -int ExtensionSet::ByteSize() const { - int total_size = 0; +size_t ExtensionSet::ByteSize() const { + size_t total_size = 0; for (ExtensionMap::const_iterator iter = extensions_.begin(); iter != extensions_.end(); ++iter) { @@ -1536,8 +1536,8 @@ void ExtensionSet::Extension::SerializeFieldWithCachedSizes( } } -int ExtensionSet::Extension::ByteSize(int number) const { - int result = 0; +size_t ExtensionSet::Extension::ByteSize(int number) const { + size_t result = 0; if (is_repeated) { if (is_packed) { @@ -1563,7 +1563,7 @@ int ExtensionSet::Extension::ByteSize(int number) const { #define HANDLE_TYPE(UPPERCASE, CAMELCASE, LOWERCASE) \ case WireFormatLite::TYPE_##UPPERCASE: \ result += WireFormatLite::k##CAMELCASE##Size * \ - repeated_##LOWERCASE##_value->size(); \ + FromIntSize(repeated_##LOWERCASE##_value->size()); \ break HANDLE_TYPE( FIXED32, Fixed32, uint32); HANDLE_TYPE( FIXED64, Fixed64, uint64); @@ -1582,7 +1582,7 @@ int ExtensionSet::Extension::ByteSize(int number) const { break; } - cached_size = result; + cached_size = ToCachedSize(result); if (result > 0) { result += io::CodedOutputStream::VarintSize32(result); result += io::CodedOutputStream::VarintSize32( @@ -1590,12 +1590,13 @@ int ExtensionSet::Extension::ByteSize(int number) const { WireFormatLite::WIRETYPE_LENGTH_DELIMITED)); } } else { - int tag_size = WireFormatLite::TagSize(number, real_type(type)); + size_t tag_size = WireFormatLite::TagSize(number, real_type(type)); switch (real_type(type)) { #define HANDLE_TYPE(UPPERCASE, CAMELCASE, LOWERCASE) \ case WireFormatLite::TYPE_##UPPERCASE: \ - result += tag_size * repeated_##LOWERCASE##_value->size(); \ + result += tag_size * \ + FromIntSize(repeated_##LOWERCASE##_value->size()); \ for (int i = 0; i < repeated_##LOWERCASE##_value->size(); i++) { \ result += WireFormatLite::CAMELCASE##Size( \ repeated_##LOWERCASE##_value->Get(i)); \ @@ -1619,7 +1620,7 @@ int ExtensionSet::Extension::ByteSize(int number) const { #define HANDLE_TYPE(UPPERCASE, CAMELCASE, LOWERCASE) \ case WireFormatLite::TYPE_##UPPERCASE: \ result += (tag_size + WireFormatLite::k##CAMELCASE##Size) * \ - repeated_##LOWERCASE##_value->size(); \ + FromIntSize(repeated_##LOWERCASE##_value->size()); \ break HANDLE_TYPE( FIXED32, Fixed32, uint32); HANDLE_TYPE( FIXED64, Fixed64, uint64); @@ -1652,7 +1653,7 @@ int ExtensionSet::Extension::ByteSize(int number) const { #undef HANDLE_TYPE case WireFormatLite::TYPE_MESSAGE: { if (is_lazy) { - int size = lazymessage_value->ByteSize(); + size_t size = lazymessage_value->ByteSize(); result += io::CodedOutputStream::VarintSize32(size) + size; } else { result += WireFormatLite::MessageSize(*message_value); diff --git a/src/google/protobuf/extension_set.h b/src/google/protobuf/extension_set.h index 3e1d1ef5..f5aa8de9 100644 --- a/src/google/protobuf/extension_set.h +++ b/src/google/protobuf/extension_set.h @@ -423,10 +423,10 @@ class LIBPROTOBUF_EXPORT ExtensionSet { uint8* SerializeMessageSetWithCachedSizesToArray(uint8* target) const; // Returns the total serialized size of all the extensions. - int ByteSize() const; + size_t ByteSize() const; // Like ByteSize() but uses MessageSet format. - int MessageSetByteSize() const; + size_t MessageSetByteSize() const; // Returns (an estimate of) the total number of bytes used for storing the // extensions in memory, excluding sizeof(*this). If the ExtensionSet is @@ -551,8 +551,8 @@ class LIBPROTOBUF_EXPORT ExtensionSet { int number, bool deterministic, uint8* target) const; - int ByteSize(int number) const; - int MessageSetItemByteSize(int number) const; + size_t ByteSize(int number) const; + size_t MessageSetItemByteSize(int number) const; void Clear(); int GetSize() const; void Free(); diff --git a/src/google/protobuf/extension_set_heavy.cc b/src/google/protobuf/extension_set_heavy.cc index b26a246c..1bbc8fef 100644 --- a/src/google/protobuf/extension_set_heavy.cc +++ b/src/google/protobuf/extension_set_heavy.cc @@ -749,7 +749,7 @@ void ExtensionSet::Extension::SerializeMessageSetItemWithCachedSizes( output->WriteTag(WireFormatLite::kMessageSetItemEndTag); } -int ExtensionSet::Extension::MessageSetItemByteSize(int number) const { +size_t ExtensionSet::Extension::MessageSetItemByteSize(int number) const { if (type != WireFormatLite::TYPE_MESSAGE || is_repeated) { // Not a valid MessageSet extension, but compute the byte size for it the // normal way. @@ -758,13 +758,13 @@ int ExtensionSet::Extension::MessageSetItemByteSize(int number) const { if (is_cleared) return 0; - int our_size = WireFormatLite::kMessageSetItemTagsSize; + size_t our_size = WireFormatLite::kMessageSetItemTagsSize; // type_id our_size += io::CodedOutputStream::VarintSize32(number); // message - int message_size = 0; + size_t message_size = 0; if (is_lazy) { message_size = lazymessage_value->ByteSize(); } else { @@ -785,8 +785,8 @@ void ExtensionSet::SerializeMessageSetWithCachedSizes( } } -int ExtensionSet::MessageSetByteSize() const { - int total_size = 0; +size_t ExtensionSet::MessageSetByteSize() const { + size_t total_size = 0; for (ExtensionMap::const_iterator iter = extensions_.begin(); iter != extensions_.end(); ++iter) { diff --git a/src/google/protobuf/extension_set_unittest.cc b/src/google/protobuf/extension_set_unittest.cc index 688afedb..a70a2ff6 100644 --- a/src/google/protobuf/extension_set_unittest.cc +++ b/src/google/protobuf/extension_set_unittest.cc @@ -796,7 +796,7 @@ TEST(ExtensionSetTest, SpaceUsedExcludingSelf) { } \ int expected_size = sizeof(cpptype) * (16 - \ kMinRepeatedFieldAllocationSize) + empty_repeated_field_size; \ - EXPECT_EQ(expected_size, message.SpaceUsed()) << #type; \ + EXPECT_LE(expected_size, message.SpaceUsed()) << #type; \ } while (0) TEST_REPEATED_EXTENSIONS_SPACE_USED(int32 , int32 , 101); diff --git a/src/google/protobuf/field_mask.pb.cc b/src/google/protobuf/field_mask.pb.cc index d2acc38b..ffe513d3 100644 --- a/src/google/protobuf/field_mask.pb.cc +++ b/src/google/protobuf/field_mask.pb.cc @@ -43,20 +43,19 @@ void protobuf_AssignDesc_google_2fprotobuf_2ffield_5fmask_2eproto() { FieldMask_reflection_ = ::google::protobuf::internal::GeneratedMessageReflection::NewGeneratedMessageReflection( FieldMask_descriptor_, - FieldMask::default_instance_, + FieldMask::internal_default_instance(), FieldMask_offsets_, -1, -1, -1, sizeof(FieldMask), - GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(FieldMask, _internal_metadata_), - GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(FieldMask, _is_default_instance_)); + GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(FieldMask, _internal_metadata_)); } namespace { GOOGLE_PROTOBUF_DECLARE_ONCE(protobuf_AssignDescriptors_once_); -inline void protobuf_AssignDescriptorsOnce() { +void protobuf_AssignDescriptorsOnce() { ::google::protobuf::GoogleOnceInit(&protobuf_AssignDescriptors_once_, &protobuf_AssignDesc_google_2fprotobuf_2ffield_5fmask_2eproto); } @@ -65,36 +64,48 @@ void protobuf_RegisterTypes(const ::std::string&) GOOGLE_ATTRIBUTE_COLD; void protobuf_RegisterTypes(const ::std::string&) { protobuf_AssignDescriptorsOnce(); ::google::protobuf::MessageFactory::InternalRegisterGeneratedMessage( - FieldMask_descriptor_, &FieldMask::default_instance()); + FieldMask_descriptor_, FieldMask::internal_default_instance()); } } // namespace void protobuf_ShutdownFile_google_2fprotobuf_2ffield_5fmask_2eproto() { - delete FieldMask::default_instance_; delete FieldMask_reflection_; } -void protobuf_AddDesc_google_2fprotobuf_2ffield_5fmask_2eproto() GOOGLE_ATTRIBUTE_COLD; -void protobuf_AddDesc_google_2fprotobuf_2ffield_5fmask_2eproto() { - static bool already_here = false; - if (already_here) return; - already_here = true; +void protobuf_InitDefaults_google_2fprotobuf_2ffield_5fmask_2eproto_impl() { + GOOGLE_PROTOBUF_VERIFY_VERSION; + + ::google::protobuf::internal::GetEmptyString(); + FieldMask::default_instance_.DefaultConstruct(); + FieldMask::default_instance_.get_mutable()->InitAsDefaultInstance(); +} + +GOOGLE_PROTOBUF_DECLARE_ONCE(protobuf_InitDefaults_google_2fprotobuf_2ffield_5fmask_2eproto_once_); +void protobuf_InitDefaults_google_2fprotobuf_2ffield_5fmask_2eproto() { + ::google::protobuf::GoogleOnceInit(&protobuf_InitDefaults_google_2fprotobuf_2ffield_5fmask_2eproto_once_, + &protobuf_InitDefaults_google_2fprotobuf_2ffield_5fmask_2eproto_impl); +} +void protobuf_AddDesc_google_2fprotobuf_2ffield_5fmask_2eproto_impl() { GOOGLE_PROTOBUF_VERIFY_VERSION; + protobuf_InitDefaults_google_2fprotobuf_2ffield_5fmask_2eproto(); ::google::protobuf::DescriptorPool::InternalAddGeneratedFile( "\n google/protobuf/field_mask.proto\022\017goog" "le.protobuf\"\032\n\tFieldMask\022\r\n\005paths\030\001 \003(\tB" - "Q\n\023com.google.protobufB\016FieldMaskProtoP\001" - "\240\001\001\242\002\003GPB\252\002\036Google.Protobuf.WellKnownTyp" - "esb\006proto3", 170); + "N\n\023com.google.protobufB\016FieldMaskProtoP\001" + "\242\002\003GPB\252\002\036Google.Protobuf.WellKnownTypesb" + "\006proto3", 167); ::google::protobuf::MessageFactory::InternalRegisterGeneratedFile( "google/protobuf/field_mask.proto", &protobuf_RegisterTypes); - FieldMask::default_instance_ = new FieldMask(); - FieldMask::default_instance_->InitAsDefaultInstance(); ::google::protobuf::internal::OnShutdown(&protobuf_ShutdownFile_google_2fprotobuf_2ffield_5fmask_2eproto); } +GOOGLE_PROTOBUF_DECLARE_ONCE(protobuf_AddDesc_google_2fprotobuf_2ffield_5fmask_2eproto_once_); +void protobuf_AddDesc_google_2fprotobuf_2ffield_5fmask_2eproto() { + ::google::protobuf::GoogleOnceInit(&protobuf_AddDesc_google_2fprotobuf_2ffield_5fmask_2eproto_once_, + &protobuf_AddDesc_google_2fprotobuf_2ffield_5fmask_2eproto_impl); +} // Force AddDescriptors() to be called at static initialization time. struct StaticDescriptorInitializer_google_2fprotobuf_2ffield_5fmask_2eproto { StaticDescriptorInitializer_google_2fprotobuf_2ffield_5fmask_2eproto() { @@ -102,6 +113,16 @@ struct StaticDescriptorInitializer_google_2fprotobuf_2ffield_5fmask_2eproto { } } static_descriptor_initializer_google_2fprotobuf_2ffield_5fmask_2eproto_; +namespace { + +static void MergeFromFail(int line) GOOGLE_ATTRIBUTE_COLD GOOGLE_ATTRIBUTE_NORETURN; +static void MergeFromFail(int line) { + ::google::protobuf::internal::MergeFromFail(__FILE__, line); +} + +} // namespace + + // =================================================================== #if !defined(_MSC_VER) || _MSC_VER >= 1900 @@ -110,25 +131,23 @@ const int FieldMask::kPathsFieldNumber; FieldMask::FieldMask() : ::google::protobuf::Message(), _internal_metadata_(NULL) { + if (this != internal_default_instance()) protobuf_InitDefaults_google_2fprotobuf_2ffield_5fmask_2eproto(); SharedCtor(); // @@protoc_insertion_point(constructor:google.protobuf.FieldMask) } void FieldMask::InitAsDefaultInstance() { - _is_default_instance_ = true; } FieldMask::FieldMask(const FieldMask& from) : ::google::protobuf::Message(), _internal_metadata_(NULL) { SharedCtor(); - MergeFrom(from); + UnsafeMergeFrom(from); // @@protoc_insertion_point(copy_constructor:google.protobuf.FieldMask) } void FieldMask::SharedCtor() { - _is_default_instance_ = false; - ::google::protobuf::internal::GetEmptyString(); _cached_size_ = 0; } @@ -138,8 +157,6 @@ FieldMask::~FieldMask() { } void FieldMask::SharedDtor() { - if (this != default_instance_) { - } } void FieldMask::SetCachedSize(int size) const { @@ -153,11 +170,11 @@ const ::google::protobuf::Descriptor* FieldMask::descriptor() { } const FieldMask& FieldMask::default_instance() { - if (default_instance_ == NULL) protobuf_AddDesc_google_2fprotobuf_2ffield_5fmask_2eproto(); - return *default_instance_; + protobuf_InitDefaults_google_2fprotobuf_2ffield_5fmask_2eproto(); + return *internal_default_instance(); } -FieldMask* FieldMask::default_instance_ = NULL; +::google::protobuf::internal::ExplicitlyConstructed FieldMask::default_instance_; FieldMask* FieldMask::New(::google::protobuf::Arena* arena) const { FieldMask* n = new FieldMask; @@ -256,29 +273,29 @@ void FieldMask::SerializeWithCachedSizes( return target; } -int FieldMask::ByteSize() const { +size_t FieldMask::ByteSizeLong() const { // @@protoc_insertion_point(message_byte_size_start:google.protobuf.FieldMask) - int total_size = 0; + size_t total_size = 0; // repeated string paths = 1; - total_size += 1 * this->paths_size(); + total_size += 1 * + ::google::protobuf::internal::FromIntSize(this->paths_size()); for (int i = 0; i < this->paths_size(); i++) { total_size += ::google::protobuf::internal::WireFormatLite::StringSize( this->paths(i)); } + int cached_size = ::google::protobuf::internal::ToCachedSize(total_size); GOOGLE_SAFE_CONCURRENT_WRITES_BEGIN(); - _cached_size_ = total_size; + _cached_size_ = cached_size; GOOGLE_SAFE_CONCURRENT_WRITES_END(); return total_size; } void FieldMask::MergeFrom(const ::google::protobuf::Message& from) { // @@protoc_insertion_point(generalized_merge_from_start:google.protobuf.FieldMask) - if (GOOGLE_PREDICT_FALSE(&from == this)) { - ::google::protobuf::internal::MergeFromFail(__FILE__, __LINE__); - } - const FieldMask* source = + if (GOOGLE_PREDICT_FALSE(&from == this)) MergeFromFail(__LINE__); + const FieldMask* source = ::google::protobuf::internal::DynamicCastToGenerated( &from); if (source == NULL) { @@ -286,16 +303,22 @@ void FieldMask::MergeFrom(const ::google::protobuf::Message& from) { ::google::protobuf::internal::ReflectionOps::Merge(from, this); } else { // @@protoc_insertion_point(generalized_merge_from_cast_success:google.protobuf.FieldMask) - MergeFrom(*source); + UnsafeMergeFrom(*source); } } void FieldMask::MergeFrom(const FieldMask& from) { // @@protoc_insertion_point(class_specific_merge_from_start:google.protobuf.FieldMask) - if (GOOGLE_PREDICT_FALSE(&from == this)) { - ::google::protobuf::internal::MergeFromFail(__FILE__, __LINE__); + if (GOOGLE_PREDICT_TRUE(&from != this)) { + UnsafeMergeFrom(from); + } else { + MergeFromFail(__LINE__); } - paths_.MergeFrom(from.paths_); +} + +void FieldMask::UnsafeMergeFrom(const FieldMask& from) { + GOOGLE_DCHECK(&from != this); + paths_.UnsafeMergeFrom(from.paths_); } void FieldMask::CopyFrom(const ::google::protobuf::Message& from) { @@ -309,7 +332,7 @@ void FieldMask::CopyFrom(const FieldMask& from) { // @@protoc_insertion_point(class_specific_copy_from_start:google.protobuf.FieldMask) if (&from == this) return; Clear(); - MergeFrom(from); + UnsafeMergeFrom(from); } bool FieldMask::IsInitialized() const { @@ -345,49 +368,49 @@ int FieldMask::paths_size() const { void FieldMask::clear_paths() { paths_.Clear(); } - const ::std::string& FieldMask::paths(int index) const { +const ::std::string& FieldMask::paths(int index) const { // @@protoc_insertion_point(field_get:google.protobuf.FieldMask.paths) return paths_.Get(index); } - ::std::string* FieldMask::mutable_paths(int index) { +::std::string* FieldMask::mutable_paths(int index) { // @@protoc_insertion_point(field_mutable:google.protobuf.FieldMask.paths) return paths_.Mutable(index); } - void FieldMask::set_paths(int index, const ::std::string& value) { +void FieldMask::set_paths(int index, const ::std::string& value) { // @@protoc_insertion_point(field_set:google.protobuf.FieldMask.paths) paths_.Mutable(index)->assign(value); } - void FieldMask::set_paths(int index, const char* value) { +void FieldMask::set_paths(int index, const char* value) { paths_.Mutable(index)->assign(value); // @@protoc_insertion_point(field_set_char:google.protobuf.FieldMask.paths) } - void FieldMask::set_paths(int index, const char* value, size_t size) { +void FieldMask::set_paths(int index, const char* value, size_t size) { paths_.Mutable(index)->assign( reinterpret_cast(value), size); // @@protoc_insertion_point(field_set_pointer:google.protobuf.FieldMask.paths) } - ::std::string* FieldMask::add_paths() { +::std::string* FieldMask::add_paths() { // @@protoc_insertion_point(field_add_mutable:google.protobuf.FieldMask.paths) return paths_.Add(); } - void FieldMask::add_paths(const ::std::string& value) { +void FieldMask::add_paths(const ::std::string& value) { paths_.Add()->assign(value); // @@protoc_insertion_point(field_add:google.protobuf.FieldMask.paths) } - void FieldMask::add_paths(const char* value) { +void FieldMask::add_paths(const char* value) { paths_.Add()->assign(value); // @@protoc_insertion_point(field_add_char:google.protobuf.FieldMask.paths) } - void FieldMask::add_paths(const char* value, size_t size) { +void FieldMask::add_paths(const char* value, size_t size) { paths_.Add()->assign(reinterpret_cast(value), size); // @@protoc_insertion_point(field_add_pointer:google.protobuf.FieldMask.paths) } - const ::google::protobuf::RepeatedPtrField< ::std::string>& +const ::google::protobuf::RepeatedPtrField< ::std::string>& FieldMask::paths() const { // @@protoc_insertion_point(field_list:google.protobuf.FieldMask.paths) return paths_; } - ::google::protobuf::RepeatedPtrField< ::std::string>* +::google::protobuf::RepeatedPtrField< ::std::string>* FieldMask::mutable_paths() { // @@protoc_insertion_point(field_mutable_list:google.protobuf.FieldMask.paths) return &paths_; diff --git a/src/google/protobuf/field_mask.pb.h b/src/google/protobuf/field_mask.pb.h index 460e1338..dd83fca5 100644 --- a/src/google/protobuf/field_mask.pb.h +++ b/src/google/protobuf/field_mask.pb.h @@ -34,6 +34,7 @@ namespace protobuf { // Internal implementation detail -- do not call these. void LIBPROTOBUF_EXPORT protobuf_AddDesc_google_2fprotobuf_2ffield_5fmask_2eproto(); +void LIBPROTOBUF_EXPORT protobuf_InitDefaults_google_2fprotobuf_2ffield_5fmask_2eproto(); void protobuf_AssignDesc_google_2fprotobuf_2ffield_5fmask_2eproto(); void protobuf_ShutdownFile_google_2fprotobuf_2ffield_5fmask_2eproto(); @@ -56,6 +57,10 @@ class LIBPROTOBUF_EXPORT FieldMask : public ::google::protobuf::Message /* @@pro static const ::google::protobuf::Descriptor* descriptor(); static const FieldMask& default_instance(); + static inline const FieldMask* internal_default_instance() { + return &default_instance_.get(); + } + void Swap(FieldMask* other); // implements Message ---------------------------------------------- @@ -70,7 +75,7 @@ class LIBPROTOBUF_EXPORT FieldMask : public ::google::protobuf::Message /* @@pro void Clear(); bool IsInitialized() const; - int ByteSize() const; + size_t ByteSizeLong() const; bool MergePartialFromCodedStream( ::google::protobuf::io::CodedInputStream* input); void SerializeWithCachedSizes( @@ -86,6 +91,7 @@ class LIBPROTOBUF_EXPORT FieldMask : public ::google::protobuf::Message /* @@pro void SharedDtor(); void SetCachedSize(int size) const; void InternalSwap(FieldMask* other); + void UnsafeMergeFrom(const FieldMask& from); private: inline ::google::protobuf::Arena* GetArenaNoVirtual() const { return _internal_metadata_.arena(); @@ -121,15 +127,15 @@ class LIBPROTOBUF_EXPORT FieldMask : public ::google::protobuf::Message /* @@pro private: ::google::protobuf::internal::InternalMetadataWithArena _internal_metadata_; - bool _is_default_instance_; ::google::protobuf::RepeatedPtrField< ::std::string> paths_; mutable int _cached_size_; - friend void LIBPROTOBUF_EXPORT protobuf_AddDesc_google_2fprotobuf_2ffield_5fmask_2eproto(); + friend void LIBPROTOBUF_EXPORT protobuf_InitDefaults_google_2fprotobuf_2ffield_5fmask_2eproto_impl(); + friend void LIBPROTOBUF_EXPORT protobuf_AddDesc_google_2fprotobuf_2ffield_5fmask_2eproto_impl(); friend void protobuf_AssignDesc_google_2fprotobuf_2ffield_5fmask_2eproto(); friend void protobuf_ShutdownFile_google_2fprotobuf_2ffield_5fmask_2eproto(); void InitAsDefaultInstance(); - static FieldMask* default_instance_; + static ::google::protobuf::internal::ExplicitlyConstructed default_instance_; }; // =================================================================== diff --git a/src/google/protobuf/field_mask.proto b/src/google/protobuf/field_mask.proto index c51de09a..b6d32a79 100644 --- a/src/google/protobuf/field_mask.proto +++ b/src/google/protobuf/field_mask.proto @@ -37,7 +37,6 @@ option java_package = "com.google.protobuf"; option java_outer_classname = "FieldMaskProto"; option java_multiple_files = true; option objc_class_prefix = "GPB"; -option java_generate_equals_and_hash = true; // `FieldMask` represents a set of symbolic field paths, for example: // @@ -82,7 +81,7 @@ option java_generate_equals_and_hash = true; // } // // A repeated field is not allowed except at the last position of a -// field mask. +// paths string. // // If a FieldMask object is not present in a get operation, the // operation applies to all fields (as if a FieldMask of all fields @@ -109,8 +108,8 @@ option java_generate_equals_and_hash = true; // // If a repeated field is specified for an update operation, the existing // repeated values in the target resource will be overwritten by the new values. -// Note that a repeated field is only allowed in the last position of a field -// mask. +// Note that a repeated field is only allowed in the last position of a `paths` +// string. // // If a sub-message is specified in the last position of the field mask for an // update operation, then the existing sub-message in the target resource is diff --git a/src/google/protobuf/generated_message_reflection.cc b/src/google/protobuf/generated_message_reflection.cc index d1f7b5ca..6f418433 100644 --- a/src/google/protobuf/generated_message_reflection.cc +++ b/src/google/protobuf/generated_message_reflection.cc @@ -173,62 +173,43 @@ static void ReportReflectionUsageEnumTypeError( // =================================================================== GeneratedMessageReflection::GeneratedMessageReflection( - const Descriptor* descriptor, - const Message* default_instance, - const int offsets[], - int has_bits_offset, - int unknown_fields_offset, - int extensions_offset, - const DescriptorPool* descriptor_pool, - MessageFactory* factory, - int object_size, - int arena_offset, - int is_default_instance_offset) - : descriptor_ (descriptor), - default_instance_ (default_instance), - offsets_ (offsets), - has_bits_offset_ (has_bits_offset), - unknown_fields_offset_(unknown_fields_offset), - extensions_offset_(extensions_offset), - arena_offset_ (arena_offset), - is_default_instance_offset_(is_default_instance_offset), - object_size_ (object_size), - descriptor_pool_ ((descriptor_pool == NULL) ? - DescriptorPool::generated_pool() : - descriptor_pool), - message_factory_ (factory) { -} + const Descriptor* descriptor, const Message* default_instance, + const int offsets[], int has_bits_offset, int unknown_fields_offset, + int extensions_offset, const DescriptorPool* descriptor_pool, + MessageFactory* factory, int object_size, int arena_offset) + : descriptor_(descriptor), + default_instance_(default_instance), + offsets_(offsets), + has_bits_offset_(has_bits_offset), + unknown_fields_offset_(unknown_fields_offset), + extensions_offset_(extensions_offset), + arena_offset_(arena_offset), + object_size_(object_size), + descriptor_pool_((descriptor_pool == NULL) + ? DescriptorPool::generated_pool() + : descriptor_pool), + message_factory_(factory) {} GeneratedMessageReflection::GeneratedMessageReflection( - const Descriptor* descriptor, - const Message* default_instance, - const int offsets[], - int has_bits_offset, - int unknown_fields_offset, - int extensions_offset, - const void* default_oneof_instance, - int oneof_case_offset, - const DescriptorPool* descriptor_pool, - MessageFactory* factory, - int object_size, - int arena_offset, - int is_default_instance_offset) - : descriptor_ (descriptor), - default_instance_ (default_instance), - default_oneof_instance_ (default_oneof_instance), - offsets_ (offsets), - has_bits_offset_ (has_bits_offset), - oneof_case_offset_(oneof_case_offset), - unknown_fields_offset_(unknown_fields_offset), - extensions_offset_(extensions_offset), - arena_offset_ (arena_offset), - is_default_instance_offset_(is_default_instance_offset), - object_size_ (object_size), - descriptor_pool_ ((descriptor_pool == NULL) ? - DescriptorPool::generated_pool() : - descriptor_pool), - message_factory_ (factory) { -} + const Descriptor* descriptor, const Message* default_instance, + const int offsets[], int has_bits_offset, int unknown_fields_offset, + int extensions_offset, const void* default_oneof_instance, + int oneof_case_offset, const DescriptorPool* descriptor_pool, + MessageFactory* factory, int object_size, int arena_offset) + : descriptor_(descriptor), + default_instance_(default_instance), + default_oneof_instance_(default_oneof_instance), + offsets_(offsets), + has_bits_offset_(has_bits_offset), + oneof_case_offset_(oneof_case_offset), + unknown_fields_offset_(unknown_fields_offset), + extensions_offset_(extensions_offset), + arena_offset_(arena_offset), + object_size_(object_size), + descriptor_pool_((descriptor_pool == NULL) + ? DescriptorPool::generated_pool() + : descriptor_pool), + message_factory_(factory) {} GeneratedMessageReflection::~GeneratedMessageReflection() {} @@ -1026,6 +1007,11 @@ struct FieldNumberSorter { return left->number() < right->number(); } }; + +inline bool IsIndexInHasBitSet(const uint32* has_bit_set, uint32 index) { + return ((has_bit_set[index / 32] >> (index % 32)) & static_cast(1)) + != 0; +} } // namespace void GeneratedMessageReflection::ListFields( @@ -1036,6 +1022,12 @@ void GeneratedMessageReflection::ListFields( // Optimization: The default instance never has any fields set. if (&message == default_instance_) return; + // Optimization: Avoid calling GetHasBits() and HasOneofField() many times + // within the field loop. + const uint32* const has_bits = GetHasBits(message); + const uint32* const oneof_case_array = reinterpret_cast( + reinterpret_cast(&message) + oneof_case_offset_); + output->reserve(descriptor_->field_count()); for (int i = 0; i < descriptor_->field_count(); i++) { const FieldDescriptor* field = descriptor_->field(i); @@ -1044,11 +1036,18 @@ void GeneratedMessageReflection::ListFields( output->push_back(field); } } else { - if (field->containing_oneof()) { - if (HasOneofField(message, field)) { + const OneofDescriptor* containing_oneof = field->containing_oneof(); + if (containing_oneof) { + // Equivalent to: HasOneofField(message, field) + if (oneof_case_array[containing_oneof->index()] == field->number()) { output->push_back(field); } - } else if (HasBit(message, field)) { + } else if (has_bits) { + // Equivalent to: HasBit(message, field) + if (IsIndexInHasBitSet(has_bits, i)) { + output->push_back(field); + } + } else if (HasBit(message, field)) { // Fall back on proto3-style HasBit. output->push_back(field); } } @@ -2001,12 +2000,7 @@ GeneratedMessageReflection::MutableInternalMetadataWithArena( inline bool GeneratedMessageReflection::GetIsDefaultInstance( const Message& message) const { - if (is_default_instance_offset_ == kHasNoDefaultInstanceField) { - return false; - } - const void* ptr = reinterpret_cast(&message) + - is_default_instance_offset_; - return *reinterpret_cast(ptr); + return &message == default_instance_; } // Simple accessors for manipulating has_bits_. @@ -2063,8 +2057,7 @@ inline bool GeneratedMessageReflection::HasBit( } } } - return GetHasBits(message)[field->index() / 32] & - (1 << (field->index() % 32)); + return IsIndexInHasBitSet(GetHasBits(message), field->index()); } inline void GeneratedMessageReflection::SetBit( @@ -2072,7 +2065,9 @@ inline void GeneratedMessageReflection::SetBit( if (has_bits_offset_ == -1) { return; } - MutableHasBits(message)[field->index() / 32] |= (1 << (field->index() % 32)); + const uint32 index = static_cast(field->index()); + MutableHasBits(message)[index / 32] |= + (static_cast(1) << (index % 32)); } inline void GeneratedMessageReflection::ClearBit( @@ -2080,7 +2075,9 @@ inline void GeneratedMessageReflection::ClearBit( if (has_bits_offset_ == -1) { return; } - MutableHasBits(message)[field->index() / 32] &= ~(1 << (field->index() % 32)); + const uint32 index = static_cast(field->index()); + MutableHasBits(message)[index / 32] &= + ~(static_cast(1) << (index % 32)); } inline void GeneratedMessageReflection::SwapBit( @@ -2275,19 +2272,11 @@ GeneratedMessageReflection::NewGeneratedMessageReflection( int object_size, int arena_offset, int is_default_instance_offset) { - return new GeneratedMessageReflection(descriptor, - default_instance, - offsets, - has_bits_offset, - unknown_fields_offset, - extensions_offset, - default_oneof_instance, - oneof_case_offset, - DescriptorPool::generated_pool(), - MessageFactory::generated_factory(), - object_size, - arena_offset, - is_default_instance_offset); + return new GeneratedMessageReflection( + descriptor, default_instance, offsets, has_bits_offset, + unknown_fields_offset, extensions_offset, default_oneof_instance, + oneof_case_offset, DescriptorPool::generated_pool(), + MessageFactory::generated_factory(), object_size, arena_offset); } GeneratedMessageReflection* @@ -2301,17 +2290,11 @@ GeneratedMessageReflection::NewGeneratedMessageReflection( int object_size, int arena_offset, int is_default_instance_offset) { - return new GeneratedMessageReflection(descriptor, - default_instance, - offsets, - has_bits_offset, - unknown_fields_offset, - extensions_offset, - DescriptorPool::generated_pool(), - MessageFactory::generated_factory(), - object_size, - arena_offset, - is_default_instance_offset); + return new GeneratedMessageReflection( + descriptor, default_instance, offsets, has_bits_offset, + unknown_fields_offset, extensions_offset, + DescriptorPool::generated_pool(), MessageFactory::generated_factory(), + object_size, arena_offset); } } // namespace internal diff --git a/src/google/protobuf/generated_message_reflection.h b/src/google/protobuf/generated_message_reflection.h index 15fc802c..1413b110 100644 --- a/src/google/protobuf/generated_message_reflection.h +++ b/src/google/protobuf/generated_message_reflection.h @@ -132,15 +132,11 @@ class LIBPROTOBUF_EXPORT GeneratedMessageReflection : public Reflection { // by sizeof(). GeneratedMessageReflection(const Descriptor* descriptor, const Message* default_instance, - const int offsets[], - int has_bits_offset, - int unknown_fields_offset, - int extensions_offset, + const int offsets[], int has_bits_offset, + int unknown_fields_offset, int extensions_offset, const DescriptorPool* pool, - MessageFactory* factory, - int object_size, - int arena_offset, - int is_default_instance_offset = -1); + MessageFactory* factory, int object_size, + int arena_offset); // Similar with the construction above. Call this construction if the // message has oneof definition. @@ -168,17 +164,12 @@ class LIBPROTOBUF_EXPORT GeneratedMessageReflection : public Reflection { // other parameters are the same with the construction above. GeneratedMessageReflection(const Descriptor* descriptor, const Message* default_instance, - const int offsets[], - int has_bits_offset, - int unknown_fields_offset, - int extensions_offset, + const int offsets[], int has_bits_offset, + int unknown_fields_offset, int extensions_offset, const void* default_oneof_instance, - int oneof_case_offset, - const DescriptorPool* pool, - MessageFactory* factory, - int object_size, - int arena_offset, - int is_default_instance_offset = -1); + int oneof_case_offset, const DescriptorPool* pool, + MessageFactory* factory, int object_size, + int arena_offset); ~GeneratedMessageReflection(); // Shorter-to-call helpers for the above two constructions that work if the @@ -226,11 +217,11 @@ class LIBPROTOBUF_EXPORT GeneratedMessageReflection : public Reflection { Message* ReleaseLast(Message* message, const FieldDescriptor* field) const; void Swap(Message* message1, Message* message2) const; void SwapFields(Message* message1, Message* message2, - const vector& fields) const; + const std::vector& fields) const; void SwapElements(Message* message, const FieldDescriptor* field, int index1, int index2) const; void ListFields(const Message& message, - vector* output) const; + std::vector* output) const; int32 GetInt32 (const Message& message, const FieldDescriptor* field) const; @@ -448,11 +439,8 @@ class LIBPROTOBUF_EXPORT GeneratedMessageReflection : public Reflection { int unknown_fields_offset_; int extensions_offset_; int arena_offset_; - int is_default_instance_offset_; int object_size_; - static const int kHasNoDefaultInstanceField = -1; - const DescriptorPool* descriptor_pool_; MessageFactory* message_factory_; diff --git a/src/google/protobuf/generated_message_util.cc b/src/google/protobuf/generated_message_util.cc index 7ad6d61c..73f55927 100644 --- a/src/google/protobuf/generated_message_util.cc +++ b/src/google/protobuf/generated_message_util.cc @@ -48,15 +48,15 @@ double NaN() { return std::numeric_limits::quiet_NaN(); } -const ::std::string* empty_string_; +ExplicitlyConstructed< ::std::string> fixed_address_empty_string; GOOGLE_PROTOBUF_DECLARE_ONCE(empty_string_once_init_); void DeleteEmptyString() { - delete empty_string_; + GetEmptyStringAlreadyInited().~string(); } void InitEmptyString() { - empty_string_ = new string; + fixed_address_empty_string.DefaultConstruct(); OnShutdown(&DeleteEmptyString); } diff --git a/src/google/protobuf/generated_message_util.h b/src/google/protobuf/generated_message_util.h index 8967726e..871acca5 100644 --- a/src/google/protobuf/generated_message_util.h +++ b/src/google/protobuf/generated_message_util.h @@ -43,6 +43,7 @@ #include #include +#include namespace google { @@ -70,22 +71,49 @@ namespace internal { LIBPROTOBUF_EXPORT double Infinity(); LIBPROTOBUF_EXPORT double NaN(); +// This type is used to define a global variable, without it's constructor +// and destructor run on start and end of the program lifetime. This circumvents +// the initial construction order fiasco, while keeping the address of the +// empty string a compile time constant. +template +class ExplicitlyConstructed { + public: + void DefaultConstruct() { + new (&union_) T(); + init_ = true; + } + + bool IsInitialized() { return init_; } + + const T& get() const { return reinterpret_cast(union_); } + T* get_mutable() { return reinterpret_cast(&union_); } + + private: + // Prefer c++14 aligned_storage, but for compatibility this will do. + union AlignedUnion { + char space[sizeof(T)]; + int64 align_to_int64; + void* align_to_ptr; + } union_; + bool init_; // false by linker +}; + // TODO(jieluo): Change to template. We have tried to use template, // but it causes net/rpc/python:rpcutil_test fail (the empty string will // init twice). It may related to swig. Change to template after we // found the solution. -// Default empty string object. Don't use the pointer directly. Instead, call +// Default empty string object. Don't use this directly. Instead, call // GetEmptyString() to get the reference. -LIBPROTOBUF_EXPORT extern const ::std::string* empty_string_; +extern ExplicitlyConstructed< ::std::string> fixed_address_empty_string; LIBPROTOBUF_EXPORT extern ProtobufOnceType empty_string_once_init_; LIBPROTOBUF_EXPORT void InitEmptyString(); LIBPROTOBUF_EXPORT inline const ::std::string& GetEmptyStringAlreadyInited() { - assert(empty_string_ != NULL); - return *empty_string_; + return fixed_address_empty_string.get(); } + LIBPROTOBUF_EXPORT inline const ::std::string& GetEmptyString() { ::google::protobuf::GoogleOnceInit(&empty_string_once_init_, &InitEmptyString); return GetEmptyStringAlreadyInited(); @@ -106,20 +134,28 @@ template bool AllAreInitialized(const Type& t) { return true; } -class ArenaString; - -// Read a length (varint32), followed by a string, from *input. Return a -// pointer to a copy of the string that resides in *arena. Requires both -// args to be non-NULL. If something goes wrong while reading the data -// then NULL is returned (e.g., input does not start with a valid varint). -LIBPROTOBUF_EXPORT ArenaString* ReadArenaString( - ::google::protobuf::io::CodedInputStream* input, - ::google::protobuf::Arena* arena); - // Helper function to crash on merge failure. // Moved out of generated code to reduce binary size. LIBPROTOBUF_EXPORT void MergeFromFail(const char* file, int line) GOOGLE_ATTRIBUTE_NORETURN; +// We compute sizes as size_t but cache them as int. This function converts a +// computed size to a cached size. Since we don't proceed with serialization if +// the total size was > INT_MAX, it is not important what this function returns +// for inputs > INT_MAX. +inline int ToCachedSize(size_t size) { + return static_cast(size); +} + +// We mainly calculate sizes in terms of size_t, but some functions that compute +// sizes return "int". These int sizes are expected to always be positive. +// This function is more efficient than casting an int to size_t directly on +// 64-bit platforms because it avoids making the compiler emit a sign extending +// instruction, which we don't want and don't want to pay for. +inline size_t FromIntSize(int size) { + // Convert to unsigned before widening so sign extension is not necessary. + return static_cast(size); +} + } // namespace internal } // namespace protobuf diff --git a/src/google/protobuf/has_bits.h b/src/google/protobuf/has_bits.h new file mode 100644 index 00000000..133bc02a --- /dev/null +++ b/src/google/protobuf/has_bits.h @@ -0,0 +1,72 @@ +// 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. + +#ifndef GOOGLE_PROTOBUF_HAS_BITS_H__ +#define GOOGLE_PROTOBUF_HAS_BITS_H__ + +#include + +namespace google { +namespace protobuf { +namespace internal { + +template +class HasBits { + public: + HasBits() GOOGLE_ATTRIBUTE_ALWAYS_INLINE { Clear(); } + + void Clear() GOOGLE_ATTRIBUTE_ALWAYS_INLINE { + memset(has_bits_, 0, sizeof(has_bits_)); + } + + ::google::protobuf::uint32& operator[](int index) GOOGLE_ATTRIBUTE_ALWAYS_INLINE { + return has_bits_[index]; + } + + const ::google::protobuf::uint32& operator[](int index) const GOOGLE_ATTRIBUTE_ALWAYS_INLINE { + return has_bits_[index]; + } + + bool operator==(const HasBits& rhs) const { + return memcmp(has_bits_, rhs.has_bits_, sizeof(has_bits_)) == 0; + } + + bool operator!=(const HasBits& rhs) const { + return !(*this == rhs); + } + private: + ::google::protobuf::uint32 has_bits_[doublewords]; +}; + +} // namespace internal +} // namespace protobuf + +} // namespace google +#endif // GOOGLE_PROTOBUF_HAS_BITS_H__ diff --git a/src/google/protobuf/io/coded_stream.cc b/src/google/protobuf/io/coded_stream.cc index a5675e79..08394ca7 100644 --- a/src/google/protobuf/io/coded_stream.cc +++ b/src/google/protobuf/io/coded_stream.cc @@ -47,6 +47,7 @@ #include #include #include +#include namespace google { @@ -902,46 +903,18 @@ bool CodedOutputStream::Refresh() { } } -int CodedOutputStream::VarintSize32Fallback(uint32 value) { +size_t CodedOutputStream::VarintSize32Fallback(uint32 value) { + GOOGLE_DCHECK_NE(0, value); // This is enforced by our caller. + + return 1 + Bits::Log2FloorNonZero(value) / 7; +} + +size_t CodedOutputStream::VarintSize64(uint64 value) { if (value < (1 << 7)) { return 1; - } else if (value < (1 << 14)) { - return 2; - } else if (value < (1 << 21)) { - return 3; - } else if (value < (1 << 28)) { - return 4; - } else { - return 5; } -} -int CodedOutputStream::VarintSize64(uint64 value) { - if (value < (1ull << 35)) { - if (value < (1ull << 7)) { - return 1; - } else if (value < (1ull << 14)) { - return 2; - } else if (value < (1ull << 21)) { - return 3; - } else if (value < (1ull << 28)) { - return 4; - } else { - return 5; - } - } else { - if (value < (1ull << 42)) { - return 6; - } else if (value < (1ull << 49)) { - return 7; - } else if (value < (1ull << 56)) { - return 8; - } else if (value < (1ull << 63)) { - return 9; - } else { - return 10; - } - } + return 1 + Bits::Log2FloorNonZero64(value) / 7; } uint8* CodedOutputStream::WriteStringWithSizeToArray(const string& str, diff --git a/src/google/protobuf/io/coded_stream.h b/src/google/protobuf/io/coded_stream.h index 316da765..1402cc17 100644 --- a/src/google/protobuf/io/coded_stream.h +++ b/src/google/protobuf/io/coded_stream.h @@ -784,17 +784,17 @@ class LIBPROTOBUF_EXPORT CodedOutputStream { uint8* target); // Returns the number of bytes needed to encode the given value as a varint. - static int VarintSize32(uint32 value); + static size_t VarintSize32(uint32 value); // Returns the number of bytes needed to encode the given value as a varint. - static int VarintSize64(uint64 value); + static size_t VarintSize64(uint64 value); // If negative, 10 bytes. Otheriwse, same as VarintSize32(). - static int VarintSize32SignExtended(int32 value); + static size_t VarintSize32SignExtended(int32 value); // Compile-time equivalent of VarintSize32(). template struct StaticVarintSize32 { - static const int value = + static const size_t value = (Value < (1 << 7)) ? 1 : (Value < (1 << 14)) @@ -890,7 +890,7 @@ class LIBPROTOBUF_EXPORT CodedOutputStream { GOOGLE_ATTRIBUTE_ALWAYS_INLINE static uint8* WriteVarint64ToArrayInline( uint64 value, uint8* target); - static int VarintSize32Fallback(uint32 value); + static size_t VarintSize32Fallback(uint32 value); // See above. Other projects may use "friend" to allow them to call this. static void SetDefaultSerializationDeterministic() { @@ -1225,7 +1225,7 @@ inline uint8* CodedOutputStream::WriteTagToArray( return WriteVarint32ToArray(value, target); } -inline int CodedOutputStream::VarintSize32(uint32 value) { +inline size_t CodedOutputStream::VarintSize32(uint32 value) { if (value < (1 << 7)) { return 1; } else { @@ -1233,7 +1233,7 @@ inline int CodedOutputStream::VarintSize32(uint32 value) { } } -inline int CodedOutputStream::VarintSize32SignExtended(int32 value) { +inline size_t CodedOutputStream::VarintSize32SignExtended(int32 value) { if (value < 0) { return 10; // TODO(kenton): Make this a symbolic constant. } else { diff --git a/src/google/protobuf/io/coded_stream_unittest.cc b/src/google/protobuf/io/coded_stream_unittest.cc index a8108e45..9f1ebc3f 100644 --- a/src/google/protobuf/io/coded_stream_unittest.cc +++ b/src/google/protobuf/io/coded_stream_unittest.cc @@ -58,6 +58,7 @@ #define ULL(x) GOOGLE_ULONGLONG(x) namespace google { + namespace protobuf { namespace io { namespace { diff --git a/src/google/protobuf/io/zero_copy_stream_impl.h b/src/google/protobuf/io/zero_copy_stream_impl.h index 0746fa6a..3365790e 100644 --- a/src/google/protobuf/io/zero_copy_stream_impl.h +++ b/src/google/protobuf/io/zero_copy_stream_impl.h @@ -218,7 +218,7 @@ class LIBPROTOBUF_EXPORT IstreamInputStream : public ZeroCopyInputStream { // If a block_size is given, it specifies the number of bytes that // should be read and returned with each call to Next(). Otherwise, // a reasonable default is used. - explicit IstreamInputStream(istream* stream, int block_size = -1); + explicit IstreamInputStream(std::istream* stream, int block_size = -1); ~IstreamInputStream(); // implements ZeroCopyInputStream ---------------------------------- @@ -230,7 +230,7 @@ class LIBPROTOBUF_EXPORT IstreamInputStream : public ZeroCopyInputStream { private: class LIBPROTOBUF_EXPORT CopyingIstreamInputStream : public CopyingInputStream { public: - CopyingIstreamInputStream(istream* input); + CopyingIstreamInputStream(std::istream* input); ~CopyingIstreamInputStream(); // implements CopyingInputStream --------------------------------- @@ -239,7 +239,7 @@ class LIBPROTOBUF_EXPORT IstreamInputStream : public ZeroCopyInputStream { private: // The stream. - istream* input_; + std::istream* input_; GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(CopyingIstreamInputStream); }; @@ -262,7 +262,7 @@ class LIBPROTOBUF_EXPORT OstreamOutputStream : public ZeroCopyOutputStream { // If a block_size is given, it specifies the size of the buffers // that should be returned by Next(). Otherwise, a reasonable default // is used. - explicit OstreamOutputStream(ostream* stream, int block_size = -1); + explicit OstreamOutputStream(std::ostream* stream, int block_size = -1); ~OstreamOutputStream(); // implements ZeroCopyOutputStream --------------------------------- @@ -273,7 +273,7 @@ class LIBPROTOBUF_EXPORT OstreamOutputStream : public ZeroCopyOutputStream { private: class LIBPROTOBUF_EXPORT CopyingOstreamOutputStream : public CopyingOutputStream { public: - CopyingOstreamOutputStream(ostream* output); + CopyingOstreamOutputStream(std::ostream* output); ~CopyingOstreamOutputStream(); // implements CopyingOutputStream -------------------------------- @@ -281,7 +281,7 @@ class LIBPROTOBUF_EXPORT OstreamOutputStream : public ZeroCopyOutputStream { private: // The stream. - ostream* output_; + std::ostream* output_; GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(CopyingOstreamOutputStream); }; diff --git a/src/google/protobuf/map.h b/src/google/protobuf/map.h index bfc63b0f..2d295510 100644 --- a/src/google/protobuf/map.h +++ b/src/google/protobuf/map.h @@ -565,7 +565,7 @@ class Map { void Init() { if (old_style_) deprecated_elements_ = Arena::Create( - arena_, 0, hasher(), equal_to(), + arena_, 0, hasher(), std::equal_to(), MapAllocator*> >(arena_)); else elements_ = @@ -596,7 +596,7 @@ class Map { // If arena is not given, malloc needs to be called which doesn't // construct element object. if (arena_ == NULL) { - return reinterpret_cast(malloc(n * sizeof(value_type))); + return static_cast(::operator new(n * sizeof(value_type))); } else { return reinterpret_cast( Arena::CreateArray(arena_, n * sizeof(value_type))); @@ -605,7 +605,11 @@ class Map { void deallocate(pointer p, size_type n) { if (arena_ == NULL) { - free(p); +#if defined(__GXX_DELETE_WITH_SIZE__) || defined(__cpp_sized_deallocation) + ::operator delete(p, n * sizeof(value_type)); +#else + ::operator delete(p); +#endif } } @@ -1351,7 +1355,7 @@ class Map { GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(InnerMap); }; // end of class InnerMap - typedef hash_map, equal_to, + typedef hash_map, std::equal_to, MapAllocator*> > > DeprecatedInnerMap; diff --git a/src/google/protobuf/map_entry.h b/src/google/protobuf/map_entry.h index e87eda64..abcd4529 100644 --- a/src/google/protobuf/map_entry.h +++ b/src/google/protobuf/map_entry.h @@ -158,8 +158,8 @@ class MapEntry : public MapEntryBase { return entry_lite_.MergePartialFromCodedStream(input); } - int ByteSize() const { - return entry_lite_.ByteSize(); + size_t ByteSizeLong() const { + return entry_lite_.ByteSizeLong(); } void SerializeWithCachedSizes(::google::protobuf::io::CodedOutputStream* output) const { diff --git a/src/google/protobuf/map_entry_lite.h b/src/google/protobuf/map_entry_lite.h index 4dedfd57..3fb58220 100644 --- a/src/google/protobuf/map_entry_lite.h +++ b/src/google/protobuf/map_entry_lite.h @@ -119,7 +119,7 @@ class MapEntryLite : public MessageLite { kKeyFieldNumber, KeyTypeHandler::kWireType); static const uint8 kValueTag = GOOGLE_PROTOBUF_WIRE_FORMAT_MAKE_TAG( kValueFieldNumber, ValueTypeHandler::kWireType); - static const int kTagSize = 1; + static const size_t kTagSize = 1; public: ~MapEntryLite() { @@ -201,8 +201,8 @@ class MapEntryLite : public MessageLite { } } - int ByteSize() const { - int size = 0; + size_t ByteSizeLong() const { + size_t size = 0; size += has_key() ? kTagSize + KeyTypeHandler::ByteSize(key()) : 0; size += has_value() ? kTagSize + ValueTypeHandler::ByteSize(value()) : 0; return size; diff --git a/src/google/protobuf/map_type_handler.h b/src/google/protobuf/map_type_handler.h index 685a770f..a21c92d9 100644 --- a/src/google/protobuf/map_type_handler.h +++ b/src/google/protobuf/map_type_handler.h @@ -158,7 +158,7 @@ class MapTypeHandler { MapWireFieldTypeTraits::kIsEnum; // Functions used in parsing and serialization. =================== - static inline int ByteSize(const MapEntryAccessorType& value); + static inline size_t ByteSize(const MapEntryAccessorType& value); static inline int GetCachedSize(const MapEntryAccessorType& value); static inline bool Read(io::CodedInputStream* input, MapEntryAccessorType* value); @@ -276,7 +276,7 @@ MAP_HANDLER(BOOL) #undef MAP_HANDLER template -inline int +inline size_t MapTypeHandler::ByteSize( const MapEntryAccessorType& value) { return WireFormatLite::MessageSizeNoVirtual(value); diff --git a/src/google/protobuf/message.cc b/src/google/protobuf/message.cc index f18077dd..c8de458c 100644 --- a/src/google/protobuf/message.cc +++ b/src/google/protobuf/message.cc @@ -46,9 +46,9 @@ #include #include #include -#include #include #include +#include #include #include #include @@ -146,9 +146,9 @@ void Message::SerializeWithCachedSizes( WireFormat::SerializeWithCachedSizes(*this, GetCachedSize(), output); } -int Message::ByteSize() const { - int size = WireFormat::ByteSize(*this); - SetCachedSize(size); +size_t Message::ByteSizeLong() const { + size_t size = WireFormat::ByteSize(*this); + SetCachedSize(internal::ToCachedSize(size)); return size; } @@ -299,8 +299,8 @@ class GeneratedMessageFactory : public MessageFactory { hash_map, streq> file_map_; - // Initialized lazily, so requires locking. Mutex mutex_; + // Initialized lazily, so requires locking. hash_map type_map_; }; diff --git a/src/google/protobuf/message.h b/src/google/protobuf/message.h index 9705e97e..bee25f77 100644 --- a/src/google/protobuf/message.h +++ b/src/google/protobuf/message.h @@ -271,10 +271,10 @@ class LIBPROTOBUF_EXPORT Message : public MessageLite { bool ParsePartialFromFileDescriptor(int file_descriptor); // Parse a protocol buffer from a C++ istream. If successful, the entire // input will be consumed. - bool ParseFromIstream(istream* input); + bool ParseFromIstream(std::istream* input); // Like ParseFromIstream(), but accepts messages that are missing // required fields. - bool ParsePartialFromIstream(istream* input); + bool ParsePartialFromIstream(std::istream* input); // Serialize the message and write it to the given file descriptor. All // required fields must be set. @@ -283,9 +283,9 @@ class LIBPROTOBUF_EXPORT Message : public MessageLite { bool SerializePartialToFileDescriptor(int file_descriptor) const; // Serialize the message and write it to the given C++ ostream. All // required fields must be set. - bool SerializeToOstream(ostream* output) const; + bool SerializeToOstream(std::ostream* output) const; // Like SerializeToOstream(), but allows missing required fields. - bool SerializePartialToOstream(ostream* output) const; + bool SerializePartialToOstream(std::ostream* output) const; // Reflection-based methods ---------------------------------------- @@ -297,7 +297,7 @@ class LIBPROTOBUF_EXPORT Message : public MessageLite { virtual bool IsInitialized() const; virtual void CheckTypeAndMergeFrom(const MessageLite& other); virtual bool MergePartialFromCodedStream(io::CodedInputStream* input); - virtual int ByteSize() const; + virtual size_t ByteSizeLong() const; virtual void SerializeWithCachedSizes(io::CodedOutputStream* output) const; private: diff --git a/src/google/protobuf/message_lite.cc b/src/google/protobuf/message_lite.cc index ba56db95..9d6da264 100644 --- a/src/google/protobuf/message_lite.cc +++ b/src/google/protobuf/message_lite.cc @@ -33,8 +33,9 @@ // Based on original Protocol Buffers design by // Sanjay Ghemawat, Jeff Dean, and others. -#include #include +#include +#include #include #include #include @@ -58,9 +59,9 @@ namespace { // protobuf implementation but is more likely caused by concurrent modification // of the message. This function attempts to distinguish between the two and // provide a useful error message. -void ByteSizeConsistencyError(int byte_size_before_serialization, - int byte_size_after_serialization, - int bytes_produced_by_serialization, +void ByteSizeConsistencyError(size_t byte_size_before_serialization, + size_t byte_size_after_serialization, + size_t bytes_produced_by_serialization, const MessageLite& message) { GOOGLE_CHECK_EQ(byte_size_before_serialization, byte_size_after_serialization) << message.GetTypeName() @@ -236,12 +237,15 @@ bool MessageLite::SerializeToCodedStream(io::CodedOutputStream* output) const { return SerializePartialToCodedStream(output); } +size_t MessageLite::ByteSizeLong() const { + return internal::FromIntSize(ByteSize()); +} + bool MessageLite::SerializePartialToCodedStream( io::CodedOutputStream* output) const { - const int size = ByteSize(); // Force size to be cached. - if (size < 0) { - // Messages >2G cannot be serialized due to overflow computing ByteSize. - GOOGLE_LOG(ERROR) << "Error computing ByteSize (possible overflow?)."; + const size_t size = ByteSizeLong(); // Force size to be cached. + if (size > INT_MAX) { + GOOGLE_LOG(ERROR) << "Exceeded maximum protobuf size of 2GB."; return false; } @@ -249,7 +253,7 @@ bool MessageLite::SerializePartialToCodedStream( if (buffer != NULL) { uint8* end = SerializeWithCachedSizesToArray(buffer); if (end - buffer != size) { - ByteSizeConsistencyError(size, ByteSize(), end - buffer, *this); + ByteSizeConsistencyError(size, ByteSizeLong(), end - buffer, *this); } return true; } else { @@ -261,7 +265,7 @@ bool MessageLite::SerializePartialToCodedStream( int final_byte_count = output->ByteCount(); if (final_byte_count - original_byte_count != size) { - ByteSizeConsistencyError(size, ByteSize(), + ByteSizeConsistencyError(size, ByteSizeLong(), final_byte_count - original_byte_count, *this); } @@ -287,11 +291,10 @@ bool MessageLite::AppendToString(string* output) const { } bool MessageLite::AppendPartialToString(string* output) const { - int old_size = output->size(); - int byte_size = ByteSize(); - if (byte_size < 0) { - // Messages >2G cannot be serialized due to overflow computing ByteSize. - GOOGLE_LOG(ERROR) << "Error computing ByteSize (possible overflow?)."; + size_t old_size = output->size(); + size_t byte_size = ByteSizeLong(); + if (byte_size > INT_MAX) { + GOOGLE_LOG(ERROR) << "Exceeded maximum protobuf size of 2GB."; return false; } @@ -300,7 +303,7 @@ bool MessageLite::AppendPartialToString(string* output) const { reinterpret_cast(io::mutable_string_data(output) + old_size); uint8* end = SerializeWithCachedSizesToArray(start); if (end - start != byte_size) { - ByteSizeConsistencyError(byte_size, ByteSize(), end - start, *this); + ByteSizeConsistencyError(byte_size, ByteSizeLong(), end - start, *this); } return true; } @@ -321,12 +324,12 @@ bool MessageLite::SerializeToArray(void* data, int size) const { } bool MessageLite::SerializePartialToArray(void* data, int size) const { - int byte_size = ByteSize(); + int byte_size = ByteSizeLong(); if (size < byte_size) return false; uint8* start = reinterpret_cast(data); uint8* end = SerializeWithCachedSizesToArray(start); if (end - start != byte_size) { - ByteSizeConsistencyError(byte_size, ByteSize(), end - start, *this); + ByteSizeConsistencyError(byte_size, ByteSizeLong(), end - start, *this); } return true; } diff --git a/src/google/protobuf/message_lite.h b/src/google/protobuf/message_lite.h index 2bdfe496..d3c3b1f0 100644 --- a/src/google/protobuf/message_lite.h +++ b/src/google/protobuf/message_lite.h @@ -239,12 +239,13 @@ class LIBPROTOBUF_EXPORT MessageLite { bool AppendPartialToString(string* output) const; // Computes the serialized size of the message. This recursively calls - // ByteSize() on all embedded messages. If a subclass does not override - // this, it MUST override SetCachedSize(). + // ByteSize() on all embedded messages. Subclasses MUST override either + // ByteSize() or ByteSizeLong() (overriding both is fine). // // ByteSize() is generally linear in the number of fields defined for the // proto. - virtual int ByteSize() const = 0; + virtual int ByteSize() const { return ByteSizeLong(); } + virtual size_t ByteSizeLong() const; // Serializes the message without recomputing the size. The message must // not have changed since the last call to ByteSize(); if it has, the results diff --git a/src/google/protobuf/message_unittest.cc b/src/google/protobuf/message_unittest.cc index d668a1a6..3af05808 100644 --- a/src/google/protobuf/message_unittest.cc +++ b/src/google/protobuf/message_unittest.cc @@ -265,6 +265,24 @@ TEST(MessageTest, CheckOverflow) { EXPECT_FALSE(message.AppendToCord(&serialized)); } +TEST(MessageTest, CheckBigOverflow) { + unittest::TestAllTypes message; + // Create a message with size just over 4GB. We should be able to detect this + // too, even though it will make a plain "int" wrap back to a positive number. + const string data(1024, 'x'); + Cord one_megabyte; + for (int i = 0; i < 1024; i++) { + one_megabyte.Append(data); + } + + for (int i = 0; i < 4 * 1024 + 1; ++i) { + message.add_repeated_cord()->CopyFrom(one_megabyte); + } + + Cord serialized; + EXPECT_FALSE(message.AppendToCord(&serialized)); +} + #endif // PROTOBUF_HAS_DEATH_TEST namespace { @@ -272,6 +290,12 @@ namespace { class NegativeByteSize : public unittest::TestRequired { public: virtual int ByteSize() const { return -1; } + + // The implementation of ByteSizeLong() from MessageLite, to simulate what + // would happen if TestRequired *hadn't* overridden it already. + virtual size_t ByteSizeLong() const { + return static_cast(ByteSize()); + } }; } // namespace @@ -319,6 +343,18 @@ TEST(MessageTest, ParseFailsOnInvalidMessageEnd) { EXPECT_FALSE(message.ParseFromArray("\014", 1)); } +// Regression test for b/23630858 +TEST(MessageTest, MessageIsStillValidAfterParseFails) { + unittest::TestAllTypes message; + + // 9 0xFFs for the "optional_uint64" field. + string invalid_data = "\x20\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF"; + + EXPECT_FALSE(message.ParseFromString(invalid_data)); + message.Clear(); + EXPECT_EQ(0, message.optional_uint64()); +} + namespace { void ExpectMessageMerged(const unittest::TestAllTypes& message) { diff --git a/src/google/protobuf/metadata.h b/src/google/protobuf/metadata.h index fdee150b..6e3eef63 100644 --- a/src/google/protobuf/metadata.h +++ b/src/google/protobuf/metadata.h @@ -152,10 +152,6 @@ class LIBPROTOBUF_EXPORT InternalMetadataWithArena { } }; -// Temporary compatibility typedef. Remove once this is released in components -// and upb CL is submitted. -typedef InternalMetadataWithArena InternalMetadata; - } // namespace internal } // namespace protobuf diff --git a/src/google/protobuf/reflection.h b/src/google/protobuf/reflection.h index 2391f453..d5a6653c 100755 --- a/src/google/protobuf/reflection.h +++ b/src/google/protobuf/reflection.h @@ -80,6 +80,12 @@ class RepeatedFieldRef< typedef IteratorType iterator; typedef IteratorType const_iterator; + typedef T value_type; + typedef T& reference; + typedef const T& const_reference; + typedef int size_type; + typedef ptrdiff_t difference_type; + iterator begin() const { return iterator(data_, accessor_, true); } @@ -202,11 +208,18 @@ class RepeatedFieldRef< typedef IteratorType iterator; typedef IteratorType const_iterator; + typedef T value_type; + typedef T& reference; + typedef const T& const_reference; + typedef int size_type; + typedef ptrdiff_t difference_type; + iterator begin() const { return iterator(data_, accessor_, true, NewMessage()); } iterator end() const { - return iterator(data_, accessor_, false, NewMessage()); + // The end iterator must not be dereferenced, no need for scratch space. + return iterator(data_, accessor_, false, NULL); } private: @@ -428,13 +441,13 @@ class RepeatedFieldRefIterator public: // Constructor for non-message fields. RepeatedFieldRefIterator(const void* data, - const RepeatedFieldAccessor* accessor, - bool begin) - : data_(data), accessor_(accessor), - iterator_(begin ? accessor->BeginIterator(data) : - accessor->EndIterator(data)), - scratch_space_(new AccessorValueType) { - } + const RepeatedFieldAccessor* accessor, bool begin) + : data_(data), + accessor_(accessor), + iterator_(begin ? accessor->BeginIterator(data) + : accessor->EndIterator(data)), + // The end iterator must not be dereferenced, no need for scratch space. + scratch_space_(begin ? new AccessorValueType : NULL) {} // Constructor for message fields. RepeatedFieldRefIterator(const void* data, const RepeatedFieldAccessor* accessor, diff --git a/src/google/protobuf/reflection_ops.h b/src/google/protobuf/reflection_ops.h index 4775911e..45d8c650 100644 --- a/src/google/protobuf/reflection_ops.h +++ b/src/google/protobuf/reflection_ops.h @@ -67,7 +67,7 @@ class LIBPROTOBUF_EXPORT ReflectionOps { // the front of each name. static void FindInitializationErrors(const Message& message, const string& prefix, - vector* errors); + std::vector* errors); private: // All methods are static. No need to construct. diff --git a/src/google/protobuf/repeated_field.cc b/src/google/protobuf/repeated_field.cc index 77004f59..5ca964c1 100644 --- a/src/google/protobuf/repeated_field.cc +++ b/src/google/protobuf/repeated_field.cc @@ -58,14 +58,16 @@ void** RepeatedPtrFieldBase::InternalExtend(int extend_amount) { (std::numeric_limits::max() - kRepHeaderSize) / sizeof(old_rep->elements[0])) << "Requested size is too large to fit into size_t."; + size_t bytes = kRepHeaderSize + sizeof(old_rep->elements[0]) * new_size; if (arena == NULL) { - rep_ = reinterpret_cast( - new char[kRepHeaderSize + sizeof(old_rep->elements[0]) * new_size]); + rep_ = reinterpret_cast(::operator new(bytes)); } else { rep_ = reinterpret_cast( - ::google::protobuf::Arena::CreateArray(arena, - kRepHeaderSize + sizeof(old_rep->elements[0]) * new_size)); + ::google::protobuf::Arena::CreateArray(arena, bytes)); } +#if defined(__GXX_DELETE_WITH_SIZE__) || defined(__cpp_sized_deallocation) + const int old_total_size = total_size_; +#endif total_size_ = new_size; if (old_rep && old_rep->allocated_size > 0) { memcpy(rep_->elements, old_rep->elements, @@ -75,7 +77,13 @@ void** RepeatedPtrFieldBase::InternalExtend(int extend_amount) { rep_->allocated_size = 0; } if (arena == NULL) { - delete [] reinterpret_cast(old_rep); +#if defined(__GXX_DELETE_WITH_SIZE__) || defined(__cpp_sized_deallocation) + const size_t old_size = + old_total_size * sizeof(rep_->elements[0]) + kRepHeaderSize; + ::operator delete(static_cast(old_rep), old_size); +#else + ::operator delete(static_cast(old_rep)); +#endif } return &rep_->elements[current_size_]; } diff --git a/src/google/protobuf/repeated_field.h b/src/google/protobuf/repeated_field.h index bc567555..0a41495f 100644 --- a/src/google/protobuf/repeated_field.h +++ b/src/google/protobuf/repeated_field.h @@ -120,6 +120,10 @@ class RepeatedField { const Element& Get(int index) const; Element* Mutable(int index); + + const Element& operator[](int index) const { return Get(index); } + Element& operator[](int index) { return *Mutable(index); } + void Set(int index, const Element& value); void Add(const Element& value); Element* Add(); @@ -134,6 +138,7 @@ class RepeatedField { void Clear(); void MergeFrom(const RepeatedField& other); + void UnsafeMergeFrom(const RepeatedField& other); void CopyFrom(const RepeatedField& other); // Reserve space to expand the field to at least the given size. If the @@ -284,7 +289,12 @@ class RepeatedField { e->Element::~Element(); } if (rep->arena == NULL) { - delete[] reinterpret_cast(rep); +#if defined(__GXX_DELETE_WITH_SIZE__) || defined(__cpp_sized_deallocation) + const size_t bytes = size * sizeof(*e) + kRepHeaderSize; + ::operator delete(static_cast(rep), bytes); +#else + ::operator delete(static_cast(rep)); +#endif } } } @@ -742,6 +752,9 @@ class RepeatedPtrField : public internal::RepeatedPtrFieldBase { Element* Mutable(int index); Element* Add(); + const Element& operator[](int index) const { return Get(index); } + Element& operator[](int index) { return *Mutable(index); } + // Remove the last element in the array. // Ownership of the element is retained by the array. void RemoveLast(); @@ -753,6 +766,7 @@ class RepeatedPtrField : public internal::RepeatedPtrFieldBase { void Clear(); void MergeFrom(const RepeatedPtrField& other); + void UnsafeMergeFrom(const RepeatedPtrField& other) { MergeFrom(other); } void CopyFrom(const RepeatedPtrField& other); // Reserve space to expand the field to at least the given size. This only @@ -1138,8 +1152,7 @@ inline void RepeatedField::Clear() { } template -inline void RepeatedField::MergeFrom(const RepeatedField& other) { - GOOGLE_CHECK_NE(&other, this); +inline void RepeatedField::UnsafeMergeFrom(const RepeatedField& other) { if (other.current_size_ != 0) { Reserve(current_size_ + other.current_size_); CopyArray(rep_->elements + current_size_, @@ -1148,6 +1161,12 @@ inline void RepeatedField::MergeFrom(const RepeatedField& other) { } } +template +inline void RepeatedField::MergeFrom(const RepeatedField& other) { + GOOGLE_CHECK_NE(&other, this); + UnsafeMergeFrom(other); +} + template inline void RepeatedField::CopyFrom(const RepeatedField& other) { if (&other == this) return; @@ -1265,13 +1284,12 @@ void RepeatedField::Reserve(int new_size) { (std::numeric_limits::max() - kRepHeaderSize) / sizeof(Element)) << "Requested size is too large to fit into size_t."; + size_t bytes = kRepHeaderSize + sizeof(Element) * new_size; if (arena == NULL) { - rep_ = reinterpret_cast( - new char[kRepHeaderSize + sizeof(Element) * new_size]); + rep_ = static_cast(::operator new(bytes)); } else { rep_ = reinterpret_cast( - ::google::protobuf::Arena::CreateArray(arena, - kRepHeaderSize + sizeof(Element) * new_size)); + ::google::protobuf::Arena::CreateArray(arena, bytes)); } rep_->arena = arena; int old_total_size = total_size_; @@ -1363,7 +1381,12 @@ void RepeatedPtrFieldBase::Destroy() { for (int i = 0; i < n; i++) { TypeHandler::Delete(cast(elements[i]), NULL); } - delete[] reinterpret_cast(rep_); +#if defined(__GXX_DELETE_WITH_SIZE__) || defined(__cpp_sized_deallocation) + const size_t size = total_size_ * sizeof(elements[0]) + kRepHeaderSize; + ::operator delete(static_cast(rep_), size); +#else + ::operator delete(static_cast(rep_)); +#endif } rep_ = NULL; } diff --git a/src/google/protobuf/repeated_field_unittest.cc b/src/google/protobuf/repeated_field_unittest.cc index 39b24b33..33547146 100644 --- a/src/google/protobuf/repeated_field_unittest.cc +++ b/src/google/protobuf/repeated_field_unittest.cc @@ -95,7 +95,7 @@ TEST(RepeatedField, Small) { EXPECT_EQ(field.size(), 0); // Additional bytes are for 'struct Rep' header. int expected_usage = 4 * sizeof(int) + sizeof(Arena*); - EXPECT_EQ(field.SpaceUsedExcludingSelf(), expected_usage); + EXPECT_GE(field.SpaceUsedExcludingSelf(), expected_usage); } @@ -207,7 +207,7 @@ TEST(RepeatedField, ReserveMoreThanDouble) { RepeatedField field; field.Reserve(20); - EXPECT_EQ(20, ReservedSpace(&field)); + EXPECT_LE(20, ReservedSpace(&field)); } TEST(RepeatedField, ReserveLessThanDouble) { @@ -215,9 +215,10 @@ TEST(RepeatedField, ReserveLessThanDouble) { // field to grow by double instead. RepeatedField field; field.Reserve(20); - field.Reserve(30); + int capacity = field.Capacity(); + field.Reserve(capacity * 1.5); - EXPECT_EQ(40, ReservedSpace(&field)); + EXPECT_LE(2 * capacity, ReservedSpace(&field)); } TEST(RepeatedField, ReserveLessThanExisting) { @@ -229,7 +230,7 @@ TEST(RepeatedField, ReserveLessThanExisting) { field.Reserve(10); EXPECT_EQ(previous_ptr, field.data()); - EXPECT_EQ(20, ReservedSpace(&field)); + EXPECT_LE(20, ReservedSpace(&field)); } TEST(RepeatedField, Resize) { @@ -397,6 +398,16 @@ TEST(RepeatedField, MutableDataIsMutable) { EXPECT_EQ(2, field.Get(0)); } +TEST(RepeatedField, SubscriptOperators) { + RepeatedField field; + field.Add(1); + EXPECT_EQ(1, field.Get(0)); + EXPECT_EQ(1, field[0]); + EXPECT_EQ(field.Mutable(0), &field[0]); + const RepeatedField& const_field = field; + EXPECT_EQ(field.data(), &const_field[0]); +} + TEST(RepeatedField, Truncate) { RepeatedField field; @@ -470,11 +481,11 @@ TEST(RepeatedField, ClearThenReserveMore) { EXPECT_EQ(32, field.size()); field.Clear(); EXPECT_EQ(0, field.size()); - EXPECT_EQ(32, field.Capacity()); + EXPECT_LE(32, field.Capacity()); field.Reserve(1024); EXPECT_EQ(0, field.size()); - EXPECT_EQ(1024, field.Capacity()); + EXPECT_LE(1024, field.Capacity()); // Finish test -- |field| should destroy the cleared-but-not-yet-destroyed // strings. } @@ -629,15 +640,18 @@ TEST(RepeatedPtrField, ReserveMoreThanDouble) { RepeatedPtrField field; field.Reserve(20); - EXPECT_EQ(20, ReservedSpace(&field)); + EXPECT_LE(20, ReservedSpace(&field)); } TEST(RepeatedPtrField, ReserveLessThanDouble) { RepeatedPtrField field; field.Reserve(20); - field.Reserve(30); - EXPECT_EQ(40, ReservedSpace(&field)); + int capacity = field.Capacity(); + // Grow by 1.5x + field.Reserve(capacity + (capacity >> 2)); + + EXPECT_LE(2 * capacity, ReservedSpace(&field)); } TEST(RepeatedPtrField, ReserveLessThanExisting) { @@ -647,7 +661,7 @@ TEST(RepeatedPtrField, ReserveLessThanExisting) { field.Reserve(10); EXPECT_EQ(previous_ptr, field.data()); - EXPECT_EQ(20, ReservedSpace(&field)); + EXPECT_LE(20, ReservedSpace(&field)); } TEST(RepeatedPtrField, ReserveDoesntLoseAllocated) { @@ -918,6 +932,16 @@ TEST(RepeatedPtrField, MutableDataIsMutable) { EXPECT_EQ("2", field.Get(0)); } +TEST(RepeatedPtrField, SubscriptOperators) { + RepeatedPtrField field; + *field.Add() = "1"; + EXPECT_EQ("1", field.Get(0)); + EXPECT_EQ("1", field[0]); + EXPECT_EQ(field.Mutable(0), &field[0]); + const RepeatedPtrField& const_field = field; + EXPECT_EQ(*field.data(), &const_field[0]); +} + TEST(RepeatedPtrField, ExtractSubrange) { // Exhaustively test every subrange in arrays of all sizes from 0 through 9 // with 0 through 3 cleared elements at the end. diff --git a/src/google/protobuf/source_context.pb.cc b/src/google/protobuf/source_context.pb.cc index 019ccf15..195a5d49 100644 --- a/src/google/protobuf/source_context.pb.cc +++ b/src/google/protobuf/source_context.pb.cc @@ -43,20 +43,19 @@ void protobuf_AssignDesc_google_2fprotobuf_2fsource_5fcontext_2eproto() { SourceContext_reflection_ = ::google::protobuf::internal::GeneratedMessageReflection::NewGeneratedMessageReflection( SourceContext_descriptor_, - SourceContext::default_instance_, + SourceContext::internal_default_instance(), SourceContext_offsets_, -1, -1, -1, sizeof(SourceContext), - GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(SourceContext, _internal_metadata_), - GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(SourceContext, _is_default_instance_)); + GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(SourceContext, _internal_metadata_)); } namespace { GOOGLE_PROTOBUF_DECLARE_ONCE(protobuf_AssignDescriptors_once_); -inline void protobuf_AssignDescriptorsOnce() { +void protobuf_AssignDescriptorsOnce() { ::google::protobuf::GoogleOnceInit(&protobuf_AssignDescriptors_once_, &protobuf_AssignDesc_google_2fprotobuf_2fsource_5fcontext_2eproto); } @@ -65,36 +64,48 @@ void protobuf_RegisterTypes(const ::std::string&) GOOGLE_ATTRIBUTE_COLD; void protobuf_RegisterTypes(const ::std::string&) { protobuf_AssignDescriptorsOnce(); ::google::protobuf::MessageFactory::InternalRegisterGeneratedMessage( - SourceContext_descriptor_, &SourceContext::default_instance()); + SourceContext_descriptor_, SourceContext::internal_default_instance()); } } // namespace void protobuf_ShutdownFile_google_2fprotobuf_2fsource_5fcontext_2eproto() { - delete SourceContext::default_instance_; delete SourceContext_reflection_; } -void protobuf_AddDesc_google_2fprotobuf_2fsource_5fcontext_2eproto() GOOGLE_ATTRIBUTE_COLD; -void protobuf_AddDesc_google_2fprotobuf_2fsource_5fcontext_2eproto() { - static bool already_here = false; - if (already_here) return; - already_here = true; +void protobuf_InitDefaults_google_2fprotobuf_2fsource_5fcontext_2eproto_impl() { + GOOGLE_PROTOBUF_VERIFY_VERSION; + + ::google::protobuf::internal::GetEmptyString(); + SourceContext::default_instance_.DefaultConstruct(); + SourceContext::default_instance_.get_mutable()->InitAsDefaultInstance(); +} + +GOOGLE_PROTOBUF_DECLARE_ONCE(protobuf_InitDefaults_google_2fprotobuf_2fsource_5fcontext_2eproto_once_); +void protobuf_InitDefaults_google_2fprotobuf_2fsource_5fcontext_2eproto() { + ::google::protobuf::GoogleOnceInit(&protobuf_InitDefaults_google_2fprotobuf_2fsource_5fcontext_2eproto_once_, + &protobuf_InitDefaults_google_2fprotobuf_2fsource_5fcontext_2eproto_impl); +} +void protobuf_AddDesc_google_2fprotobuf_2fsource_5fcontext_2eproto_impl() { GOOGLE_PROTOBUF_VERIFY_VERSION; + protobuf_InitDefaults_google_2fprotobuf_2fsource_5fcontext_2eproto(); ::google::protobuf::DescriptorPool::InternalAddGeneratedFile( "\n$google/protobuf/source_context.proto\022\017" "google.protobuf\"\"\n\rSourceContext\022\021\n\tfile" - "_name\030\001 \001(\tBU\n\023com.google.protobufB\022Sour" - "ceContextProtoP\001\240\001\001\242\002\003GPB\252\002\036Google.Proto" - "buf.WellKnownTypesb\006proto3", 186); + "_name\030\001 \001(\tBR\n\023com.google.protobufB\022Sour" + "ceContextProtoP\001\242\002\003GPB\252\002\036Google.Protobuf" + ".WellKnownTypesb\006proto3", 183); ::google::protobuf::MessageFactory::InternalRegisterGeneratedFile( "google/protobuf/source_context.proto", &protobuf_RegisterTypes); - SourceContext::default_instance_ = new SourceContext(); - SourceContext::default_instance_->InitAsDefaultInstance(); ::google::protobuf::internal::OnShutdown(&protobuf_ShutdownFile_google_2fprotobuf_2fsource_5fcontext_2eproto); } +GOOGLE_PROTOBUF_DECLARE_ONCE(protobuf_AddDesc_google_2fprotobuf_2fsource_5fcontext_2eproto_once_); +void protobuf_AddDesc_google_2fprotobuf_2fsource_5fcontext_2eproto() { + ::google::protobuf::GoogleOnceInit(&protobuf_AddDesc_google_2fprotobuf_2fsource_5fcontext_2eproto_once_, + &protobuf_AddDesc_google_2fprotobuf_2fsource_5fcontext_2eproto_impl); +} // Force AddDescriptors() to be called at static initialization time. struct StaticDescriptorInitializer_google_2fprotobuf_2fsource_5fcontext_2eproto { StaticDescriptorInitializer_google_2fprotobuf_2fsource_5fcontext_2eproto() { @@ -102,6 +113,16 @@ struct StaticDescriptorInitializer_google_2fprotobuf_2fsource_5fcontext_2eproto } } static_descriptor_initializer_google_2fprotobuf_2fsource_5fcontext_2eproto_; +namespace { + +static void MergeFromFail(int line) GOOGLE_ATTRIBUTE_COLD GOOGLE_ATTRIBUTE_NORETURN; +static void MergeFromFail(int line) { + ::google::protobuf::internal::MergeFromFail(__FILE__, line); +} + +} // namespace + + // =================================================================== #if !defined(_MSC_VER) || _MSC_VER >= 1900 @@ -110,27 +131,25 @@ const int SourceContext::kFileNameFieldNumber; SourceContext::SourceContext() : ::google::protobuf::Message(), _internal_metadata_(NULL) { + if (this != internal_default_instance()) protobuf_InitDefaults_google_2fprotobuf_2fsource_5fcontext_2eproto(); SharedCtor(); // @@protoc_insertion_point(constructor:google.protobuf.SourceContext) } void SourceContext::InitAsDefaultInstance() { - _is_default_instance_ = true; } SourceContext::SourceContext(const SourceContext& from) : ::google::protobuf::Message(), _internal_metadata_(NULL) { SharedCtor(); - MergeFrom(from); + UnsafeMergeFrom(from); // @@protoc_insertion_point(copy_constructor:google.protobuf.SourceContext) } void SourceContext::SharedCtor() { - _is_default_instance_ = false; - ::google::protobuf::internal::GetEmptyString(); - _cached_size_ = 0; file_name_.UnsafeSetDefault(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); + _cached_size_ = 0; } SourceContext::~SourceContext() { @@ -140,8 +159,6 @@ SourceContext::~SourceContext() { void SourceContext::SharedDtor() { file_name_.DestroyNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); - if (this != default_instance_) { - } } void SourceContext::SetCachedSize(int size) const { @@ -155,11 +172,11 @@ const ::google::protobuf::Descriptor* SourceContext::descriptor() { } const SourceContext& SourceContext::default_instance() { - if (default_instance_ == NULL) protobuf_AddDesc_google_2fprotobuf_2fsource_5fcontext_2eproto(); - return *default_instance_; + protobuf_InitDefaults_google_2fprotobuf_2fsource_5fcontext_2eproto(); + return *internal_default_instance(); } -SourceContext* SourceContext::default_instance_ = NULL; +::google::protobuf::internal::ExplicitlyConstructed SourceContext::default_instance_; SourceContext* SourceContext::New(::google::protobuf::Arena* arena) const { SourceContext* n = new SourceContext; @@ -256,9 +273,9 @@ void SourceContext::SerializeWithCachedSizes( return target; } -int SourceContext::ByteSize() const { +size_t SourceContext::ByteSizeLong() const { // @@protoc_insertion_point(message_byte_size_start:google.protobuf.SourceContext) - int total_size = 0; + size_t total_size = 0; // optional string file_name = 1; if (this->file_name().size() > 0) { @@ -267,18 +284,17 @@ int SourceContext::ByteSize() const { this->file_name()); } + int cached_size = ::google::protobuf::internal::ToCachedSize(total_size); GOOGLE_SAFE_CONCURRENT_WRITES_BEGIN(); - _cached_size_ = total_size; + _cached_size_ = cached_size; GOOGLE_SAFE_CONCURRENT_WRITES_END(); return total_size; } void SourceContext::MergeFrom(const ::google::protobuf::Message& from) { // @@protoc_insertion_point(generalized_merge_from_start:google.protobuf.SourceContext) - if (GOOGLE_PREDICT_FALSE(&from == this)) { - ::google::protobuf::internal::MergeFromFail(__FILE__, __LINE__); - } - const SourceContext* source = + if (GOOGLE_PREDICT_FALSE(&from == this)) MergeFromFail(__LINE__); + const SourceContext* source = ::google::protobuf::internal::DynamicCastToGenerated( &from); if (source == NULL) { @@ -286,15 +302,21 @@ void SourceContext::MergeFrom(const ::google::protobuf::Message& from) { ::google::protobuf::internal::ReflectionOps::Merge(from, this); } else { // @@protoc_insertion_point(generalized_merge_from_cast_success:google.protobuf.SourceContext) - MergeFrom(*source); + UnsafeMergeFrom(*source); } } void SourceContext::MergeFrom(const SourceContext& from) { // @@protoc_insertion_point(class_specific_merge_from_start:google.protobuf.SourceContext) - if (GOOGLE_PREDICT_FALSE(&from == this)) { - ::google::protobuf::internal::MergeFromFail(__FILE__, __LINE__); + if (GOOGLE_PREDICT_TRUE(&from != this)) { + UnsafeMergeFrom(from); + } else { + MergeFromFail(__LINE__); } +} + +void SourceContext::UnsafeMergeFrom(const SourceContext& from) { + GOOGLE_DCHECK(&from != this); if (from.file_name().size() > 0) { file_name_.AssignWithDefault(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), from.file_name_); @@ -312,7 +334,7 @@ void SourceContext::CopyFrom(const SourceContext& from) { // @@protoc_insertion_point(class_specific_copy_from_start:google.protobuf.SourceContext) if (&from == this) return; Clear(); - MergeFrom(from); + UnsafeMergeFrom(from); } bool SourceContext::IsInitialized() const { @@ -345,37 +367,37 @@ void SourceContext::InternalSwap(SourceContext* other) { void SourceContext::clear_file_name() { file_name_.ClearToEmptyNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); } - const ::std::string& SourceContext::file_name() const { +const ::std::string& SourceContext::file_name() const { // @@protoc_insertion_point(field_get:google.protobuf.SourceContext.file_name) return file_name_.GetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); } - void SourceContext::set_file_name(const ::std::string& value) { +void SourceContext::set_file_name(const ::std::string& value) { file_name_.SetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), value); // @@protoc_insertion_point(field_set:google.protobuf.SourceContext.file_name) } - void SourceContext::set_file_name(const char* value) { +void SourceContext::set_file_name(const char* value) { file_name_.SetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), ::std::string(value)); // @@protoc_insertion_point(field_set_char:google.protobuf.SourceContext.file_name) } - void SourceContext::set_file_name(const char* value, size_t size) { +void SourceContext::set_file_name(const char* value, size_t size) { file_name_.SetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), ::std::string(reinterpret_cast(value), size)); // @@protoc_insertion_point(field_set_pointer:google.protobuf.SourceContext.file_name) } - ::std::string* SourceContext::mutable_file_name() { +::std::string* SourceContext::mutable_file_name() { // @@protoc_insertion_point(field_mutable:google.protobuf.SourceContext.file_name) return file_name_.MutableNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); } - ::std::string* SourceContext::release_file_name() { +::std::string* SourceContext::release_file_name() { // @@protoc_insertion_point(field_release:google.protobuf.SourceContext.file_name) return file_name_.ReleaseNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); } - void SourceContext::set_allocated_file_name(::std::string* file_name) { +void SourceContext::set_allocated_file_name(::std::string* file_name) { if (file_name != NULL) { } else { diff --git a/src/google/protobuf/source_context.pb.h b/src/google/protobuf/source_context.pb.h index 163b1eb0..b82f1f27 100644 --- a/src/google/protobuf/source_context.pb.h +++ b/src/google/protobuf/source_context.pb.h @@ -34,6 +34,7 @@ namespace protobuf { // Internal implementation detail -- do not call these. void LIBPROTOBUF_EXPORT protobuf_AddDesc_google_2fprotobuf_2fsource_5fcontext_2eproto(); +void LIBPROTOBUF_EXPORT protobuf_InitDefaults_google_2fprotobuf_2fsource_5fcontext_2eproto(); void protobuf_AssignDesc_google_2fprotobuf_2fsource_5fcontext_2eproto(); void protobuf_ShutdownFile_google_2fprotobuf_2fsource_5fcontext_2eproto(); @@ -56,6 +57,10 @@ class LIBPROTOBUF_EXPORT SourceContext : public ::google::protobuf::Message /* @ static const ::google::protobuf::Descriptor* descriptor(); static const SourceContext& default_instance(); + static inline const SourceContext* internal_default_instance() { + return &default_instance_.get(); + } + void Swap(SourceContext* other); // implements Message ---------------------------------------------- @@ -70,7 +75,7 @@ class LIBPROTOBUF_EXPORT SourceContext : public ::google::protobuf::Message /* @ void Clear(); bool IsInitialized() const; - int ByteSize() const; + size_t ByteSizeLong() const; bool MergePartialFromCodedStream( ::google::protobuf::io::CodedInputStream* input); void SerializeWithCachedSizes( @@ -86,6 +91,7 @@ class LIBPROTOBUF_EXPORT SourceContext : public ::google::protobuf::Message /* @ void SharedDtor(); void SetCachedSize(int size) const; void InternalSwap(SourceContext* other); + void UnsafeMergeFrom(const SourceContext& from); private: inline ::google::protobuf::Arena* GetArenaNoVirtual() const { return _internal_metadata_.arena(); @@ -116,15 +122,15 @@ class LIBPROTOBUF_EXPORT SourceContext : public ::google::protobuf::Message /* @ private: ::google::protobuf::internal::InternalMetadataWithArena _internal_metadata_; - bool _is_default_instance_; ::google::protobuf::internal::ArenaStringPtr file_name_; mutable int _cached_size_; - friend void LIBPROTOBUF_EXPORT protobuf_AddDesc_google_2fprotobuf_2fsource_5fcontext_2eproto(); + friend void LIBPROTOBUF_EXPORT protobuf_InitDefaults_google_2fprotobuf_2fsource_5fcontext_2eproto_impl(); + friend void LIBPROTOBUF_EXPORT protobuf_AddDesc_google_2fprotobuf_2fsource_5fcontext_2eproto_impl(); friend void protobuf_AssignDesc_google_2fprotobuf_2fsource_5fcontext_2eproto(); friend void protobuf_ShutdownFile_google_2fprotobuf_2fsource_5fcontext_2eproto(); void InitAsDefaultInstance(); - static SourceContext* default_instance_; + static ::google::protobuf::internal::ExplicitlyConstructed default_instance_; }; // =================================================================== diff --git a/src/google/protobuf/source_context.proto b/src/google/protobuf/source_context.proto index a2c08e2b..79137ce8 100644 --- a/src/google/protobuf/source_context.proto +++ b/src/google/protobuf/source_context.proto @@ -36,7 +36,6 @@ option csharp_namespace = "Google.Protobuf.WellKnownTypes"; option java_package = "com.google.protobuf"; option java_outer_classname = "SourceContextProto"; option java_multiple_files = true; -option java_generate_equals_and_hash = true; option objc_class_prefix = "GPB"; // `SourceContext` represents information about the source of a diff --git a/src/google/protobuf/struct.pb.cc b/src/google/protobuf/struct.pb.cc index 998ea0e0..c609f879 100644 --- a/src/google/protobuf/struct.pb.cc +++ b/src/google/protobuf/struct.pb.cc @@ -59,14 +59,13 @@ void protobuf_AssignDesc_google_2fprotobuf_2fstruct_2eproto() { Struct_reflection_ = ::google::protobuf::internal::GeneratedMessageReflection::NewGeneratedMessageReflection( Struct_descriptor_, - Struct::default_instance_, + Struct::internal_default_instance(), Struct_offsets_, -1, -1, -1, sizeof(Struct), - GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(Struct, _internal_metadata_), - GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(Struct, _is_default_instance_)); + GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(Struct, _internal_metadata_)); Struct_FieldsEntry_descriptor_ = Struct_descriptor_->nested_type(0); Value_descriptor_ = file->message_type(1); static const int Value_offsets_[7] = { @@ -81,7 +80,7 @@ void protobuf_AssignDesc_google_2fprotobuf_2fstruct_2eproto() { Value_reflection_ = ::google::protobuf::internal::GeneratedMessageReflection::NewGeneratedMessageReflection( Value_descriptor_, - Value::default_instance_, + Value::internal_default_instance(), Value_offsets_, -1, -1, @@ -89,8 +88,7 @@ void protobuf_AssignDesc_google_2fprotobuf_2fstruct_2eproto() { Value_default_oneof_instance_, GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(Value, _oneof_case_[0]), sizeof(Value), - GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(Value, _internal_metadata_), - GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(Value, _is_default_instance_)); + GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(Value, _internal_metadata_)); ListValue_descriptor_ = file->message_type(2); static const int ListValue_offsets_[1] = { GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(ListValue, values_), @@ -98,21 +96,20 @@ void protobuf_AssignDesc_google_2fprotobuf_2fstruct_2eproto() { ListValue_reflection_ = ::google::protobuf::internal::GeneratedMessageReflection::NewGeneratedMessageReflection( ListValue_descriptor_, - ListValue::default_instance_, + ListValue::internal_default_instance(), ListValue_offsets_, -1, -1, -1, sizeof(ListValue), - GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(ListValue, _internal_metadata_), - GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(ListValue, _is_default_instance_)); + GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(ListValue, _internal_metadata_)); NullValue_descriptor_ = file->enum_type(0); } namespace { GOOGLE_PROTOBUF_DECLARE_ONCE(protobuf_AssignDescriptors_once_); -inline void protobuf_AssignDescriptorsOnce() { +void protobuf_AssignDescriptorsOnce() { ::google::protobuf::GoogleOnceInit(&protobuf_AssignDescriptors_once_, &protobuf_AssignDesc_google_2fprotobuf_2fstruct_2eproto); } @@ -121,7 +118,7 @@ void protobuf_RegisterTypes(const ::std::string&) GOOGLE_ATTRIBUTE_COLD; void protobuf_RegisterTypes(const ::std::string&) { protobuf_AssignDescriptorsOnce(); ::google::protobuf::MessageFactory::InternalRegisterGeneratedMessage( - Struct_descriptor_, &Struct::default_instance()); + Struct_descriptor_, Struct::internal_default_instance()); ::google::protobuf::MessageFactory::InternalRegisterGeneratedMessage( Struct_FieldsEntry_descriptor_, ::google::protobuf::internal::MapEntry< @@ -132,30 +129,43 @@ void protobuf_RegisterTypes(const ::std::string&) { 0>::CreateDefaultInstance( Struct_FieldsEntry_descriptor_)); ::google::protobuf::MessageFactory::InternalRegisterGeneratedMessage( - Value_descriptor_, &Value::default_instance()); + Value_descriptor_, Value::internal_default_instance()); ::google::protobuf::MessageFactory::InternalRegisterGeneratedMessage( - ListValue_descriptor_, &ListValue::default_instance()); + ListValue_descriptor_, ListValue::internal_default_instance()); } } // namespace void protobuf_ShutdownFile_google_2fprotobuf_2fstruct_2eproto() { - delete Struct::default_instance_; delete Struct_reflection_; - delete Value::default_instance_; delete Value_default_oneof_instance_; delete Value_reflection_; - delete ListValue::default_instance_; delete ListValue_reflection_; } -void protobuf_AddDesc_google_2fprotobuf_2fstruct_2eproto() GOOGLE_ATTRIBUTE_COLD; -void protobuf_AddDesc_google_2fprotobuf_2fstruct_2eproto() { - static bool already_here = false; - if (already_here) return; - already_here = true; +void protobuf_InitDefaults_google_2fprotobuf_2fstruct_2eproto_impl() { + GOOGLE_PROTOBUF_VERIFY_VERSION; + + ::google::protobuf::internal::GetEmptyString(); + Struct::default_instance_.DefaultConstruct(); + ::google::protobuf::internal::GetEmptyString(); + Value::default_instance_.DefaultConstruct(); + Value_default_oneof_instance_ = new ValueOneofInstance(); + ListValue::default_instance_.DefaultConstruct(); + Struct::default_instance_.get_mutable()->InitAsDefaultInstance(); + Value::default_instance_.get_mutable()->InitAsDefaultInstance(); + ListValue::default_instance_.get_mutable()->InitAsDefaultInstance(); +} + +GOOGLE_PROTOBUF_DECLARE_ONCE(protobuf_InitDefaults_google_2fprotobuf_2fstruct_2eproto_once_); +void protobuf_InitDefaults_google_2fprotobuf_2fstruct_2eproto() { + ::google::protobuf::GoogleOnceInit(&protobuf_InitDefaults_google_2fprotobuf_2fstruct_2eproto_once_, + &protobuf_InitDefaults_google_2fprotobuf_2fstruct_2eproto_impl); +} +void protobuf_AddDesc_google_2fprotobuf_2fstruct_2eproto_impl() { GOOGLE_PROTOBUF_VERIFY_VERSION; + protobuf_InitDefaults_google_2fprotobuf_2fstruct_2eproto(); ::google::protobuf::DescriptorPool::InternalAddGeneratedFile( "\n\034google/protobuf/struct.proto\022\017google.p" "rotobuf\"\204\001\n\006Struct\0223\n\006fields\030\001 \003(\0132#.goo" @@ -171,21 +181,19 @@ void protobuf_AddDesc_google_2fprotobuf_2fstruct_2eproto() { "es\030\001 \003(\0132\026.google.protobuf.Value*\033\n\tNull" "Value\022\016\n\nNULL_VALUE\020\000B\201\001\n\023com.google.pro" "tobufB\013StructProtoP\001Z1github.com/golang/" - "protobuf/ptypes/struct;structpb\240\001\001\242\002\003GPB" + "protobuf/ptypes/struct;structpb\370\001\001\242\002\003GPB" "\252\002\036Google.Protobuf.WellKnownTypesb\006proto" "3", 641); ::google::protobuf::MessageFactory::InternalRegisterGeneratedFile( "google/protobuf/struct.proto", &protobuf_RegisterTypes); - Struct::default_instance_ = new Struct(); - Value::default_instance_ = new Value(); - Value_default_oneof_instance_ = new ValueOneofInstance(); - ListValue::default_instance_ = new ListValue(); - Struct::default_instance_->InitAsDefaultInstance(); - Value::default_instance_->InitAsDefaultInstance(); - ListValue::default_instance_->InitAsDefaultInstance(); ::google::protobuf::internal::OnShutdown(&protobuf_ShutdownFile_google_2fprotobuf_2fstruct_2eproto); } +GOOGLE_PROTOBUF_DECLARE_ONCE(protobuf_AddDesc_google_2fprotobuf_2fstruct_2eproto_once_); +void protobuf_AddDesc_google_2fprotobuf_2fstruct_2eproto() { + ::google::protobuf::GoogleOnceInit(&protobuf_AddDesc_google_2fprotobuf_2fstruct_2eproto_once_, + &protobuf_AddDesc_google_2fprotobuf_2fstruct_2eproto_impl); +} // Force AddDescriptors() to be called at static initialization time. struct StaticDescriptorInitializer_google_2fprotobuf_2fstruct_2eproto { StaticDescriptorInitializer_google_2fprotobuf_2fstruct_2eproto() { @@ -197,7 +205,7 @@ const ::google::protobuf::EnumDescriptor* NullValue_descriptor() { return NullValue_descriptor_; } bool NullValue_IsValid(int value) { - switch(value) { + switch (value) { case 0: return true; default: @@ -206,6 +214,16 @@ bool NullValue_IsValid(int value) { } +namespace { + +static void MergeFromFail(int line) GOOGLE_ATTRIBUTE_COLD GOOGLE_ATTRIBUTE_NORETURN; +static void MergeFromFail(int line) { + ::google::protobuf::internal::MergeFromFail(__FILE__, line); +} + +} // namespace + + // =================================================================== #if !defined(_MSC_VER) || _MSC_VER >= 1900 @@ -214,30 +232,39 @@ const int Struct::kFieldsFieldNumber; Struct::Struct() : ::google::protobuf::Message(), _internal_metadata_(NULL) { + if (this != internal_default_instance()) protobuf_InitDefaults_google_2fprotobuf_2fstruct_2eproto(); SharedCtor(); // @@protoc_insertion_point(constructor:google.protobuf.Struct) } +Struct::Struct(::google::protobuf::Arena* arena) + : ::google::protobuf::Message(), + _internal_metadata_(arena), + fields_(arena) { +#ifdef GOOGLE_PROTOBUF_NO_STATIC_INITIALIZER + protobuf_InitDefaults_google_2fprotobuf_2fstruct_2eproto(); +#endif // GOOGLE_PROTOBUF_NO_STATIC_INITIALIZER + SharedCtor(); + RegisterArenaDtor(arena); + // @@protoc_insertion_point(arena_constructor:google.protobuf.Struct) +} void Struct::InitAsDefaultInstance() { - _is_default_instance_ = true; } Struct::Struct(const Struct& from) : ::google::protobuf::Message(), _internal_metadata_(NULL) { SharedCtor(); - MergeFrom(from); + UnsafeMergeFrom(from); // @@protoc_insertion_point(copy_constructor:google.protobuf.Struct) } void Struct::SharedCtor() { - _is_default_instance_ = false; - ::google::protobuf::internal::GetEmptyString(); - _cached_size_ = 0; fields_.SetAssignDescriptorCallback( protobuf_AssignDescriptorsOnce); fields_.SetEntryDescriptor( &::google::protobuf::Struct_FieldsEntry_descriptor_); + _cached_size_ = 0; } Struct::~Struct() { @@ -246,10 +273,19 @@ Struct::~Struct() { } void Struct::SharedDtor() { - if (this != default_instance_) { + ::google::protobuf::Arena* arena = GetArenaNoVirtual(); + if (arena != NULL) { + return; } + } +void Struct::ArenaDtor(void* object) { + Struct* _this = reinterpret_cast< Struct* >(object); + (void)_this; +} +void Struct::RegisterArenaDtor(::google::protobuf::Arena* arena) { +} void Struct::SetCachedSize(int size) const { GOOGLE_SAFE_CONCURRENT_WRITES_BEGIN(); _cached_size_ = size; @@ -261,18 +297,14 @@ const ::google::protobuf::Descriptor* Struct::descriptor() { } const Struct& Struct::default_instance() { - if (default_instance_ == NULL) protobuf_AddDesc_google_2fprotobuf_2fstruct_2eproto(); - return *default_instance_; + protobuf_InitDefaults_google_2fprotobuf_2fstruct_2eproto(); + return *internal_default_instance(); } -Struct* Struct::default_instance_ = NULL; +::google::protobuf::internal::ExplicitlyConstructed Struct::default_instance_; Struct* Struct::New(::google::protobuf::Arena* arena) const { - Struct* n = new Struct; - if (arena != NULL) { - arena->Own(n); - } - return n; + return ::google::protobuf::Arena::CreateMessage(arena); } void Struct::Clear() { @@ -373,6 +405,9 @@ void Struct::SerializeWithCachedSizes( items[i]->first, items[i]->second)); ::google::protobuf::internal::WireFormatLite::WriteMessageMaybeToArray( 1, *entry, output); + if (entry->GetArena() != NULL) { + entry.release(); + } Utf8Check::Check(items[i]); } } else { @@ -384,6 +419,9 @@ void Struct::SerializeWithCachedSizes( it->first, it->second)); ::google::protobuf::internal::WireFormatLite::WriteMessageMaybeToArray( 1, *entry, output); + if (entry->GetArena() != NULL) { + entry.release(); + } Utf8Check::Check(&*it); } } @@ -431,6 +469,9 @@ void Struct::SerializeWithCachedSizes( InternalWriteMessageNoVirtualToArray( 1, *entry, deterministic, target); ; + if (entry->GetArena() != NULL) { + entry.release(); + } Utf8Check::Check(items[i]); } } else { @@ -444,6 +485,9 @@ void Struct::SerializeWithCachedSizes( InternalWriteMessageNoVirtualToArray( 1, *entry, deterministic, target); ; + if (entry->GetArena() != NULL) { + entry.release(); + } Utf8Check::Check(&*it); } } @@ -453,35 +497,41 @@ void Struct::SerializeWithCachedSizes( return target; } -int Struct::ByteSize() const { +size_t Struct::ByteSizeLong() const { // @@protoc_insertion_point(message_byte_size_start:google.protobuf.Struct) - int total_size = 0; + size_t total_size = 0; // map fields = 1; - total_size += 1 * this->fields_size(); + total_size += 1 * + ::google::protobuf::internal::FromIntSize(this->fields_size()); { ::google::protobuf::scoped_ptr entry; for (::google::protobuf::Map< ::std::string, ::google::protobuf::Value >::const_iterator it = this->fields().begin(); it != this->fields().end(); ++it) { + if (entry.get() != NULL && entry->GetArena() != NULL) { + entry.release(); + } entry.reset(fields_.NewEntryWrapper(it->first, it->second)); total_size += ::google::protobuf::internal::WireFormatLite:: MessageSizeNoVirtual(*entry); } + if (entry.get() != NULL && entry->GetArena() != NULL) { + entry.release(); + } } + int cached_size = ::google::protobuf::internal::ToCachedSize(total_size); GOOGLE_SAFE_CONCURRENT_WRITES_BEGIN(); - _cached_size_ = total_size; + _cached_size_ = cached_size; GOOGLE_SAFE_CONCURRENT_WRITES_END(); return total_size; } void Struct::MergeFrom(const ::google::protobuf::Message& from) { // @@protoc_insertion_point(generalized_merge_from_start:google.protobuf.Struct) - if (GOOGLE_PREDICT_FALSE(&from == this)) { - ::google::protobuf::internal::MergeFromFail(__FILE__, __LINE__); - } - const Struct* source = + if (GOOGLE_PREDICT_FALSE(&from == this)) MergeFromFail(__LINE__); + const Struct* source = ::google::protobuf::internal::DynamicCastToGenerated( &from); if (source == NULL) { @@ -489,15 +539,21 @@ void Struct::MergeFrom(const ::google::protobuf::Message& from) { ::google::protobuf::internal::ReflectionOps::Merge(from, this); } else { // @@protoc_insertion_point(generalized_merge_from_cast_success:google.protobuf.Struct) - MergeFrom(*source); + UnsafeMergeFrom(*source); } } void Struct::MergeFrom(const Struct& from) { // @@protoc_insertion_point(class_specific_merge_from_start:google.protobuf.Struct) - if (GOOGLE_PREDICT_FALSE(&from == this)) { - ::google::protobuf::internal::MergeFromFail(__FILE__, __LINE__); + if (GOOGLE_PREDICT_TRUE(&from != this)) { + UnsafeMergeFrom(from); + } else { + MergeFromFail(__LINE__); } +} + +void Struct::UnsafeMergeFrom(const Struct& from) { + GOOGLE_DCHECK(&from != this); fields_.MergeFrom(from.fields_); } @@ -512,7 +568,7 @@ void Struct::CopyFrom(const Struct& from) { // @@protoc_insertion_point(class_specific_copy_from_start:google.protobuf.Struct) if (&from == this) return; Clear(); - MergeFrom(from); + UnsafeMergeFrom(from); } bool Struct::IsInitialized() const { @@ -522,6 +578,18 @@ bool Struct::IsInitialized() const { void Struct::Swap(Struct* other) { if (other == this) return; + if (GetArenaNoVirtual() == other->GetArenaNoVirtual()) { + InternalSwap(other); + } else { + Struct temp; + temp.UnsafeMergeFrom(*this); + CopyFrom(*other); + other->CopyFrom(temp); + } +} +void Struct::UnsafeArenaSwap(Struct* other) { + if (other == this) return; + GOOGLE_DCHECK(GetArenaNoVirtual() == other->GetArenaNoVirtual()); InternalSwap(other); } void Struct::InternalSwap(Struct* other) { @@ -574,33 +642,43 @@ const int Value::kListValueFieldNumber; Value::Value() : ::google::protobuf::Message(), _internal_metadata_(NULL) { + if (this != internal_default_instance()) protobuf_InitDefaults_google_2fprotobuf_2fstruct_2eproto(); SharedCtor(); // @@protoc_insertion_point(constructor:google.protobuf.Value) } +Value::Value(::google::protobuf::Arena* arena) + : ::google::protobuf::Message(), + _internal_metadata_(arena) { +#ifdef GOOGLE_PROTOBUF_NO_STATIC_INITIALIZER + protobuf_InitDefaults_google_2fprotobuf_2fstruct_2eproto(); +#endif // GOOGLE_PROTOBUF_NO_STATIC_INITIALIZER + SharedCtor(); + RegisterArenaDtor(arena); + // @@protoc_insertion_point(arena_constructor:google.protobuf.Value) +} void Value::InitAsDefaultInstance() { - _is_default_instance_ = true; Value_default_oneof_instance_->null_value_ = 0; Value_default_oneof_instance_->number_value_ = 0; Value_default_oneof_instance_->string_value_.UnsafeSetDefault(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); Value_default_oneof_instance_->bool_value_ = false; - Value_default_oneof_instance_->struct_value_ = const_cast< ::google::protobuf::Struct*>(&::google::protobuf::Struct::default_instance()); - Value_default_oneof_instance_->list_value_ = const_cast< ::google::protobuf::ListValue*>(&::google::protobuf::ListValue::default_instance()); + Value_default_oneof_instance_->struct_value_ = const_cast< ::google::protobuf::Struct*>( + ::google::protobuf::Struct::internal_default_instance()); + Value_default_oneof_instance_->list_value_ = const_cast< ::google::protobuf::ListValue*>( + ::google::protobuf::ListValue::internal_default_instance()); } Value::Value(const Value& from) : ::google::protobuf::Message(), _internal_metadata_(NULL) { SharedCtor(); - MergeFrom(from); + UnsafeMergeFrom(from); // @@protoc_insertion_point(copy_constructor:google.protobuf.Value) } void Value::SharedCtor() { - _is_default_instance_ = false; - ::google::protobuf::internal::GetEmptyString(); - _cached_size_ = 0; clear_has_kind(); + _cached_size_ = 0; } Value::~Value() { @@ -609,13 +687,22 @@ Value::~Value() { } void Value::SharedDtor() { + ::google::protobuf::Arena* arena = GetArenaNoVirtual(); + if (arena != NULL) { + return; + } + if (has_kind()) { clear_kind(); } - if (this != default_instance_) { - } } +void Value::ArenaDtor(void* object) { + Value* _this = reinterpret_cast< Value* >(object); + (void)_this; +} +void Value::RegisterArenaDtor(::google::protobuf::Arena* arena) { +} void Value::SetCachedSize(int size) const { GOOGLE_SAFE_CONCURRENT_WRITES_BEGIN(); _cached_size_ = size; @@ -627,23 +714,19 @@ const ::google::protobuf::Descriptor* Value::descriptor() { } const Value& Value::default_instance() { - if (default_instance_ == NULL) protobuf_AddDesc_google_2fprotobuf_2fstruct_2eproto(); - return *default_instance_; + protobuf_InitDefaults_google_2fprotobuf_2fstruct_2eproto(); + return *internal_default_instance(); } -Value* Value::default_instance_ = NULL; +::google::protobuf::internal::ExplicitlyConstructed Value::default_instance_; Value* Value::New(::google::protobuf::Arena* arena) const { - Value* n = new Value; - if (arena != NULL) { - arena->Own(n); - } - return n; + return ::google::protobuf::Arena::CreateMessage(arena); } void Value::clear_kind() { // @@protoc_insertion_point(one_of_clear_start:google.protobuf.Value) - switch(kind_case()) { + switch (kind_case()) { case kNullValue: { // No need to clear break; @@ -653,7 +736,8 @@ void Value::clear_kind() { break; } case kStringValue: { - kind_.string_value_.DestroyNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); + kind_.string_value_.Destroy(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), + GetArenaNoVirtual()); break; } case kBoolValue: { @@ -661,11 +745,15 @@ void Value::clear_kind() { break; } case kStructValue: { - delete kind_.struct_value_; + if (GetArenaNoVirtual() == NULL) { + delete kind_.struct_value_; + } break; } case kListValue: { - delete kind_.list_value_; + if (GetArenaNoVirtual() == NULL) { + delete kind_.list_value_; + } break; } case KIND_NOT_SET: { @@ -702,14 +790,13 @@ bool Value::MergePartialFromCodedStream( } else { goto handle_unusual; } - if (input->ExpectTag(17)) goto parse_number_value; + goto after_list_value; break; } // optional double number_value = 2; case 2: { if (tag == 17) { - parse_number_value: clear_kind(); DO_((::google::protobuf::internal::WireFormatLite::ReadPrimitive< double, ::google::protobuf::internal::WireFormatLite::TYPE_DOUBLE>( @@ -718,14 +805,13 @@ bool Value::MergePartialFromCodedStream( } else { goto handle_unusual; } - if (input->ExpectTag(26)) goto parse_string_value; + goto after_list_value; break; } // optional string string_value = 3; case 3: { if (tag == 26) { - parse_string_value: DO_(::google::protobuf::internal::WireFormatLite::ReadString( input, this->mutable_string_value())); DO_(::google::protobuf::internal::WireFormatLite::VerifyUtf8String( @@ -735,14 +821,13 @@ bool Value::MergePartialFromCodedStream( } else { goto handle_unusual; } - if (input->ExpectTag(32)) goto parse_bool_value; + goto after_list_value; break; } // optional bool bool_value = 4; case 4: { if (tag == 32) { - parse_bool_value: clear_kind(); DO_((::google::protobuf::internal::WireFormatLite::ReadPrimitive< bool, ::google::protobuf::internal::WireFormatLite::TYPE_BOOL>( @@ -751,14 +836,13 @@ bool Value::MergePartialFromCodedStream( } else { goto handle_unusual; } - if (input->ExpectTag(42)) goto parse_struct_value; + goto after_list_value; break; } // optional .google.protobuf.Struct struct_value = 5; case 5: { if (tag == 42) { - parse_struct_value: DO_(::google::protobuf::internal::WireFormatLite::ReadMessageNoVirtual( input, mutable_struct_value())); } else { @@ -777,6 +861,7 @@ bool Value::MergePartialFromCodedStream( } else { goto handle_unusual; } + after_list_value: if (input->ExpectAtEnd()) goto success; break; } @@ -895,9 +980,9 @@ void Value::SerializeWithCachedSizes( return target; } -int Value::ByteSize() const { +size_t Value::ByteSizeLong() const { // @@protoc_insertion_point(message_byte_size_start:google.protobuf.Value) - int total_size = 0; + size_t total_size = 0; switch (kind_case()) { // optional .google.protobuf.NullValue null_value = 1; @@ -941,18 +1026,17 @@ int Value::ByteSize() const { break; } } + int cached_size = ::google::protobuf::internal::ToCachedSize(total_size); GOOGLE_SAFE_CONCURRENT_WRITES_BEGIN(); - _cached_size_ = total_size; + _cached_size_ = cached_size; GOOGLE_SAFE_CONCURRENT_WRITES_END(); return total_size; } void Value::MergeFrom(const ::google::protobuf::Message& from) { // @@protoc_insertion_point(generalized_merge_from_start:google.protobuf.Value) - if (GOOGLE_PREDICT_FALSE(&from == this)) { - ::google::protobuf::internal::MergeFromFail(__FILE__, __LINE__); - } - const Value* source = + if (GOOGLE_PREDICT_FALSE(&from == this)) MergeFromFail(__LINE__); + const Value* source = ::google::protobuf::internal::DynamicCastToGenerated( &from); if (source == NULL) { @@ -960,15 +1044,21 @@ void Value::MergeFrom(const ::google::protobuf::Message& from) { ::google::protobuf::internal::ReflectionOps::Merge(from, this); } else { // @@protoc_insertion_point(generalized_merge_from_cast_success:google.protobuf.Value) - MergeFrom(*source); + UnsafeMergeFrom(*source); } } void Value::MergeFrom(const Value& from) { // @@protoc_insertion_point(class_specific_merge_from_start:google.protobuf.Value) - if (GOOGLE_PREDICT_FALSE(&from == this)) { - ::google::protobuf::internal::MergeFromFail(__FILE__, __LINE__); + if (GOOGLE_PREDICT_TRUE(&from != this)) { + UnsafeMergeFrom(from); + } else { + MergeFromFail(__LINE__); } +} + +void Value::UnsafeMergeFrom(const Value& from) { + GOOGLE_DCHECK(&from != this); switch (from.kind_case()) { case kNullValue: { set_null_value(from.null_value()); @@ -1011,7 +1101,7 @@ void Value::CopyFrom(const Value& from) { // @@protoc_insertion_point(class_specific_copy_from_start:google.protobuf.Value) if (&from == this) return; Clear(); - MergeFrom(from); + UnsafeMergeFrom(from); } bool Value::IsInitialized() const { @@ -1021,6 +1111,18 @@ bool Value::IsInitialized() const { void Value::Swap(Value* other) { if (other == this) return; + if (GetArenaNoVirtual() == other->GetArenaNoVirtual()) { + InternalSwap(other); + } else { + Value temp; + temp.UnsafeMergeFrom(*this); + CopyFrom(*other); + other->CopyFrom(temp); + } +} +void Value::UnsafeArenaSwap(Value* other) { + if (other == this) return; + GOOGLE_DCHECK(GetArenaNoVirtual() == other->GetArenaNoVirtual()); InternalSwap(other); } void Value::InternalSwap(Value* other) { @@ -1054,14 +1156,14 @@ void Value::clear_null_value() { clear_has_kind(); } } - ::google::protobuf::NullValue Value::null_value() const { +::google::protobuf::NullValue Value::null_value() const { // @@protoc_insertion_point(field_get:google.protobuf.Value.null_value) if (has_null_value()) { return static_cast< ::google::protobuf::NullValue >(kind_.null_value_); } return static_cast< ::google::protobuf::NullValue >(0); } - void Value::set_null_value(::google::protobuf::NullValue value) { +void Value::set_null_value(::google::protobuf::NullValue value) { if (!has_null_value()) { clear_kind(); set_has_null_value(); @@ -1083,14 +1185,14 @@ void Value::clear_number_value() { clear_has_kind(); } } - double Value::number_value() const { +double Value::number_value() const { // @@protoc_insertion_point(field_get:google.protobuf.Value.number_value) if (has_number_value()) { return kind_.number_value_; } return 0; } - void Value::set_number_value(double value) { +void Value::set_number_value(double value) { if (!has_number_value()) { clear_kind(); set_has_number_value(); @@ -1108,77 +1210,105 @@ void Value::set_has_string_value() { } void Value::clear_string_value() { if (has_string_value()) { - kind_.string_value_.DestroyNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); + kind_.string_value_.Destroy(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), + GetArenaNoVirtual()); clear_has_kind(); } } - const ::std::string& Value::string_value() const { +const ::std::string& Value::string_value() const { // @@protoc_insertion_point(field_get:google.protobuf.Value.string_value) if (has_string_value()) { - return kind_.string_value_.GetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); + return kind_.string_value_.Get(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); } return *&::google::protobuf::internal::GetEmptyStringAlreadyInited(); } - void Value::set_string_value(const ::std::string& value) { - // @@protoc_insertion_point(field_set:google.protobuf.Value.string_value) +void Value::set_string_value(const ::std::string& value) { if (!has_string_value()) { clear_kind(); set_has_string_value(); kind_.string_value_.UnsafeSetDefault(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); } - kind_.string_value_.SetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), value); + kind_.string_value_.Set(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), value, + GetArenaNoVirtual()); // @@protoc_insertion_point(field_set:google.protobuf.Value.string_value) } - void Value::set_string_value(const char* value) { +void Value::set_string_value(const char* value) { if (!has_string_value()) { clear_kind(); set_has_string_value(); kind_.string_value_.UnsafeSetDefault(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); } - kind_.string_value_.SetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), - ::std::string(value)); + kind_.string_value_.Set(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), + ::std::string(value), GetArenaNoVirtual()); // @@protoc_insertion_point(field_set_char:google.protobuf.Value.string_value) } - void Value::set_string_value(const char* value, size_t size) { +void Value::set_string_value(const char* value, + size_t size) { if (!has_string_value()) { clear_kind(); set_has_string_value(); kind_.string_value_.UnsafeSetDefault(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); } - kind_.string_value_.SetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), ::std::string( - reinterpret_cast(value), size)); + kind_.string_value_.Set(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), ::std::string( + reinterpret_cast(value), size), + GetArenaNoVirtual()); // @@protoc_insertion_point(field_set_pointer:google.protobuf.Value.string_value) } - ::std::string* Value::mutable_string_value() { +::std::string* Value::mutable_string_value() { if (!has_string_value()) { clear_kind(); set_has_string_value(); kind_.string_value_.UnsafeSetDefault(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); } + return kind_.string_value_.Mutable(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), + GetArenaNoVirtual()); // @@protoc_insertion_point(field_mutable:google.protobuf.Value.string_value) - return kind_.string_value_.MutableNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); } - ::std::string* Value::release_string_value() { +::std::string* Value::release_string_value() { // @@protoc_insertion_point(field_release:google.protobuf.Value.string_value) if (has_string_value()) { clear_has_kind(); - return kind_.string_value_.ReleaseNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); + return kind_.string_value_.Release(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), + GetArenaNoVirtual()); } else { return NULL; } } - void Value::set_allocated_string_value(::std::string* string_value) { +::std::string* Value::unsafe_arena_release_string_value() { + // @@protoc_insertion_point(field_unsafe_arena_release:google.protobuf.Value.string_value) + GOOGLE_DCHECK(GetArenaNoVirtual() != NULL); + if (has_string_value()) { + clear_has_kind(); + return kind_.string_value_.UnsafeArenaRelease( + &::google::protobuf::internal::GetEmptyStringAlreadyInited(), GetArenaNoVirtual()); + } else { + return NULL; + } +} +void Value::set_allocated_string_value(::std::string* string_value) { if (!has_string_value()) { kind_.string_value_.UnsafeSetDefault(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); } clear_kind(); if (string_value != NULL) { set_has_string_value(); - kind_.string_value_.SetAllocatedNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), - string_value); + kind_.string_value_.SetAllocated(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), string_value, + GetArenaNoVirtual()); } // @@protoc_insertion_point(field_set_allocated:google.protobuf.Value.string_value) } +void Value::unsafe_arena_set_allocated_string_value(::std::string* string_value) { + GOOGLE_DCHECK(GetArenaNoVirtual() != NULL); + if (!has_string_value()) { + kind_.string_value_.UnsafeSetDefault(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); + } + clear_kind(); + if (string_value) { + set_has_string_value(); + kind_.string_value_.UnsafeArenaSetAllocated(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), string_value, GetArenaNoVirtual()); + } + // @@protoc_insertion_point(field_unsafe_arena_set_allocated:google.protobuf.Value.string_value) +} // optional bool bool_value = 4; bool Value::has_bool_value() const { @@ -1193,14 +1323,14 @@ void Value::clear_bool_value() { clear_has_kind(); } } - bool Value::bool_value() const { +bool Value::bool_value() const { // @@protoc_insertion_point(field_get:google.protobuf.Value.bool_value) if (has_bool_value()) { return kind_.bool_value_; } return false; } - void Value::set_bool_value(bool value) { +void Value::set_bool_value(bool value) { if (!has_bool_value()) { clear_kind(); set_has_bool_value(); @@ -1218,7 +1348,9 @@ void Value::set_has_struct_value() { } void Value::clear_struct_value() { if (has_struct_value()) { - delete kind_.struct_value_; + if (GetArenaNoVirtual() == NULL) { + delete kind_.struct_value_; + } clear_has_kind(); } } @@ -1232,13 +1364,51 @@ void Value::clear_struct_value() { if (!has_struct_value()) { clear_kind(); set_has_struct_value(); - kind_.struct_value_ = new ::google::protobuf::Struct; + kind_.struct_value_ = + ::google::protobuf::Arena::CreateMessage< ::google::protobuf::Struct >( + GetArenaNoVirtual()); } // @@protoc_insertion_point(field_mutable:google.protobuf.Value.struct_value) return kind_.struct_value_; } ::google::protobuf::Struct* Value::release_struct_value() { // @@protoc_insertion_point(field_release:google.protobuf.Value.struct_value) + if (has_struct_value()) { + clear_has_kind(); + if (GetArenaNoVirtual() != NULL) { + ::google::protobuf::Struct* temp = new ::google::protobuf::Struct(*kind_.struct_value_); + kind_.struct_value_ = NULL; + return temp; + } else { + ::google::protobuf::Struct* temp = kind_.struct_value_; + kind_.struct_value_ = NULL; + return temp; + } + } else { + return NULL; + } +} +void Value::set_allocated_struct_value(::google::protobuf::Struct* struct_value) { + clear_kind(); + if (struct_value) { + if (GetArenaNoVirtual() != NULL && + ::google::protobuf::Arena::GetArena(struct_value) == NULL) { + GetArenaNoVirtual()->Own(struct_value); + } else if (GetArenaNoVirtual() != + ::google::protobuf::Arena::GetArena(struct_value)) { + ::google::protobuf::Struct* new_struct_value = + ::google::protobuf::Arena::CreateMessage< ::google::protobuf::Struct >( + GetArenaNoVirtual()); + new_struct_value->CopyFrom(*struct_value); + struct_value = new_struct_value; + } + set_has_struct_value(); + kind_.struct_value_ = struct_value; + } + // @@protoc_insertion_point(field_set_allocated:google.protobuf.Value.struct_value) +} + ::google::protobuf::Struct* Value::unsafe_arena_release_struct_value() { + // @@protoc_insertion_point(field_unsafe_arena_release:google.protobuf.Value.struct_value) if (has_struct_value()) { clear_has_kind(); ::google::protobuf::Struct* temp = kind_.struct_value_; @@ -1248,13 +1418,13 @@ void Value::clear_struct_value() { return NULL; } } -void Value::set_allocated_struct_value(::google::protobuf::Struct* struct_value) { + void Value::unsafe_arena_set_allocated_struct_value(::google::protobuf::Struct* struct_value) { clear_kind(); if (struct_value) { set_has_struct_value(); kind_.struct_value_ = struct_value; } - // @@protoc_insertion_point(field_set_allocated:google.protobuf.Value.struct_value) + // @@protoc_insertion_point(field_unsafe_arena_set_allocated:google.protobuf.Value.struct_value) } // optional .google.protobuf.ListValue list_value = 6; @@ -1266,7 +1436,9 @@ void Value::set_has_list_value() { } void Value::clear_list_value() { if (has_list_value()) { - delete kind_.list_value_; + if (GetArenaNoVirtual() == NULL) { + delete kind_.list_value_; + } clear_has_kind(); } } @@ -1280,13 +1452,51 @@ void Value::clear_list_value() { if (!has_list_value()) { clear_kind(); set_has_list_value(); - kind_.list_value_ = new ::google::protobuf::ListValue; + kind_.list_value_ = + ::google::protobuf::Arena::CreateMessage< ::google::protobuf::ListValue >( + GetArenaNoVirtual()); } // @@protoc_insertion_point(field_mutable:google.protobuf.Value.list_value) return kind_.list_value_; } ::google::protobuf::ListValue* Value::release_list_value() { // @@protoc_insertion_point(field_release:google.protobuf.Value.list_value) + if (has_list_value()) { + clear_has_kind(); + if (GetArenaNoVirtual() != NULL) { + ::google::protobuf::ListValue* temp = new ::google::protobuf::ListValue(*kind_.list_value_); + kind_.list_value_ = NULL; + return temp; + } else { + ::google::protobuf::ListValue* temp = kind_.list_value_; + kind_.list_value_ = NULL; + return temp; + } + } else { + return NULL; + } +} +void Value::set_allocated_list_value(::google::protobuf::ListValue* list_value) { + clear_kind(); + if (list_value) { + if (GetArenaNoVirtual() != NULL && + ::google::protobuf::Arena::GetArena(list_value) == NULL) { + GetArenaNoVirtual()->Own(list_value); + } else if (GetArenaNoVirtual() != + ::google::protobuf::Arena::GetArena(list_value)) { + ::google::protobuf::ListValue* new_list_value = + ::google::protobuf::Arena::CreateMessage< ::google::protobuf::ListValue >( + GetArenaNoVirtual()); + new_list_value->CopyFrom(*list_value); + list_value = new_list_value; + } + set_has_list_value(); + kind_.list_value_ = list_value; + } + // @@protoc_insertion_point(field_set_allocated:google.protobuf.Value.list_value) +} + ::google::protobuf::ListValue* Value::unsafe_arena_release_list_value() { + // @@protoc_insertion_point(field_unsafe_arena_release:google.protobuf.Value.list_value) if (has_list_value()) { clear_has_kind(); ::google::protobuf::ListValue* temp = kind_.list_value_; @@ -1296,13 +1506,13 @@ void Value::clear_list_value() { return NULL; } } -void Value::set_allocated_list_value(::google::protobuf::ListValue* list_value) { + void Value::unsafe_arena_set_allocated_list_value(::google::protobuf::ListValue* list_value) { clear_kind(); if (list_value) { set_has_list_value(); kind_.list_value_ = list_value; } - // @@protoc_insertion_point(field_set_allocated:google.protobuf.Value.list_value) + // @@protoc_insertion_point(field_unsafe_arena_set_allocated:google.protobuf.Value.list_value) } bool Value::has_kind() const { @@ -1324,24 +1534,34 @@ const int ListValue::kValuesFieldNumber; ListValue::ListValue() : ::google::protobuf::Message(), _internal_metadata_(NULL) { + if (this != internal_default_instance()) protobuf_InitDefaults_google_2fprotobuf_2fstruct_2eproto(); SharedCtor(); // @@protoc_insertion_point(constructor:google.protobuf.ListValue) } +ListValue::ListValue(::google::protobuf::Arena* arena) + : ::google::protobuf::Message(), + _internal_metadata_(arena), + values_(arena) { +#ifdef GOOGLE_PROTOBUF_NO_STATIC_INITIALIZER + protobuf_InitDefaults_google_2fprotobuf_2fstruct_2eproto(); +#endif // GOOGLE_PROTOBUF_NO_STATIC_INITIALIZER + SharedCtor(); + RegisterArenaDtor(arena); + // @@protoc_insertion_point(arena_constructor:google.protobuf.ListValue) +} void ListValue::InitAsDefaultInstance() { - _is_default_instance_ = true; } ListValue::ListValue(const ListValue& from) : ::google::protobuf::Message(), _internal_metadata_(NULL) { SharedCtor(); - MergeFrom(from); + UnsafeMergeFrom(from); // @@protoc_insertion_point(copy_constructor:google.protobuf.ListValue) } void ListValue::SharedCtor() { - _is_default_instance_ = false; _cached_size_ = 0; } @@ -1351,10 +1571,19 @@ ListValue::~ListValue() { } void ListValue::SharedDtor() { - if (this != default_instance_) { + ::google::protobuf::Arena* arena = GetArenaNoVirtual(); + if (arena != NULL) { + return; } + } +void ListValue::ArenaDtor(void* object) { + ListValue* _this = reinterpret_cast< ListValue* >(object); + (void)_this; +} +void ListValue::RegisterArenaDtor(::google::protobuf::Arena* arena) { +} void ListValue::SetCachedSize(int size) const { GOOGLE_SAFE_CONCURRENT_WRITES_BEGIN(); _cached_size_ = size; @@ -1366,18 +1595,14 @@ const ::google::protobuf::Descriptor* ListValue::descriptor() { } const ListValue& ListValue::default_instance() { - if (default_instance_ == NULL) protobuf_AddDesc_google_2fprotobuf_2fstruct_2eproto(); - return *default_instance_; + protobuf_InitDefaults_google_2fprotobuf_2fstruct_2eproto(); + return *internal_default_instance(); } -ListValue* ListValue::default_instance_ = NULL; +::google::protobuf::internal::ExplicitlyConstructed ListValue::default_instance_; ListValue* ListValue::New(::google::protobuf::Arena* arena) const { - ListValue* n = new ListValue; - if (arena != NULL) { - arena->Own(n); - } - return n; + return ::google::protobuf::Arena::CreateMessage(arena); } void ListValue::Clear() { @@ -1459,30 +1684,32 @@ void ListValue::SerializeWithCachedSizes( return target; } -int ListValue::ByteSize() const { +size_t ListValue::ByteSizeLong() const { // @@protoc_insertion_point(message_byte_size_start:google.protobuf.ListValue) - int total_size = 0; + size_t total_size = 0; // repeated .google.protobuf.Value values = 1; - total_size += 1 * this->values_size(); - for (int i = 0; i < this->values_size(); i++) { - total_size += - ::google::protobuf::internal::WireFormatLite::MessageSizeNoVirtual( - this->values(i)); + { + unsigned int count = this->values_size(); + total_size += 1UL * count; + for (unsigned int i = 0; i < count; i++) { + total_size += + ::google::protobuf::internal::WireFormatLite::MessageSizeNoVirtual( + this->values(i)); + } } + int cached_size = ::google::protobuf::internal::ToCachedSize(total_size); GOOGLE_SAFE_CONCURRENT_WRITES_BEGIN(); - _cached_size_ = total_size; + _cached_size_ = cached_size; GOOGLE_SAFE_CONCURRENT_WRITES_END(); return total_size; } void ListValue::MergeFrom(const ::google::protobuf::Message& from) { // @@protoc_insertion_point(generalized_merge_from_start:google.protobuf.ListValue) - if (GOOGLE_PREDICT_FALSE(&from == this)) { - ::google::protobuf::internal::MergeFromFail(__FILE__, __LINE__); - } - const ListValue* source = + if (GOOGLE_PREDICT_FALSE(&from == this)) MergeFromFail(__LINE__); + const ListValue* source = ::google::protobuf::internal::DynamicCastToGenerated( &from); if (source == NULL) { @@ -1490,15 +1717,21 @@ void ListValue::MergeFrom(const ::google::protobuf::Message& from) { ::google::protobuf::internal::ReflectionOps::Merge(from, this); } else { // @@protoc_insertion_point(generalized_merge_from_cast_success:google.protobuf.ListValue) - MergeFrom(*source); + UnsafeMergeFrom(*source); } } void ListValue::MergeFrom(const ListValue& from) { // @@protoc_insertion_point(class_specific_merge_from_start:google.protobuf.ListValue) - if (GOOGLE_PREDICT_FALSE(&from == this)) { - ::google::protobuf::internal::MergeFromFail(__FILE__, __LINE__); + if (GOOGLE_PREDICT_TRUE(&from != this)) { + UnsafeMergeFrom(from); + } else { + MergeFromFail(__LINE__); } +} + +void ListValue::UnsafeMergeFrom(const ListValue& from) { + GOOGLE_DCHECK(&from != this); values_.MergeFrom(from.values_); } @@ -1513,7 +1746,7 @@ void ListValue::CopyFrom(const ListValue& from) { // @@protoc_insertion_point(class_specific_copy_from_start:google.protobuf.ListValue) if (&from == this) return; Clear(); - MergeFrom(from); + UnsafeMergeFrom(from); } bool ListValue::IsInitialized() const { @@ -1523,6 +1756,18 @@ bool ListValue::IsInitialized() const { void ListValue::Swap(ListValue* other) { if (other == this) return; + if (GetArenaNoVirtual() == other->GetArenaNoVirtual()) { + InternalSwap(other); + } else { + ListValue temp; + temp.UnsafeMergeFrom(*this); + CopyFrom(*other); + other->CopyFrom(temp); + } +} +void ListValue::UnsafeArenaSwap(ListValue* other) { + if (other == this) return; + GOOGLE_DCHECK(GetArenaNoVirtual() == other->GetArenaNoVirtual()); InternalSwap(other); } void ListValue::InternalSwap(ListValue* other) { diff --git a/src/google/protobuf/struct.pb.h b/src/google/protobuf/struct.pb.h index d98a12e2..34b9bfb8 100644 --- a/src/google/protobuf/struct.pb.h +++ b/src/google/protobuf/struct.pb.h @@ -37,6 +37,7 @@ namespace protobuf { // Internal implementation detail -- do not call these. void LIBPROTOBUF_EXPORT protobuf_AddDesc_google_2fprotobuf_2fstruct_2eproto(); +void LIBPROTOBUF_EXPORT protobuf_InitDefaults_google_2fprotobuf_2fstruct_2eproto(); void protobuf_AssignDesc_google_2fprotobuf_2fstruct_2eproto(); void protobuf_ShutdownFile_google_2fprotobuf_2fstruct_2eproto(); @@ -78,9 +79,18 @@ class LIBPROTOBUF_EXPORT Struct : public ::google::protobuf::Message /* @@protoc return *this; } + inline ::google::protobuf::Arena* GetArena() const { return GetArenaNoVirtual(); } + inline void* GetMaybeArenaPointer() const { + return MaybeArenaPtr(); + } static const ::google::protobuf::Descriptor* descriptor(); static const Struct& default_instance(); + static inline const Struct* internal_default_instance() { + return &default_instance_.get(); + } + + void UnsafeArenaSwap(Struct* other); void Swap(Struct* other); // implements Message ---------------------------------------------- @@ -95,7 +105,7 @@ class LIBPROTOBUF_EXPORT Struct : public ::google::protobuf::Message /* @@protoc void Clear(); bool IsInitialized() const; - int ByteSize() const; + size_t ByteSizeLong() const; bool MergePartialFromCodedStream( ::google::protobuf::io::CodedInputStream* input); void SerializeWithCachedSizes( @@ -111,6 +121,12 @@ class LIBPROTOBUF_EXPORT Struct : public ::google::protobuf::Message /* @@protoc void SharedDtor(); void SetCachedSize(int size) const; void InternalSwap(Struct* other); + void UnsafeMergeFrom(const Struct& from); + protected: + explicit Struct(::google::protobuf::Arena* arena); + private: + static void ArenaDtor(void* object); + inline void RegisterArenaDtor(::google::protobuf::Arena* arena); private: inline ::google::protobuf::Arena* GetArenaNoVirtual() const { return _internal_metadata_.arena(); @@ -140,7 +156,9 @@ class LIBPROTOBUF_EXPORT Struct : public ::google::protobuf::Message /* @@protoc private: ::google::protobuf::internal::InternalMetadataWithArena _internal_metadata_; - bool _is_default_instance_; + friend class ::google::protobuf::Arena; + typedef void InternalArenaConstructable_; + typedef void DestructorSkippable_; typedef ::google::protobuf::internal::MapEntryLite< ::std::string, ::google::protobuf::Value, ::google::protobuf::internal::WireFormatLite::TYPE_STRING, @@ -153,12 +171,13 @@ class LIBPROTOBUF_EXPORT Struct : public ::google::protobuf::Message /* @@protoc ::google::protobuf::internal::WireFormatLite::TYPE_MESSAGE, 0 > fields_; mutable int _cached_size_; - friend void LIBPROTOBUF_EXPORT protobuf_AddDesc_google_2fprotobuf_2fstruct_2eproto(); + friend void LIBPROTOBUF_EXPORT protobuf_InitDefaults_google_2fprotobuf_2fstruct_2eproto_impl(); + friend void LIBPROTOBUF_EXPORT protobuf_AddDesc_google_2fprotobuf_2fstruct_2eproto_impl(); friend void protobuf_AssignDesc_google_2fprotobuf_2fstruct_2eproto(); friend void protobuf_ShutdownFile_google_2fprotobuf_2fstruct_2eproto(); void InitAsDefaultInstance(); - static Struct* default_instance_; + static ::google::protobuf::internal::ExplicitlyConstructed default_instance_; }; // ------------------------------------------------------------------- @@ -174,6 +193,10 @@ class LIBPROTOBUF_EXPORT Value : public ::google::protobuf::Message /* @@protoc_ return *this; } + inline ::google::protobuf::Arena* GetArena() const { return GetArenaNoVirtual(); } + inline void* GetMaybeArenaPointer() const { + return MaybeArenaPtr(); + } static const ::google::protobuf::Descriptor* descriptor(); static const Value& default_instance(); @@ -187,6 +210,11 @@ class LIBPROTOBUF_EXPORT Value : public ::google::protobuf::Message /* @@protoc_ KIND_NOT_SET = 0, }; + static inline const Value* internal_default_instance() { + return &default_instance_.get(); + } + + void UnsafeArenaSwap(Value* other); void Swap(Value* other); // implements Message ---------------------------------------------- @@ -201,7 +229,7 @@ class LIBPROTOBUF_EXPORT Value : public ::google::protobuf::Message /* @@protoc_ void Clear(); bool IsInitialized() const; - int ByteSize() const; + size_t ByteSizeLong() const; bool MergePartialFromCodedStream( ::google::protobuf::io::CodedInputStream* input); void SerializeWithCachedSizes( @@ -217,6 +245,12 @@ class LIBPROTOBUF_EXPORT Value : public ::google::protobuf::Message /* @@protoc_ void SharedDtor(); void SetCachedSize(int size) const; void InternalSwap(Value* other); + void UnsafeMergeFrom(const Value& from); + protected: + explicit Value(::google::protobuf::Arena* arena); + private: + static void ArenaDtor(void* object); + inline void RegisterArenaDtor(::google::protobuf::Arena* arena); private: inline ::google::protobuf::Arena* GetArenaNoVirtual() const { return _internal_metadata_.arena(); @@ -263,6 +297,9 @@ class LIBPROTOBUF_EXPORT Value : public ::google::protobuf::Message /* @@protoc_ ::std::string* mutable_string_value(); ::std::string* release_string_value(); void set_allocated_string_value(::std::string* string_value); + ::std::string* unsafe_arena_release_string_value(); + void unsafe_arena_set_allocated_string_value( + ::std::string* string_value); // optional bool bool_value = 4; private: @@ -277,19 +314,37 @@ class LIBPROTOBUF_EXPORT Value : public ::google::protobuf::Message /* @@protoc_ bool has_struct_value() const; void clear_struct_value(); static const int kStructValueFieldNumber = 5; + private: + void _slow_mutable_struct_value(); + void _slow_set_allocated_struct_value( + ::google::protobuf::Arena* message_arena, ::google::protobuf::Struct** struct_value); + ::google::protobuf::Struct* _slow_release_struct_value(); + public: const ::google::protobuf::Struct& struct_value() const; ::google::protobuf::Struct* mutable_struct_value(); ::google::protobuf::Struct* release_struct_value(); void set_allocated_struct_value(::google::protobuf::Struct* struct_value); + ::google::protobuf::Struct* unsafe_arena_release_struct_value(); + void unsafe_arena_set_allocated_struct_value( + ::google::protobuf::Struct* struct_value); // optional .google.protobuf.ListValue list_value = 6; bool has_list_value() const; void clear_list_value(); static const int kListValueFieldNumber = 6; + private: + void _slow_mutable_list_value(); + void _slow_set_allocated_list_value( + ::google::protobuf::Arena* message_arena, ::google::protobuf::ListValue** list_value); + ::google::protobuf::ListValue* _slow_release_list_value(); + public: const ::google::protobuf::ListValue& list_value() const; ::google::protobuf::ListValue* mutable_list_value(); ::google::protobuf::ListValue* release_list_value(); void set_allocated_list_value(::google::protobuf::ListValue* list_value); + ::google::protobuf::ListValue* unsafe_arena_release_list_value(); + void unsafe_arena_set_allocated_list_value( + ::google::protobuf::ListValue* list_value); KindCase kind_case() const; // @@protoc_insertion_point(class_scope:google.protobuf.Value) @@ -306,7 +361,9 @@ class LIBPROTOBUF_EXPORT Value : public ::google::protobuf::Message /* @@protoc_ inline void clear_has_kind(); ::google::protobuf::internal::InternalMetadataWithArena _internal_metadata_; - bool _is_default_instance_; + friend class ::google::protobuf::Arena; + typedef void InternalArenaConstructable_; + typedef void DestructorSkippable_; union KindUnion { KindUnion() {} int null_value_; @@ -319,12 +376,13 @@ class LIBPROTOBUF_EXPORT Value : public ::google::protobuf::Message /* @@protoc_ mutable int _cached_size_; ::google::protobuf::uint32 _oneof_case_[1]; - friend void LIBPROTOBUF_EXPORT protobuf_AddDesc_google_2fprotobuf_2fstruct_2eproto(); + friend void LIBPROTOBUF_EXPORT protobuf_InitDefaults_google_2fprotobuf_2fstruct_2eproto_impl(); + friend void LIBPROTOBUF_EXPORT protobuf_AddDesc_google_2fprotobuf_2fstruct_2eproto_impl(); friend void protobuf_AssignDesc_google_2fprotobuf_2fstruct_2eproto(); friend void protobuf_ShutdownFile_google_2fprotobuf_2fstruct_2eproto(); void InitAsDefaultInstance(); - static Value* default_instance_; + static ::google::protobuf::internal::ExplicitlyConstructed default_instance_; }; // ------------------------------------------------------------------- @@ -340,9 +398,18 @@ class LIBPROTOBUF_EXPORT ListValue : public ::google::protobuf::Message /* @@pro return *this; } + inline ::google::protobuf::Arena* GetArena() const { return GetArenaNoVirtual(); } + inline void* GetMaybeArenaPointer() const { + return MaybeArenaPtr(); + } static const ::google::protobuf::Descriptor* descriptor(); static const ListValue& default_instance(); + static inline const ListValue* internal_default_instance() { + return &default_instance_.get(); + } + + void UnsafeArenaSwap(ListValue* other); void Swap(ListValue* other); // implements Message ---------------------------------------------- @@ -357,7 +424,7 @@ class LIBPROTOBUF_EXPORT ListValue : public ::google::protobuf::Message /* @@pro void Clear(); bool IsInitialized() const; - int ByteSize() const; + size_t ByteSizeLong() const; bool MergePartialFromCodedStream( ::google::protobuf::io::CodedInputStream* input); void SerializeWithCachedSizes( @@ -373,6 +440,12 @@ class LIBPROTOBUF_EXPORT ListValue : public ::google::protobuf::Message /* @@pro void SharedDtor(); void SetCachedSize(int size) const; void InternalSwap(ListValue* other); + void UnsafeMergeFrom(const ListValue& from); + protected: + explicit ListValue(::google::protobuf::Arena* arena); + private: + static void ArenaDtor(void* object); + inline void RegisterArenaDtor(::google::protobuf::Arena* arena); private: inline ::google::protobuf::Arena* GetArenaNoVirtual() const { return _internal_metadata_.arena(); @@ -404,15 +477,18 @@ class LIBPROTOBUF_EXPORT ListValue : public ::google::protobuf::Message /* @@pro private: ::google::protobuf::internal::InternalMetadataWithArena _internal_metadata_; - bool _is_default_instance_; + friend class ::google::protobuf::Arena; + typedef void InternalArenaConstructable_; + typedef void DestructorSkippable_; ::google::protobuf::RepeatedPtrField< ::google::protobuf::Value > values_; mutable int _cached_size_; - friend void LIBPROTOBUF_EXPORT protobuf_AddDesc_google_2fprotobuf_2fstruct_2eproto(); + friend void LIBPROTOBUF_EXPORT protobuf_InitDefaults_google_2fprotobuf_2fstruct_2eproto_impl(); + friend void LIBPROTOBUF_EXPORT protobuf_AddDesc_google_2fprotobuf_2fstruct_2eproto_impl(); friend void protobuf_AssignDesc_google_2fprotobuf_2fstruct_2eproto(); friend void protobuf_ShutdownFile_google_2fprotobuf_2fstruct_2eproto(); void InitAsDefaultInstance(); - static ListValue* default_instance_; + static ::google::protobuf::internal::ExplicitlyConstructed default_instance_; }; // =================================================================== @@ -511,25 +587,26 @@ inline void Value::set_has_string_value() { } inline void Value::clear_string_value() { if (has_string_value()) { - kind_.string_value_.DestroyNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); + kind_.string_value_.Destroy(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), + GetArenaNoVirtual()); clear_has_kind(); } } inline const ::std::string& Value::string_value() const { // @@protoc_insertion_point(field_get:google.protobuf.Value.string_value) if (has_string_value()) { - return kind_.string_value_.GetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); + return kind_.string_value_.Get(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); } return *&::google::protobuf::internal::GetEmptyStringAlreadyInited(); } inline void Value::set_string_value(const ::std::string& value) { - // @@protoc_insertion_point(field_set:google.protobuf.Value.string_value) if (!has_string_value()) { clear_kind(); set_has_string_value(); kind_.string_value_.UnsafeSetDefault(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); } - kind_.string_value_.SetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), value); + kind_.string_value_.Set(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), value, + GetArenaNoVirtual()); // @@protoc_insertion_point(field_set:google.protobuf.Value.string_value) } inline void Value::set_string_value(const char* value) { @@ -538,18 +615,20 @@ inline void Value::set_string_value(const char* value) { set_has_string_value(); kind_.string_value_.UnsafeSetDefault(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); } - kind_.string_value_.SetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), - ::std::string(value)); + kind_.string_value_.Set(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), + ::std::string(value), GetArenaNoVirtual()); // @@protoc_insertion_point(field_set_char:google.protobuf.Value.string_value) } -inline void Value::set_string_value(const char* value, size_t size) { +inline void Value::set_string_value(const char* value, + size_t size) { if (!has_string_value()) { clear_kind(); set_has_string_value(); kind_.string_value_.UnsafeSetDefault(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); } - kind_.string_value_.SetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), ::std::string( - reinterpret_cast(value), size)); + kind_.string_value_.Set(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), ::std::string( + reinterpret_cast(value), size), + GetArenaNoVirtual()); // @@protoc_insertion_point(field_set_pointer:google.protobuf.Value.string_value) } inline ::std::string* Value::mutable_string_value() { @@ -558,14 +637,27 @@ inline ::std::string* Value::mutable_string_value() { set_has_string_value(); kind_.string_value_.UnsafeSetDefault(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); } + return kind_.string_value_.Mutable(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), + GetArenaNoVirtual()); // @@protoc_insertion_point(field_mutable:google.protobuf.Value.string_value) - return kind_.string_value_.MutableNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); } inline ::std::string* Value::release_string_value() { // @@protoc_insertion_point(field_release:google.protobuf.Value.string_value) if (has_string_value()) { clear_has_kind(); - return kind_.string_value_.ReleaseNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); + return kind_.string_value_.Release(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), + GetArenaNoVirtual()); + } else { + return NULL; + } +} +inline ::std::string* Value::unsafe_arena_release_string_value() { + // @@protoc_insertion_point(field_unsafe_arena_release:google.protobuf.Value.string_value) + GOOGLE_DCHECK(GetArenaNoVirtual() != NULL); + if (has_string_value()) { + clear_has_kind(); + return kind_.string_value_.UnsafeArenaRelease( + &::google::protobuf::internal::GetEmptyStringAlreadyInited(), GetArenaNoVirtual()); } else { return NULL; } @@ -577,11 +669,23 @@ inline void Value::set_allocated_string_value(::std::string* string_value) { clear_kind(); if (string_value != NULL) { set_has_string_value(); - kind_.string_value_.SetAllocatedNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), - string_value); + kind_.string_value_.SetAllocated(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), string_value, + GetArenaNoVirtual()); } // @@protoc_insertion_point(field_set_allocated:google.protobuf.Value.string_value) } +inline void Value::unsafe_arena_set_allocated_string_value(::std::string* string_value) { + GOOGLE_DCHECK(GetArenaNoVirtual() != NULL); + if (!has_string_value()) { + kind_.string_value_.UnsafeSetDefault(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); + } + clear_kind(); + if (string_value) { + set_has_string_value(); + kind_.string_value_.UnsafeArenaSetAllocated(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), string_value, GetArenaNoVirtual()); + } + // @@protoc_insertion_point(field_unsafe_arena_set_allocated:google.protobuf.Value.string_value) +} // optional bool bool_value = 4; inline bool Value::has_bool_value() const { @@ -621,7 +725,9 @@ inline void Value::set_has_struct_value() { } inline void Value::clear_struct_value() { if (has_struct_value()) { - delete kind_.struct_value_; + if (GetArenaNoVirtual() == NULL) { + delete kind_.struct_value_; + } clear_has_kind(); } } @@ -635,13 +741,51 @@ inline ::google::protobuf::Struct* Value::mutable_struct_value() { if (!has_struct_value()) { clear_kind(); set_has_struct_value(); - kind_.struct_value_ = new ::google::protobuf::Struct; + kind_.struct_value_ = + ::google::protobuf::Arena::CreateMessage< ::google::protobuf::Struct >( + GetArenaNoVirtual()); } // @@protoc_insertion_point(field_mutable:google.protobuf.Value.struct_value) return kind_.struct_value_; } inline ::google::protobuf::Struct* Value::release_struct_value() { // @@protoc_insertion_point(field_release:google.protobuf.Value.struct_value) + if (has_struct_value()) { + clear_has_kind(); + if (GetArenaNoVirtual() != NULL) { + ::google::protobuf::Struct* temp = new ::google::protobuf::Struct(*kind_.struct_value_); + kind_.struct_value_ = NULL; + return temp; + } else { + ::google::protobuf::Struct* temp = kind_.struct_value_; + kind_.struct_value_ = NULL; + return temp; + } + } else { + return NULL; + } +} +inline void Value::set_allocated_struct_value(::google::protobuf::Struct* struct_value) { + clear_kind(); + if (struct_value) { + if (GetArenaNoVirtual() != NULL && + ::google::protobuf::Arena::GetArena(struct_value) == NULL) { + GetArenaNoVirtual()->Own(struct_value); + } else if (GetArenaNoVirtual() != + ::google::protobuf::Arena::GetArena(struct_value)) { + ::google::protobuf::Struct* new_struct_value = + ::google::protobuf::Arena::CreateMessage< ::google::protobuf::Struct >( + GetArenaNoVirtual()); + new_struct_value->CopyFrom(*struct_value); + struct_value = new_struct_value; + } + set_has_struct_value(); + kind_.struct_value_ = struct_value; + } + // @@protoc_insertion_point(field_set_allocated:google.protobuf.Value.struct_value) +} +inline ::google::protobuf::Struct* Value::unsafe_arena_release_struct_value() { + // @@protoc_insertion_point(field_unsafe_arena_release:google.protobuf.Value.struct_value) if (has_struct_value()) { clear_has_kind(); ::google::protobuf::Struct* temp = kind_.struct_value_; @@ -651,13 +795,13 @@ inline ::google::protobuf::Struct* Value::release_struct_value() { return NULL; } } -inline void Value::set_allocated_struct_value(::google::protobuf::Struct* struct_value) { +inline void Value::unsafe_arena_set_allocated_struct_value(::google::protobuf::Struct* struct_value) { clear_kind(); if (struct_value) { set_has_struct_value(); kind_.struct_value_ = struct_value; } - // @@protoc_insertion_point(field_set_allocated:google.protobuf.Value.struct_value) + // @@protoc_insertion_point(field_unsafe_arena_set_allocated:google.protobuf.Value.struct_value) } // optional .google.protobuf.ListValue list_value = 6; @@ -669,7 +813,9 @@ inline void Value::set_has_list_value() { } inline void Value::clear_list_value() { if (has_list_value()) { - delete kind_.list_value_; + if (GetArenaNoVirtual() == NULL) { + delete kind_.list_value_; + } clear_has_kind(); } } @@ -683,13 +829,51 @@ inline ::google::protobuf::ListValue* Value::mutable_list_value() { if (!has_list_value()) { clear_kind(); set_has_list_value(); - kind_.list_value_ = new ::google::protobuf::ListValue; + kind_.list_value_ = + ::google::protobuf::Arena::CreateMessage< ::google::protobuf::ListValue >( + GetArenaNoVirtual()); } // @@protoc_insertion_point(field_mutable:google.protobuf.Value.list_value) return kind_.list_value_; } inline ::google::protobuf::ListValue* Value::release_list_value() { // @@protoc_insertion_point(field_release:google.protobuf.Value.list_value) + if (has_list_value()) { + clear_has_kind(); + if (GetArenaNoVirtual() != NULL) { + ::google::protobuf::ListValue* temp = new ::google::protobuf::ListValue(*kind_.list_value_); + kind_.list_value_ = NULL; + return temp; + } else { + ::google::protobuf::ListValue* temp = kind_.list_value_; + kind_.list_value_ = NULL; + return temp; + } + } else { + return NULL; + } +} +inline void Value::set_allocated_list_value(::google::protobuf::ListValue* list_value) { + clear_kind(); + if (list_value) { + if (GetArenaNoVirtual() != NULL && + ::google::protobuf::Arena::GetArena(list_value) == NULL) { + GetArenaNoVirtual()->Own(list_value); + } else if (GetArenaNoVirtual() != + ::google::protobuf::Arena::GetArena(list_value)) { + ::google::protobuf::ListValue* new_list_value = + ::google::protobuf::Arena::CreateMessage< ::google::protobuf::ListValue >( + GetArenaNoVirtual()); + new_list_value->CopyFrom(*list_value); + list_value = new_list_value; + } + set_has_list_value(); + kind_.list_value_ = list_value; + } + // @@protoc_insertion_point(field_set_allocated:google.protobuf.Value.list_value) +} +inline ::google::protobuf::ListValue* Value::unsafe_arena_release_list_value() { + // @@protoc_insertion_point(field_unsafe_arena_release:google.protobuf.Value.list_value) if (has_list_value()) { clear_has_kind(); ::google::protobuf::ListValue* temp = kind_.list_value_; @@ -699,13 +883,13 @@ inline ::google::protobuf::ListValue* Value::release_list_value() { return NULL; } } -inline void Value::set_allocated_list_value(::google::protobuf::ListValue* list_value) { +inline void Value::unsafe_arena_set_allocated_list_value(::google::protobuf::ListValue* list_value) { clear_kind(); if (list_value) { set_has_list_value(); kind_.list_value_ = list_value; } - // @@protoc_insertion_point(field_set_allocated:google.protobuf.Value.list_value) + // @@protoc_insertion_point(field_unsafe_arena_set_allocated:google.protobuf.Value.list_value) } inline bool Value::has_kind() const { diff --git a/src/google/protobuf/struct.proto b/src/google/protobuf/struct.proto index beeba811..7d7808e7 100644 --- a/src/google/protobuf/struct.proto +++ b/src/google/protobuf/struct.proto @@ -33,11 +33,11 @@ syntax = "proto3"; package google.protobuf; option csharp_namespace = "Google.Protobuf.WellKnownTypes"; +option cc_enable_arenas = true; option go_package = "github.com/golang/protobuf/ptypes/struct;structpb"; option java_package = "com.google.protobuf"; option java_outer_classname = "StructProto"; option java_multiple_files = true; -option java_generate_equals_and_hash = true; option objc_class_prefix = "GPB"; diff --git a/src/google/protobuf/stubs/port.h b/src/google/protobuf/stubs/port.h index d7f93b4c..376be5f7 100644 --- a/src/google/protobuf/stubs/port.h +++ b/src/google/protobuf/stubs/port.h @@ -326,6 +326,61 @@ static inline uint64 bswap_64(uint64 x) { #endif +// =================================================================== +// from google3/util/bits/bits.h + +class Bits { + public: + static uint32 Log2FloorNonZero(uint32 n) { +#if defined(__GNUC__) + return 31 ^ __builtin_clz(n); +#elif defined(COMPILER_MSVC) && defined(_M_IX86) + _asm { + bsr ebx, n + mov n, ebx + } + return n; +#else + return Log2FloorNonZero_Portable(n); +#endif + } + + static uint64 Log2FloorNonZero64(uint64 n) { +#if defined(__GNUC__) + return 63 ^ __builtin_clzll(n); +#else + return Log2FloorNonZero64_Portable(n); +#endif + } + private: + static int Log2FloorNonZero_Portable(uint32 n) { + if (n == 0) + return -1; + int log = 0; + uint32 value = n; + for (int i = 4; i >= 0; --i) { + int shift = (1 << i); + uint32 x = value >> shift; + if (x != 0) { + value = x; + log += shift; + } + } + assert(value == 1); + return log; + } + + static int Log2FloorNonZero64_Portable(uint64 n) { + const uint32 topbits = static_cast(n >> 32); + if (topbits == 0) { + // Top bits are zero, so scan in bottom bits + return Log2FloorNonZero(static_cast(n)); + } else { + return 32 + Log2FloorNonZero(topbits); + } + } +}; + // =================================================================== // from google3/util/endian/endian.h LIBPROTOBUF_EXPORT uint32 ghtonl(uint32 x); diff --git a/src/google/protobuf/stubs/strutil.cc b/src/google/protobuf/stubs/strutil.cc index 7ba92e8f..4fa8e99f 100644 --- a/src/google/protobuf/stubs/strutil.cc +++ b/src/google/protobuf/stubs/strutil.cc @@ -93,6 +93,21 @@ void StripString(string* s, const char* remove, char replacewith) { } } +// ---------------------------------------------------------------------- +// ReplaceCharacters +// Replaces any occurrence of the character 'remove' (or the characters +// in 'remove') with the character 'replacewith'. +// ---------------------------------------------------------------------- +void ReplaceCharacters(string *s, const char *remove, char replacewith) { + const char *str_start = s->c_str(); + const char *str = str_start; + for (str = strpbrk(str, remove); + str != NULL; + str = strpbrk(str + 1, remove)) { + (*s)[str - str_start] = replacewith; + } +} + void StripWhitespace(string* str) { int str_length = str->length(); diff --git a/src/google/protobuf/stubs/strutil.h b/src/google/protobuf/stubs/strutil.h index 8bdd6110..df28c94d 100644 --- a/src/google/protobuf/stubs/strutil.h +++ b/src/google/protobuf/stubs/strutil.h @@ -147,7 +147,7 @@ inline string StripSuffixString(const string& str, const string& suffix) { } // ---------------------------------------------------------------------- -// StripString +// ReplaceCharacters // Replaces any occurrence of the character 'remove' (or the characters // in 'remove') with the character 'replacewith'. // Good for keeping html characters or protocol characters (\t) out @@ -155,6 +155,8 @@ inline string StripSuffixString(const string& str, const string& suffix) { // StripWhitespace // Removes whitespaces from both ends of the given string. // ---------------------------------------------------------------------- +LIBPROTOBUF_EXPORT void ReplaceCharacters(string* s, const char* remove, + char replacewith); LIBPROTOBUF_EXPORT void StripString(string* s, const char* remove, char replacewith); diff --git a/src/google/protobuf/text_format.cc b/src/google/protobuf/text_format.cc index 66b2648b..5192eca9 100644 --- a/src/google/protobuf/text_format.cc +++ b/src/google/protobuf/text_format.cc @@ -393,6 +393,16 @@ class TextFormat::Parser::ParserImpl { DO(ConsumeAnyValue(full_type_name, message->GetDescriptor()->file()->pool(), &serialized_value)); + if (singular_overwrite_policy_ == FORBID_SINGULAR_OVERWRITES) { + // Fail if any_type_url_field has already been specified. + if ((!any_type_url_field->is_repeated() && + reflection->HasField(*message, any_type_url_field)) || + (!any_value_field->is_repeated() && + reflection->HasField(*message, any_value_field))) { + ReportError("Non-repeated Any specified multiple times."); + return false; + } + } reflection->SetString( message, any_type_url_field, string(prefix + full_type_name)); @@ -515,18 +525,21 @@ class TextFormat::Parser::ParserImpl { } if (field->is_repeated() && TryConsume("[")) { - // Short repeated format, e.g. "foo: [1, 2, 3]" - while (true) { - if (field->cpp_type() == FieldDescriptor::CPPTYPE_MESSAGE) { - // Perform special handling for embedded message types. - DO(ConsumeFieldMessage(message, reflection, field)); - } else { - DO(ConsumeFieldValue(message, reflection, field)); - } - if (TryConsume("]")) { - break; + // Short repeated format, e.g. "foo: [1, 2, 3]". + if (!TryConsume("]")) { + // "foo: []" is treated as empty. + while (true) { + if (field->cpp_type() == FieldDescriptor::CPPTYPE_MESSAGE) { + // Perform special handling for embedded message types. + DO(ConsumeFieldMessage(message, reflection, field)); + } else { + DO(ConsumeFieldValue(message, reflection, field)); + } + if (TryConsume("]")) { + break; + } + DO(Consume(",")); } - DO(Consume(",")); } } else if (field->cpp_type() == FieldDescriptor::CPPTYPE_MESSAGE) { DO(ConsumeFieldMessage(message, reflection, field)); diff --git a/src/google/protobuf/text_format.h b/src/google/protobuf/text_format.h index ef3d4a8f..2873d339 100644 --- a/src/google/protobuf/text_format.h +++ b/src/google/protobuf/text_format.h @@ -75,6 +75,8 @@ class LIBPROTOBUF_EXPORT TextFormat { io::ZeroCopyOutputStream* output); // Like Print(), but outputs directly to a string. + // Note: output will be cleared before prior to printing, and will + // be left empty even if printing fails. static bool PrintToString(const Message& message, string* output); // Like PrintUnknownFields(), but outputs directly to a string. @@ -301,8 +303,8 @@ class LIBPROTOBUF_EXPORT TextFormat { int64 truncate_string_field_longer_than_; google::protobuf::scoped_ptr default_field_value_printer_; - typedef map CustomPrinterMap; + typedef std::map CustomPrinterMap; CustomPrinterMap custom_printers_; }; @@ -391,11 +393,13 @@ class LIBPROTOBUF_EXPORT TextFormat { ParseInfoTree* CreateNested(const FieldDescriptor* field); // Defines the map from the index-th field descriptor to its parse location. - typedef map > LocationMap; + typedef std::map > LocationMap; // Defines the map from the index-th field descriptor to the nested parse // info tree. - typedef map > NestedMap; + typedef std::map > NestedMap; LocationMap locations_; NestedMap nested_; diff --git a/src/google/protobuf/text_format_unittest.cc b/src/google/protobuf/text_format_unittest.cc index c9521cc3..2f1bd455 100644 --- a/src/google/protobuf/text_format_unittest.cc +++ b/src/google/protobuf/text_format_unittest.cc @@ -157,7 +157,21 @@ TEST_F(TextFormatTest, ShortPrimitiveRepeateds) { TextFormat::Printer printer; printer.SetUseShortRepeatedPrimitives(true); string text; - printer.PrintToString(proto_, &text); + EXPECT_TRUE(printer.PrintToString(proto_, &text)); + + EXPECT_EQ("optional_int32: 123\n" + "repeated_int32: [456, 789]\n" + "repeated_string: \"foo\"\n" + "repeated_string: \"bar\"\n" + "repeated_nested_message {\n bb: 2\n}\n" + "repeated_nested_message {\n bb: 3\n}\n" + "repeated_nested_enum: [FOO, BAR]\n", + text); + + // Verify that any existing data in the string is cleared when + // PrintToString() is called. + text = "just some data here...\n\nblah blah"; + EXPECT_TRUE(printer.PrintToString(proto_, &text)); EXPECT_EQ("optional_int32: 123\n" "repeated_int32: [456, 789]\n" @@ -170,7 +184,7 @@ TEST_F(TextFormatTest, ShortPrimitiveRepeateds) { // Try in single-line mode. printer.SetSingleLineMode(true); - printer.PrintToString(proto_, &text); + EXPECT_TRUE(printer.PrintToString(proto_, &text)); EXPECT_EQ("optional_int32: 123 " "repeated_int32: [456, 789] " @@ -659,6 +673,87 @@ TEST_F(TextFormatTest, ParseShortRepeatedForm) { EXPECT_EQ(4, proto_.repeatedgroup(1).a()); } +TEST_F(TextFormatTest, ParseShortRepeatedWithTrailingComma) { + string parse_string = "repeated_int32: [456,]\n"; + ASSERT_FALSE(TextFormat::ParseFromString(parse_string, &proto_)); + parse_string = "repeated_nested_enum: [ FOO , ]"; + ASSERT_FALSE(TextFormat::ParseFromString(parse_string, &proto_)); + parse_string = "repeated_string: [ \"foo\", ]"; + ASSERT_FALSE(TextFormat::ParseFromString(parse_string, &proto_)); + parse_string = "repeated_nested_message: [ { bb: 1 }, ]"; + ASSERT_FALSE(TextFormat::ParseFromString(parse_string, &proto_)); + parse_string = "RepeatedGroup [{ a: 3 },]\n"; +} + +TEST_F(TextFormatTest, ParseShortRepeatedEmpty) { + string parse_string = + "repeated_int32: []\n" + "repeated_nested_enum: []\n" + "repeated_string: []\n" + "repeated_nested_message: []\n" + "RepeatedGroup []\n"; + + ASSERT_TRUE(TextFormat::ParseFromString(parse_string, &proto_)); + + EXPECT_EQ(0, proto_.repeated_int32_size()); + EXPECT_EQ(0, proto_.repeated_nested_enum_size()); + EXPECT_EQ(0, proto_.repeated_string_size()); + EXPECT_EQ(0, proto_.repeated_nested_message_size()); + EXPECT_EQ(0, proto_.repeatedgroup_size()); +} + +TEST_F(TextFormatTest, ParseShortRepeatedConcatenatedWithEmpty) { + string parse_string = + // Starting with empty [] should have no impact. + "repeated_int32: []\n" + "repeated_nested_enum: []\n" + "repeated_string: []\n" + "repeated_nested_message: []\n" + "RepeatedGroup []\n" + // Mixed short-form and long-form are simply concatenated. + "repeated_int32: 1\n" + "repeated_int32: [456, 789]\n" + "repeated_nested_enum: [ FOO ,BAR, # comment\n" + " 3]\n" + // Note that while the printer won't print repeated strings in short-form, + // the parser will accept them. + "repeated_string: [ \"foo\", 'bar' ]\n" + // Repeated message + "repeated_nested_message: [ { bb: 1 }, { bb : 2 }]\n" + // Repeated group + "RepeatedGroup [{ a: 3 },{ a: 4 }]\n" + // Adding empty [] should have no impact. + "repeated_int32: []\n" + "repeated_nested_enum: []\n" + "repeated_string: []\n" + "repeated_nested_message: []\n" + "RepeatedGroup []\n"; + + ASSERT_TRUE(TextFormat::ParseFromString(parse_string, &proto_)); + + ASSERT_EQ(3, proto_.repeated_int32_size()); + EXPECT_EQ(1, proto_.repeated_int32(0)); + EXPECT_EQ(456, proto_.repeated_int32(1)); + EXPECT_EQ(789, proto_.repeated_int32(2)); + + ASSERT_EQ(3, proto_.repeated_nested_enum_size()); + EXPECT_EQ(unittest::TestAllTypes::FOO, proto_.repeated_nested_enum(0)); + EXPECT_EQ(unittest::TestAllTypes::BAR, proto_.repeated_nested_enum(1)); + EXPECT_EQ(unittest::TestAllTypes::BAZ, proto_.repeated_nested_enum(2)); + + ASSERT_EQ(2, proto_.repeated_string_size()); + EXPECT_EQ("foo", proto_.repeated_string(0)); + EXPECT_EQ("bar", proto_.repeated_string(1)); + + ASSERT_EQ(2, proto_.repeated_nested_message_size()); + EXPECT_EQ(1, proto_.repeated_nested_message(0).bb()); + EXPECT_EQ(2, proto_.repeated_nested_message(1).bb()); + + ASSERT_EQ(2, proto_.repeatedgroup_size()); + EXPECT_EQ(3, proto_.repeatedgroup(0).a()); + EXPECT_EQ(4, proto_.repeatedgroup(1).a()); +} + TEST_F(TextFormatTest, Comments) { // Test that comments are ignored. diff --git a/src/google/protobuf/timestamp.pb.cc b/src/google/protobuf/timestamp.pb.cc index e6c9c58b..54c6e868 100644 --- a/src/google/protobuf/timestamp.pb.cc +++ b/src/google/protobuf/timestamp.pb.cc @@ -44,20 +44,19 @@ void protobuf_AssignDesc_google_2fprotobuf_2ftimestamp_2eproto() { Timestamp_reflection_ = ::google::protobuf::internal::GeneratedMessageReflection::NewGeneratedMessageReflection( Timestamp_descriptor_, - Timestamp::default_instance_, + Timestamp::internal_default_instance(), Timestamp_offsets_, -1, -1, -1, sizeof(Timestamp), - GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(Timestamp, _internal_metadata_), - GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(Timestamp, _is_default_instance_)); + GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(Timestamp, _internal_metadata_)); } namespace { GOOGLE_PROTOBUF_DECLARE_ONCE(protobuf_AssignDescriptors_once_); -inline void protobuf_AssignDescriptorsOnce() { +void protobuf_AssignDescriptorsOnce() { ::google::protobuf::GoogleOnceInit(&protobuf_AssignDescriptors_once_, &protobuf_AssignDesc_google_2fprotobuf_2ftimestamp_2eproto); } @@ -66,37 +65,48 @@ void protobuf_RegisterTypes(const ::std::string&) GOOGLE_ATTRIBUTE_COLD; void protobuf_RegisterTypes(const ::std::string&) { protobuf_AssignDescriptorsOnce(); ::google::protobuf::MessageFactory::InternalRegisterGeneratedMessage( - Timestamp_descriptor_, &Timestamp::default_instance()); + Timestamp_descriptor_, Timestamp::internal_default_instance()); } } // namespace void protobuf_ShutdownFile_google_2fprotobuf_2ftimestamp_2eproto() { - delete Timestamp::default_instance_; delete Timestamp_reflection_; } -void protobuf_AddDesc_google_2fprotobuf_2ftimestamp_2eproto() GOOGLE_ATTRIBUTE_COLD; -void protobuf_AddDesc_google_2fprotobuf_2ftimestamp_2eproto() { - static bool already_here = false; - if (already_here) return; - already_here = true; +void protobuf_InitDefaults_google_2fprotobuf_2ftimestamp_2eproto_impl() { + GOOGLE_PROTOBUF_VERIFY_VERSION; + + Timestamp::default_instance_.DefaultConstruct(); + Timestamp::default_instance_.get_mutable()->InitAsDefaultInstance(); +} + +GOOGLE_PROTOBUF_DECLARE_ONCE(protobuf_InitDefaults_google_2fprotobuf_2ftimestamp_2eproto_once_); +void protobuf_InitDefaults_google_2fprotobuf_2ftimestamp_2eproto() { + ::google::protobuf::GoogleOnceInit(&protobuf_InitDefaults_google_2fprotobuf_2ftimestamp_2eproto_once_, + &protobuf_InitDefaults_google_2fprotobuf_2ftimestamp_2eproto_impl); +} +void protobuf_AddDesc_google_2fprotobuf_2ftimestamp_2eproto_impl() { GOOGLE_PROTOBUF_VERIFY_VERSION; + protobuf_InitDefaults_google_2fprotobuf_2ftimestamp_2eproto(); ::google::protobuf::DescriptorPool::InternalAddGeneratedFile( "\n\037google/protobuf/timestamp.proto\022\017googl" "e.protobuf\"+\n\tTimestamp\022\017\n\007seconds\030\001 \001(\003" - "\022\r\n\005nanos\030\002 \001(\005B\201\001\n\023com.google.protobufB" - "\016TimestampProtoP\001Z+github.com/golang/pro" - "tobuf/ptypes/timestamp\240\001\001\370\001\001\242\002\003GPB\252\002\036Goo" - "gle.Protobuf.WellKnownTypesb\006proto3", 235); + "\022\r\n\005nanos\030\002 \001(\005B~\n\023com.google.protobufB\016" + "TimestampProtoP\001Z+github.com/golang/prot" + "obuf/ptypes/timestamp\370\001\001\242\002\003GPB\252\002\036Google." + "Protobuf.WellKnownTypesb\006proto3", 231); ::google::protobuf::MessageFactory::InternalRegisterGeneratedFile( "google/protobuf/timestamp.proto", &protobuf_RegisterTypes); - Timestamp::default_instance_ = new Timestamp(); - Timestamp::default_instance_->InitAsDefaultInstance(); ::google::protobuf::internal::OnShutdown(&protobuf_ShutdownFile_google_2fprotobuf_2ftimestamp_2eproto); } +GOOGLE_PROTOBUF_DECLARE_ONCE(protobuf_AddDesc_google_2fprotobuf_2ftimestamp_2eproto_once_); +void protobuf_AddDesc_google_2fprotobuf_2ftimestamp_2eproto() { + ::google::protobuf::GoogleOnceInit(&protobuf_AddDesc_google_2fprotobuf_2ftimestamp_2eproto_once_, + &protobuf_AddDesc_google_2fprotobuf_2ftimestamp_2eproto_impl); +} // Force AddDescriptors() to be called at static initialization time. struct StaticDescriptorInitializer_google_2fprotobuf_2ftimestamp_2eproto { StaticDescriptorInitializer_google_2fprotobuf_2ftimestamp_2eproto() { @@ -104,6 +114,16 @@ struct StaticDescriptorInitializer_google_2fprotobuf_2ftimestamp_2eproto { } } static_descriptor_initializer_google_2fprotobuf_2ftimestamp_2eproto_; +namespace { + +static void MergeFromFail(int line) GOOGLE_ATTRIBUTE_COLD GOOGLE_ATTRIBUTE_NORETURN; +static void MergeFromFail(int line) { + ::google::protobuf::internal::MergeFromFail(__FILE__, line); +} + +} // namespace + + // =================================================================== #if !defined(_MSC_VER) || _MSC_VER >= 1900 @@ -113,35 +133,36 @@ const int Timestamp::kNanosFieldNumber; Timestamp::Timestamp() : ::google::protobuf::Message(), _internal_metadata_(NULL) { + if (this != internal_default_instance()) protobuf_InitDefaults_google_2fprotobuf_2ftimestamp_2eproto(); SharedCtor(); // @@protoc_insertion_point(constructor:google.protobuf.Timestamp) } - Timestamp::Timestamp(::google::protobuf::Arena* arena) : ::google::protobuf::Message(), _internal_metadata_(arena) { +#ifdef GOOGLE_PROTOBUF_NO_STATIC_INITIALIZER + protobuf_InitDefaults_google_2fprotobuf_2ftimestamp_2eproto(); +#endif // GOOGLE_PROTOBUF_NO_STATIC_INITIALIZER SharedCtor(); RegisterArenaDtor(arena); // @@protoc_insertion_point(arena_constructor:google.protobuf.Timestamp) } void Timestamp::InitAsDefaultInstance() { - _is_default_instance_ = true; } Timestamp::Timestamp(const Timestamp& from) : ::google::protobuf::Message(), _internal_metadata_(NULL) { SharedCtor(); - MergeFrom(from); + UnsafeMergeFrom(from); // @@protoc_insertion_point(copy_constructor:google.protobuf.Timestamp) } void Timestamp::SharedCtor() { - _is_default_instance_ = false; + ::memset(&seconds_, 0, reinterpret_cast(&nanos_) - + reinterpret_cast(&seconds_) + sizeof(nanos_)); _cached_size_ = 0; - seconds_ = GOOGLE_LONGLONG(0); - nanos_ = 0; } Timestamp::~Timestamp() { @@ -150,12 +171,11 @@ Timestamp::~Timestamp() { } void Timestamp::SharedDtor() { - if (GetArenaNoVirtual() != NULL) { + ::google::protobuf::Arena* arena = GetArenaNoVirtual(); + if (arena != NULL) { return; } - if (this != default_instance_) { - } } void Timestamp::ArenaDtor(void* object) { @@ -175,11 +195,11 @@ const ::google::protobuf::Descriptor* Timestamp::descriptor() { } const Timestamp& Timestamp::default_instance() { - if (default_instance_ == NULL) protobuf_AddDesc_google_2fprotobuf_2ftimestamp_2eproto(); - return *default_instance_; + protobuf_InitDefaults_google_2fprotobuf_2ftimestamp_2eproto(); + return *internal_default_instance(); } -Timestamp* Timestamp::default_instance_ = NULL; +::google::protobuf::internal::ExplicitlyConstructed Timestamp::default_instance_; Timestamp* Timestamp::New(::google::protobuf::Arena* arena) const { return ::google::protobuf::Arena::CreateMessage(arena); @@ -223,10 +243,10 @@ bool Timestamp::MergePartialFromCodedStream( // optional int64 seconds = 1; case 1: { if (tag == 8) { + DO_((::google::protobuf::internal::WireFormatLite::ReadPrimitive< ::google::protobuf::int64, ::google::protobuf::internal::WireFormatLite::TYPE_INT64>( input, &seconds_))); - } else { goto handle_unusual; } @@ -238,10 +258,10 @@ bool Timestamp::MergePartialFromCodedStream( case 2: { if (tag == 16) { parse_nanos: + DO_((::google::protobuf::internal::WireFormatLite::ReadPrimitive< ::google::protobuf::int32, ::google::protobuf::internal::WireFormatLite::TYPE_INT32>( input, &nanos_))); - } else { goto handle_unusual; } @@ -304,9 +324,9 @@ void Timestamp::SerializeWithCachedSizes( return target; } -int Timestamp::ByteSize() const { +size_t Timestamp::ByteSizeLong() const { // @@protoc_insertion_point(message_byte_size_start:google.protobuf.Timestamp) - int total_size = 0; + size_t total_size = 0; // optional int64 seconds = 1; if (this->seconds() != 0) { @@ -322,18 +342,17 @@ int Timestamp::ByteSize() const { this->nanos()); } + int cached_size = ::google::protobuf::internal::ToCachedSize(total_size); GOOGLE_SAFE_CONCURRENT_WRITES_BEGIN(); - _cached_size_ = total_size; + _cached_size_ = cached_size; GOOGLE_SAFE_CONCURRENT_WRITES_END(); return total_size; } void Timestamp::MergeFrom(const ::google::protobuf::Message& from) { // @@protoc_insertion_point(generalized_merge_from_start:google.protobuf.Timestamp) - if (GOOGLE_PREDICT_FALSE(&from == this)) { - ::google::protobuf::internal::MergeFromFail(__FILE__, __LINE__); - } - const Timestamp* source = + if (GOOGLE_PREDICT_FALSE(&from == this)) MergeFromFail(__LINE__); + const Timestamp* source = ::google::protobuf::internal::DynamicCastToGenerated( &from); if (source == NULL) { @@ -341,15 +360,21 @@ void Timestamp::MergeFrom(const ::google::protobuf::Message& from) { ::google::protobuf::internal::ReflectionOps::Merge(from, this); } else { // @@protoc_insertion_point(generalized_merge_from_cast_success:google.protobuf.Timestamp) - MergeFrom(*source); + UnsafeMergeFrom(*source); } } void Timestamp::MergeFrom(const Timestamp& from) { // @@protoc_insertion_point(class_specific_merge_from_start:google.protobuf.Timestamp) - if (GOOGLE_PREDICT_FALSE(&from == this)) { - ::google::protobuf::internal::MergeFromFail(__FILE__, __LINE__); + if (GOOGLE_PREDICT_TRUE(&from != this)) { + UnsafeMergeFrom(from); + } else { + MergeFromFail(__LINE__); } +} + +void Timestamp::UnsafeMergeFrom(const Timestamp& from) { + GOOGLE_DCHECK(&from != this); if (from.seconds() != 0) { set_seconds(from.seconds()); } @@ -369,7 +394,7 @@ void Timestamp::CopyFrom(const Timestamp& from) { // @@protoc_insertion_point(class_specific_copy_from_start:google.protobuf.Timestamp) if (&from == this) return; Clear(); - MergeFrom(from); + UnsafeMergeFrom(from); } bool Timestamp::IsInitialized() const { @@ -383,7 +408,7 @@ void Timestamp::Swap(Timestamp* other) { InternalSwap(other); } else { Timestamp temp; - temp.MergeFrom(*this); + temp.UnsafeMergeFrom(*this); CopyFrom(*other); other->CopyFrom(temp); } @@ -415,11 +440,11 @@ void Timestamp::InternalSwap(Timestamp* other) { void Timestamp::clear_seconds() { seconds_ = GOOGLE_LONGLONG(0); } - ::google::protobuf::int64 Timestamp::seconds() const { +::google::protobuf::int64 Timestamp::seconds() const { // @@protoc_insertion_point(field_get:google.protobuf.Timestamp.seconds) return seconds_; } - void Timestamp::set_seconds(::google::protobuf::int64 value) { +void Timestamp::set_seconds(::google::protobuf::int64 value) { seconds_ = value; // @@protoc_insertion_point(field_set:google.protobuf.Timestamp.seconds) @@ -429,11 +454,11 @@ void Timestamp::clear_seconds() { void Timestamp::clear_nanos() { nanos_ = 0; } - ::google::protobuf::int32 Timestamp::nanos() const { +::google::protobuf::int32 Timestamp::nanos() const { // @@protoc_insertion_point(field_get:google.protobuf.Timestamp.nanos) return nanos_; } - void Timestamp::set_nanos(::google::protobuf::int32 value) { +void Timestamp::set_nanos(::google::protobuf::int32 value) { nanos_ = value; // @@protoc_insertion_point(field_set:google.protobuf.Timestamp.nanos) diff --git a/src/google/protobuf/timestamp.pb.h b/src/google/protobuf/timestamp.pb.h index 2d685120..acc1e7d3 100644 --- a/src/google/protobuf/timestamp.pb.h +++ b/src/google/protobuf/timestamp.pb.h @@ -34,6 +34,7 @@ namespace protobuf { // Internal implementation detail -- do not call these. void LIBPROTOBUF_EXPORT protobuf_AddDesc_google_2fprotobuf_2ftimestamp_2eproto(); +void LIBPROTOBUF_EXPORT protobuf_InitDefaults_google_2fprotobuf_2ftimestamp_2eproto(); void protobuf_AssignDesc_google_2fprotobuf_2ftimestamp_2eproto(); void protobuf_ShutdownFile_google_2fprotobuf_2ftimestamp_2eproto(); @@ -60,6 +61,10 @@ class LIBPROTOBUF_EXPORT Timestamp : public ::google::protobuf::Message /* @@pro static const ::google::protobuf::Descriptor* descriptor(); static const Timestamp& default_instance(); + static inline const Timestamp* internal_default_instance() { + return &default_instance_.get(); + } + void UnsafeArenaSwap(Timestamp* other); void Swap(Timestamp* other); @@ -75,7 +80,7 @@ class LIBPROTOBUF_EXPORT Timestamp : public ::google::protobuf::Message /* @@pro void Clear(); bool IsInitialized() const; - int ByteSize() const; + size_t ByteSizeLong() const; bool MergePartialFromCodedStream( ::google::protobuf::io::CodedInputStream* input); void SerializeWithCachedSizes( @@ -91,6 +96,7 @@ class LIBPROTOBUF_EXPORT Timestamp : public ::google::protobuf::Message /* @@pro void SharedDtor(); void SetCachedSize(int size) const; void InternalSwap(Timestamp* other); + void UnsafeMergeFrom(const Timestamp& from); protected: explicit Timestamp(::google::protobuf::Arena* arena); private: @@ -130,16 +136,16 @@ class LIBPROTOBUF_EXPORT Timestamp : public ::google::protobuf::Message /* @@pro friend class ::google::protobuf::Arena; typedef void InternalArenaConstructable_; typedef void DestructorSkippable_; - bool _is_default_instance_; ::google::protobuf::int64 seconds_; ::google::protobuf::int32 nanos_; mutable int _cached_size_; - friend void LIBPROTOBUF_EXPORT protobuf_AddDesc_google_2fprotobuf_2ftimestamp_2eproto(); + friend void LIBPROTOBUF_EXPORT protobuf_InitDefaults_google_2fprotobuf_2ftimestamp_2eproto_impl(); + friend void LIBPROTOBUF_EXPORT protobuf_AddDesc_google_2fprotobuf_2ftimestamp_2eproto_impl(); friend void protobuf_AssignDesc_google_2fprotobuf_2ftimestamp_2eproto(); friend void protobuf_ShutdownFile_google_2fprotobuf_2ftimestamp_2eproto(); void InitAsDefaultInstance(); - static Timestamp* default_instance_; + static ::google::protobuf::internal::ExplicitlyConstructed default_instance_; }; // =================================================================== diff --git a/src/google/protobuf/timestamp.proto b/src/google/protobuf/timestamp.proto index 7992a858..67e2eba4 100644 --- a/src/google/protobuf/timestamp.proto +++ b/src/google/protobuf/timestamp.proto @@ -38,7 +38,6 @@ option go_package = "github.com/golang/protobuf/ptypes/timestamp"; option java_package = "com.google.protobuf"; option java_outer_classname = "TimestampProto"; option java_multiple_files = true; -option java_generate_equals_and_hash = true; option objc_class_prefix = "GPB"; // A Timestamp represents a point in time independent of any time zone @@ -90,16 +89,14 @@ option objc_class_prefix = "GPB"; // // Example 5: Compute Timestamp from current time in Python. // -// now = time.time() -// seconds = int(now) -// nanos = int((now - seconds) * 10**9) -// timestamp = Timestamp(seconds=seconds, nanos=nanos) +// timestamp = Timestamp() +// timestamp.GetCurrentTime() // // message Timestamp { // Represents seconds of UTC time since Unix epoch - // 1970-01-01T00:00:00Z. Must be from from 0001-01-01T00:00:00Z to + // 1970-01-01T00:00:00Z. Must be from 0001-01-01T00:00:00Z to // 9999-12-31T23:59:59Z inclusive. int64 seconds = 1; diff --git a/src/google/protobuf/type.pb.cc b/src/google/protobuf/type.pb.cc index fc7d5332..0c6de296 100644 --- a/src/google/protobuf/type.pb.cc +++ b/src/google/protobuf/type.pb.cc @@ -63,14 +63,13 @@ void protobuf_AssignDesc_google_2fprotobuf_2ftype_2eproto() { Type_reflection_ = ::google::protobuf::internal::GeneratedMessageReflection::NewGeneratedMessageReflection( Type_descriptor_, - Type::default_instance_, + Type::internal_default_instance(), Type_offsets_, -1, -1, -1, sizeof(Type), - GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(Type, _internal_metadata_), - GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(Type, _is_default_instance_)); + GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(Type, _internal_metadata_)); Field_descriptor_ = file->message_type(1); static const int Field_offsets_[10] = { GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(Field, kind_), @@ -87,14 +86,13 @@ void protobuf_AssignDesc_google_2fprotobuf_2ftype_2eproto() { Field_reflection_ = ::google::protobuf::internal::GeneratedMessageReflection::NewGeneratedMessageReflection( Field_descriptor_, - Field::default_instance_, + Field::internal_default_instance(), Field_offsets_, -1, -1, -1, sizeof(Field), - GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(Field, _internal_metadata_), - GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(Field, _is_default_instance_)); + GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(Field, _internal_metadata_)); Field_Kind_descriptor_ = Field_descriptor_->enum_type(0); Field_Cardinality_descriptor_ = Field_descriptor_->enum_type(1); Enum_descriptor_ = file->message_type(2); @@ -108,14 +106,13 @@ void protobuf_AssignDesc_google_2fprotobuf_2ftype_2eproto() { Enum_reflection_ = ::google::protobuf::internal::GeneratedMessageReflection::NewGeneratedMessageReflection( Enum_descriptor_, - Enum::default_instance_, + Enum::internal_default_instance(), Enum_offsets_, -1, -1, -1, sizeof(Enum), - GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(Enum, _internal_metadata_), - GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(Enum, _is_default_instance_)); + GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(Enum, _internal_metadata_)); EnumValue_descriptor_ = file->message_type(3); static const int EnumValue_offsets_[3] = { GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(EnumValue, name_), @@ -125,14 +122,13 @@ void protobuf_AssignDesc_google_2fprotobuf_2ftype_2eproto() { EnumValue_reflection_ = ::google::protobuf::internal::GeneratedMessageReflection::NewGeneratedMessageReflection( EnumValue_descriptor_, - EnumValue::default_instance_, + EnumValue::internal_default_instance(), EnumValue_offsets_, -1, -1, -1, sizeof(EnumValue), - GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(EnumValue, _internal_metadata_), - GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(EnumValue, _is_default_instance_)); + GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(EnumValue, _internal_metadata_)); Option_descriptor_ = file->message_type(4); static const int Option_offsets_[2] = { GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(Option, name_), @@ -141,21 +137,20 @@ void protobuf_AssignDesc_google_2fprotobuf_2ftype_2eproto() { Option_reflection_ = ::google::protobuf::internal::GeneratedMessageReflection::NewGeneratedMessageReflection( Option_descriptor_, - Option::default_instance_, + Option::internal_default_instance(), Option_offsets_, -1, -1, -1, sizeof(Option), - GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(Option, _internal_metadata_), - GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(Option, _is_default_instance_)); + GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(Option, _internal_metadata_)); Syntax_descriptor_ = file->enum_type(0); } namespace { GOOGLE_PROTOBUF_DECLARE_ONCE(protobuf_AssignDescriptors_once_); -inline void protobuf_AssignDescriptorsOnce() { +void protobuf_AssignDescriptorsOnce() { ::google::protobuf::GoogleOnceInit(&protobuf_AssignDescriptors_once_, &protobuf_AssignDesc_google_2fprotobuf_2ftype_2eproto); } @@ -164,41 +159,58 @@ void protobuf_RegisterTypes(const ::std::string&) GOOGLE_ATTRIBUTE_COLD; void protobuf_RegisterTypes(const ::std::string&) { protobuf_AssignDescriptorsOnce(); ::google::protobuf::MessageFactory::InternalRegisterGeneratedMessage( - Type_descriptor_, &Type::default_instance()); + Type_descriptor_, Type::internal_default_instance()); ::google::protobuf::MessageFactory::InternalRegisterGeneratedMessage( - Field_descriptor_, &Field::default_instance()); + Field_descriptor_, Field::internal_default_instance()); ::google::protobuf::MessageFactory::InternalRegisterGeneratedMessage( - Enum_descriptor_, &Enum::default_instance()); + Enum_descriptor_, Enum::internal_default_instance()); ::google::protobuf::MessageFactory::InternalRegisterGeneratedMessage( - EnumValue_descriptor_, &EnumValue::default_instance()); + EnumValue_descriptor_, EnumValue::internal_default_instance()); ::google::protobuf::MessageFactory::InternalRegisterGeneratedMessage( - Option_descriptor_, &Option::default_instance()); + Option_descriptor_, Option::internal_default_instance()); } } // namespace void protobuf_ShutdownFile_google_2fprotobuf_2ftype_2eproto() { - delete Type::default_instance_; delete Type_reflection_; - delete Field::default_instance_; delete Field_reflection_; - delete Enum::default_instance_; delete Enum_reflection_; - delete EnumValue::default_instance_; delete EnumValue_reflection_; - delete Option::default_instance_; delete Option_reflection_; } -void protobuf_AddDesc_google_2fprotobuf_2ftype_2eproto() GOOGLE_ATTRIBUTE_COLD; -void protobuf_AddDesc_google_2fprotobuf_2ftype_2eproto() { - static bool already_here = false; - if (already_here) return; - already_here = true; +void protobuf_InitDefaults_google_2fprotobuf_2ftype_2eproto_impl() { GOOGLE_PROTOBUF_VERIFY_VERSION; - ::google::protobuf::protobuf_AddDesc_google_2fprotobuf_2fany_2eproto(); - ::google::protobuf::protobuf_AddDesc_google_2fprotobuf_2fsource_5fcontext_2eproto(); + ::google::protobuf::protobuf_InitDefaults_google_2fprotobuf_2fany_2eproto(); + ::google::protobuf::protobuf_InitDefaults_google_2fprotobuf_2fsource_5fcontext_2eproto(); + ::google::protobuf::internal::GetEmptyString(); + Type::default_instance_.DefaultConstruct(); + ::google::protobuf::internal::GetEmptyString(); + Field::default_instance_.DefaultConstruct(); + ::google::protobuf::internal::GetEmptyString(); + Enum::default_instance_.DefaultConstruct(); + ::google::protobuf::internal::GetEmptyString(); + EnumValue::default_instance_.DefaultConstruct(); + ::google::protobuf::internal::GetEmptyString(); + Option::default_instance_.DefaultConstruct(); + Type::default_instance_.get_mutable()->InitAsDefaultInstance(); + Field::default_instance_.get_mutable()->InitAsDefaultInstance(); + Enum::default_instance_.get_mutable()->InitAsDefaultInstance(); + EnumValue::default_instance_.get_mutable()->InitAsDefaultInstance(); + Option::default_instance_.get_mutable()->InitAsDefaultInstance(); +} + +GOOGLE_PROTOBUF_DECLARE_ONCE(protobuf_InitDefaults_google_2fprotobuf_2ftype_2eproto_once_); +void protobuf_InitDefaults_google_2fprotobuf_2ftype_2eproto() { + ::google::protobuf::GoogleOnceInit(&protobuf_InitDefaults_google_2fprotobuf_2ftype_2eproto_once_, + &protobuf_InitDefaults_google_2fprotobuf_2ftype_2eproto_impl); +} +void protobuf_AddDesc_google_2fprotobuf_2ftype_2eproto_impl() { + GOOGLE_PROTOBUF_VERIFY_VERSION; + + protobuf_InitDefaults_google_2fprotobuf_2ftype_2eproto(); ::google::protobuf::DescriptorPool::InternalAddGeneratedFile( "\n\032google/protobuf/type.proto\022\017google.pro" "tobuf\032\031google/protobuf/any.proto\032$google" @@ -237,23 +249,20 @@ void protobuf_AddDesc_google_2fprotobuf_2ftype_2eproto() { "\022\014\n\004name\030\001 \001(\t\022#\n\005value\030\002 \001(\0132\024.google.p" "rotobuf.Any*.\n\006Syntax\022\021\n\rSYNTAX_PROTO2\020\000" "\022\021\n\rSYNTAX_PROTO3\020\001BL\n\023com.google.protob" - "ufB\tTypeProtoP\001\240\001\001\242\002\003GPB\252\002\036Google.Protob" + "ufB\tTypeProtoP\001\370\001\001\242\002\003GPB\252\002\036Google.Protob" "uf.WellKnownTypesb\006proto3", 1545); ::google::protobuf::MessageFactory::InternalRegisterGeneratedFile( "google/protobuf/type.proto", &protobuf_RegisterTypes); - Type::default_instance_ = new Type(); - Field::default_instance_ = new Field(); - Enum::default_instance_ = new Enum(); - EnumValue::default_instance_ = new EnumValue(); - Option::default_instance_ = new Option(); - Type::default_instance_->InitAsDefaultInstance(); - Field::default_instance_->InitAsDefaultInstance(); - Enum::default_instance_->InitAsDefaultInstance(); - EnumValue::default_instance_->InitAsDefaultInstance(); - Option::default_instance_->InitAsDefaultInstance(); + ::google::protobuf::protobuf_AddDesc_google_2fprotobuf_2fany_2eproto(); + ::google::protobuf::protobuf_AddDesc_google_2fprotobuf_2fsource_5fcontext_2eproto(); ::google::protobuf::internal::OnShutdown(&protobuf_ShutdownFile_google_2fprotobuf_2ftype_2eproto); } +GOOGLE_PROTOBUF_DECLARE_ONCE(protobuf_AddDesc_google_2fprotobuf_2ftype_2eproto_once_); +void protobuf_AddDesc_google_2fprotobuf_2ftype_2eproto() { + ::google::protobuf::GoogleOnceInit(&protobuf_AddDesc_google_2fprotobuf_2ftype_2eproto_once_, + &protobuf_AddDesc_google_2fprotobuf_2ftype_2eproto_impl); +} // Force AddDescriptors() to be called at static initialization time. struct StaticDescriptorInitializer_google_2fprotobuf_2ftype_2eproto { StaticDescriptorInitializer_google_2fprotobuf_2ftype_2eproto() { @@ -265,7 +274,7 @@ const ::google::protobuf::EnumDescriptor* Syntax_descriptor() { return Syntax_descriptor_; } bool Syntax_IsValid(int value) { - switch(value) { + switch (value) { case 0: case 1: return true; @@ -275,8 +284,51 @@ bool Syntax_IsValid(int value) { } +namespace { + +static void MergeFromFail(int line) GOOGLE_ATTRIBUTE_COLD GOOGLE_ATTRIBUTE_NORETURN; +static void MergeFromFail(int line) { + ::google::protobuf::internal::MergeFromFail(__FILE__, line); +} + +} // namespace + + // =================================================================== +void Type::_slow_mutable_source_context() { + source_context_ = ::google::protobuf::Arena::Create< ::google::protobuf::SourceContext >( + GetArenaNoVirtual()); +} +::google::protobuf::SourceContext* Type::_slow_release_source_context() { + if (source_context_ == NULL) { + return NULL; + } else { + ::google::protobuf::SourceContext* temp = new ::google::protobuf::SourceContext(*source_context_); + source_context_ = NULL; + return temp; + } +} +::google::protobuf::SourceContext* Type::unsafe_arena_release_source_context() { + // @@protoc_insertion_point(field_unsafe_arena_release:google.protobuf.Type.source_context) + + ::google::protobuf::SourceContext* temp = source_context_; + source_context_ = NULL; + return temp; +} +void Type::unsafe_arena_set_allocated_source_context( + ::google::protobuf::SourceContext* source_context) { + if (GetArenaNoVirtual() == NULL) { + delete source_context_; + } + source_context_ = source_context; + if (source_context) { + + } else { + + } + // @@protoc_insertion_point(field_unsafe_arena_set_allocated:google.protobuf.Type.source_context) +} #if !defined(_MSC_VER) || _MSC_VER >= 1900 const int Type::kNameFieldNumber; const int Type::kFieldsFieldNumber; @@ -288,30 +340,42 @@ const int Type::kSyntaxFieldNumber; Type::Type() : ::google::protobuf::Message(), _internal_metadata_(NULL) { + if (this != internal_default_instance()) protobuf_InitDefaults_google_2fprotobuf_2ftype_2eproto(); SharedCtor(); // @@protoc_insertion_point(constructor:google.protobuf.Type) } +Type::Type(::google::protobuf::Arena* arena) + : ::google::protobuf::Message(), + _internal_metadata_(arena), + fields_(arena), + oneofs_(arena), + options_(arena) { +#ifdef GOOGLE_PROTOBUF_NO_STATIC_INITIALIZER + protobuf_InitDefaults_google_2fprotobuf_2ftype_2eproto(); +#endif // GOOGLE_PROTOBUF_NO_STATIC_INITIALIZER + SharedCtor(); + RegisterArenaDtor(arena); + // @@protoc_insertion_point(arena_constructor:google.protobuf.Type) +} void Type::InitAsDefaultInstance() { - _is_default_instance_ = true; - source_context_ = const_cast< ::google::protobuf::SourceContext*>(&::google::protobuf::SourceContext::default_instance()); + source_context_ = const_cast< ::google::protobuf::SourceContext*>( + ::google::protobuf::SourceContext::internal_default_instance()); } Type::Type(const Type& from) : ::google::protobuf::Message(), _internal_metadata_(NULL) { SharedCtor(); - MergeFrom(from); + UnsafeMergeFrom(from); // @@protoc_insertion_point(copy_constructor:google.protobuf.Type) } void Type::SharedCtor() { - _is_default_instance_ = false; - ::google::protobuf::internal::GetEmptyString(); - _cached_size_ = 0; name_.UnsafeSetDefault(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); source_context_ = NULL; syntax_ = 0; + _cached_size_ = 0; } Type::~Type() { @@ -320,12 +384,21 @@ Type::~Type() { } void Type::SharedDtor() { - name_.DestroyNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); - if (this != default_instance_) { - delete source_context_; + ::google::protobuf::Arena* arena = GetArenaNoVirtual(); + if (arena != NULL) { + return; } + + name_.Destroy(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), arena); + delete source_context_; } +void Type::ArenaDtor(void* object) { + Type* _this = reinterpret_cast< Type* >(object); + (void)_this; +} +void Type::RegisterArenaDtor(::google::protobuf::Arena* arena) { +} void Type::SetCachedSize(int size) const { GOOGLE_SAFE_CONCURRENT_WRITES_BEGIN(); _cached_size_ = size; @@ -337,23 +410,19 @@ const ::google::protobuf::Descriptor* Type::descriptor() { } const Type& Type::default_instance() { - if (default_instance_ == NULL) protobuf_AddDesc_google_2fprotobuf_2ftype_2eproto(); - return *default_instance_; + protobuf_InitDefaults_google_2fprotobuf_2ftype_2eproto(); + return *internal_default_instance(); } -Type* Type::default_instance_ = NULL; +::google::protobuf::internal::ExplicitlyConstructed Type::default_instance_; Type* Type::New(::google::protobuf::Arena* arena) const { - Type* n = new Type; - if (arena != NULL) { - arena->Own(n); - } - return n; + return ::google::protobuf::Arena::CreateMessage(arena); } void Type::Clear() { // @@protoc_insertion_point(message_clear_start:google.protobuf.Type) - name_.ClearToEmptyNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); + name_.ClearToEmpty(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), GetArenaNoVirtual()); if (GetArenaNoVirtual() == NULL && source_context_ != NULL) delete source_context_; source_context_ = NULL; syntax_ = 0; @@ -597,9 +666,9 @@ void Type::SerializeWithCachedSizes( return target; } -int Type::ByteSize() const { +size_t Type::ByteSizeLong() const { // @@protoc_insertion_point(message_byte_size_start:google.protobuf.Type) - int total_size = 0; + size_t total_size = 0; // optional string name = 1; if (this->name().size() > 0) { @@ -622,40 +691,46 @@ int Type::ByteSize() const { } // repeated .google.protobuf.Field fields = 2; - total_size += 1 * this->fields_size(); - for (int i = 0; i < this->fields_size(); i++) { - total_size += - ::google::protobuf::internal::WireFormatLite::MessageSizeNoVirtual( - this->fields(i)); + { + unsigned int count = this->fields_size(); + total_size += 1UL * count; + for (unsigned int i = 0; i < count; i++) { + total_size += + ::google::protobuf::internal::WireFormatLite::MessageSizeNoVirtual( + this->fields(i)); + } } // repeated string oneofs = 3; - total_size += 1 * this->oneofs_size(); + total_size += 1 * + ::google::protobuf::internal::FromIntSize(this->oneofs_size()); for (int i = 0; i < this->oneofs_size(); i++) { total_size += ::google::protobuf::internal::WireFormatLite::StringSize( this->oneofs(i)); } // repeated .google.protobuf.Option options = 4; - total_size += 1 * this->options_size(); - for (int i = 0; i < this->options_size(); i++) { - total_size += - ::google::protobuf::internal::WireFormatLite::MessageSizeNoVirtual( - this->options(i)); + { + unsigned int count = this->options_size(); + total_size += 1UL * count; + for (unsigned int i = 0; i < count; i++) { + total_size += + ::google::protobuf::internal::WireFormatLite::MessageSizeNoVirtual( + this->options(i)); + } } + int cached_size = ::google::protobuf::internal::ToCachedSize(total_size); GOOGLE_SAFE_CONCURRENT_WRITES_BEGIN(); - _cached_size_ = total_size; + _cached_size_ = cached_size; GOOGLE_SAFE_CONCURRENT_WRITES_END(); return total_size; } void Type::MergeFrom(const ::google::protobuf::Message& from) { // @@protoc_insertion_point(generalized_merge_from_start:google.protobuf.Type) - if (GOOGLE_PREDICT_FALSE(&from == this)) { - ::google::protobuf::internal::MergeFromFail(__FILE__, __LINE__); - } - const Type* source = + if (GOOGLE_PREDICT_FALSE(&from == this)) MergeFromFail(__LINE__); + const Type* source = ::google::protobuf::internal::DynamicCastToGenerated( &from); if (source == NULL) { @@ -663,21 +738,26 @@ void Type::MergeFrom(const ::google::protobuf::Message& from) { ::google::protobuf::internal::ReflectionOps::Merge(from, this); } else { // @@protoc_insertion_point(generalized_merge_from_cast_success:google.protobuf.Type) - MergeFrom(*source); + UnsafeMergeFrom(*source); } } void Type::MergeFrom(const Type& from) { // @@protoc_insertion_point(class_specific_merge_from_start:google.protobuf.Type) - if (GOOGLE_PREDICT_FALSE(&from == this)) { - ::google::protobuf::internal::MergeFromFail(__FILE__, __LINE__); + if (GOOGLE_PREDICT_TRUE(&from != this)) { + UnsafeMergeFrom(from); + } else { + MergeFromFail(__LINE__); } +} + +void Type::UnsafeMergeFrom(const Type& from) { + GOOGLE_DCHECK(&from != this); fields_.MergeFrom(from.fields_); - oneofs_.MergeFrom(from.oneofs_); + oneofs_.UnsafeMergeFrom(from.oneofs_); options_.MergeFrom(from.options_); if (from.name().size() > 0) { - - name_.AssignWithDefault(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), from.name_); + set_name(from.name()); } if (from.has_source_context()) { mutable_source_context()->::google::protobuf::SourceContext::MergeFrom(from.source_context()); @@ -698,7 +778,7 @@ void Type::CopyFrom(const Type& from) { // @@protoc_insertion_point(class_specific_copy_from_start:google.protobuf.Type) if (&from == this) return; Clear(); - MergeFrom(from); + UnsafeMergeFrom(from); } bool Type::IsInitialized() const { @@ -708,6 +788,18 @@ bool Type::IsInitialized() const { void Type::Swap(Type* other) { if (other == this) return; + if (GetArenaNoVirtual() == other->GetArenaNoVirtual()) { + InternalSwap(other); + } else { + Type temp; + temp.UnsafeMergeFrom(*this); + CopyFrom(*other); + other->CopyFrom(temp); + } +} +void Type::UnsafeArenaSwap(Type* other) { + if (other == this) return; + GOOGLE_DCHECK(GetArenaNoVirtual() == other->GetArenaNoVirtual()); InternalSwap(other); } void Type::InternalSwap(Type* other) { @@ -734,47 +826,69 @@ void Type::InternalSwap(Type* other) { // optional string name = 1; void Type::clear_name() { - name_.ClearToEmptyNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); + name_.ClearToEmpty(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), GetArenaNoVirtual()); } - const ::std::string& Type::name() const { +const ::std::string& Type::name() const { // @@protoc_insertion_point(field_get:google.protobuf.Type.name) - return name_.GetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); + return name_.Get(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); } - void Type::set_name(const ::std::string& value) { +void Type::set_name(const ::std::string& value) { - name_.SetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), value); + name_.Set(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), value, GetArenaNoVirtual()); // @@protoc_insertion_point(field_set:google.protobuf.Type.name) } - void Type::set_name(const char* value) { +void Type::set_name(const char* value) { - name_.SetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), ::std::string(value)); + name_.Set(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), ::std::string(value), + GetArenaNoVirtual()); // @@protoc_insertion_point(field_set_char:google.protobuf.Type.name) } - void Type::set_name(const char* value, size_t size) { +void Type::set_name(const char* value, + size_t size) { - name_.SetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), - ::std::string(reinterpret_cast(value), size)); + name_.Set(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), ::std::string( + reinterpret_cast(value), size), GetArenaNoVirtual()); // @@protoc_insertion_point(field_set_pointer:google.protobuf.Type.name) } - ::std::string* Type::mutable_name() { +::std::string* Type::mutable_name() { // @@protoc_insertion_point(field_mutable:google.protobuf.Type.name) - return name_.MutableNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); + return name_.Mutable(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), GetArenaNoVirtual()); } - ::std::string* Type::release_name() { +::std::string* Type::release_name() { // @@protoc_insertion_point(field_release:google.protobuf.Type.name) - return name_.ReleaseNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); + return name_.Release(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), GetArenaNoVirtual()); } - void Type::set_allocated_name(::std::string* name) { +::std::string* Type::unsafe_arena_release_name() { + // @@protoc_insertion_point(field_unsafe_arena_release:google.protobuf.Type.name) + GOOGLE_DCHECK(GetArenaNoVirtual() != NULL); + + return name_.UnsafeArenaRelease(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), + GetArenaNoVirtual()); +} +void Type::set_allocated_name(::std::string* name) { if (name != NULL) { } else { } - name_.SetAllocatedNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), name); + name_.SetAllocated(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), name, + GetArenaNoVirtual()); // @@protoc_insertion_point(field_set_allocated:google.protobuf.Type.name) } +void Type::unsafe_arena_set_allocated_name( + ::std::string* name) { + GOOGLE_DCHECK(GetArenaNoVirtual() != NULL); + if (name != NULL) { + + } else { + + } + name_.UnsafeArenaSetAllocated(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), + name, GetArenaNoVirtual()); + // @@protoc_insertion_point(field_unsafe_arena_set_allocated:google.protobuf.Type.name) +} // repeated .google.protobuf.Field fields = 2; int Type::fields_size() const { @@ -813,49 +927,49 @@ int Type::oneofs_size() const { void Type::clear_oneofs() { oneofs_.Clear(); } - const ::std::string& Type::oneofs(int index) const { +const ::std::string& Type::oneofs(int index) const { // @@protoc_insertion_point(field_get:google.protobuf.Type.oneofs) return oneofs_.Get(index); } - ::std::string* Type::mutable_oneofs(int index) { +::std::string* Type::mutable_oneofs(int index) { // @@protoc_insertion_point(field_mutable:google.protobuf.Type.oneofs) return oneofs_.Mutable(index); } - void Type::set_oneofs(int index, const ::std::string& value) { +void Type::set_oneofs(int index, const ::std::string& value) { // @@protoc_insertion_point(field_set:google.protobuf.Type.oneofs) oneofs_.Mutable(index)->assign(value); } - void Type::set_oneofs(int index, const char* value) { +void Type::set_oneofs(int index, const char* value) { oneofs_.Mutable(index)->assign(value); // @@protoc_insertion_point(field_set_char:google.protobuf.Type.oneofs) } - void Type::set_oneofs(int index, const char* value, size_t size) { +void Type::set_oneofs(int index, const char* value, size_t size) { oneofs_.Mutable(index)->assign( reinterpret_cast(value), size); // @@protoc_insertion_point(field_set_pointer:google.protobuf.Type.oneofs) } - ::std::string* Type::add_oneofs() { +::std::string* Type::add_oneofs() { // @@protoc_insertion_point(field_add_mutable:google.protobuf.Type.oneofs) return oneofs_.Add(); } - void Type::add_oneofs(const ::std::string& value) { +void Type::add_oneofs(const ::std::string& value) { oneofs_.Add()->assign(value); // @@protoc_insertion_point(field_add:google.protobuf.Type.oneofs) } - void Type::add_oneofs(const char* value) { +void Type::add_oneofs(const char* value) { oneofs_.Add()->assign(value); // @@protoc_insertion_point(field_add_char:google.protobuf.Type.oneofs) } - void Type::add_oneofs(const char* value, size_t size) { +void Type::add_oneofs(const char* value, size_t size) { oneofs_.Add()->assign(reinterpret_cast(value), size); // @@protoc_insertion_point(field_add_pointer:google.protobuf.Type.oneofs) } - const ::google::protobuf::RepeatedPtrField< ::std::string>& +const ::google::protobuf::RepeatedPtrField< ::std::string>& Type::oneofs() const { // @@protoc_insertion_point(field_list:google.protobuf.Type.oneofs) return oneofs_; } - ::google::protobuf::RepeatedPtrField< ::std::string>* +::google::protobuf::RepeatedPtrField< ::std::string>* Type::mutable_oneofs() { // @@protoc_insertion_point(field_mutable_list:google.protobuf.Type.oneofs) return &oneofs_; @@ -893,7 +1007,7 @@ Type::options() const { // optional .google.protobuf.SourceContext source_context = 5; bool Type::has_source_context() const { - return !_is_default_instance_ && source_context_ != NULL; + return this != internal_default_instance() && source_context_ != NULL; } void Type::clear_source_context() { if (GetArenaNoVirtual() == NULL && source_context_ != NULL) delete source_context_; @@ -901,12 +1015,13 @@ void Type::clear_source_context() { } const ::google::protobuf::SourceContext& Type::source_context() const { // @@protoc_insertion_point(field_get:google.protobuf.Type.source_context) - return source_context_ != NULL ? *source_context_ : *default_instance_->source_context_; + return source_context_ != NULL ? *source_context_ + : *::google::protobuf::SourceContext::internal_default_instance(); } ::google::protobuf::SourceContext* Type::mutable_source_context() { if (source_context_ == NULL) { - source_context_ = new ::google::protobuf::SourceContext; + _slow_mutable_source_context(); } // @@protoc_insertion_point(field_mutable:google.protobuf.Type.source_context) return source_context_; @@ -914,12 +1029,24 @@ const ::google::protobuf::SourceContext& Type::source_context() const { ::google::protobuf::SourceContext* Type::release_source_context() { // @@protoc_insertion_point(field_release:google.protobuf.Type.source_context) - ::google::protobuf::SourceContext* temp = source_context_; - source_context_ = NULL; - return temp; + if (GetArenaNoVirtual() != NULL) { + return _slow_release_source_context(); + } else { + ::google::protobuf::SourceContext* temp = source_context_; + source_context_ = NULL; + return temp; + } } -void Type::set_allocated_source_context(::google::protobuf::SourceContext* source_context) { - delete source_context_; + void Type::set_allocated_source_context(::google::protobuf::SourceContext* source_context) { + ::google::protobuf::Arena* message_arena = GetArenaNoVirtual(); + if (message_arena == NULL) { + delete source_context_; + } + if (source_context != NULL) { + if (message_arena != NULL) { + message_arena->Own(source_context); + } + } source_context_ = source_context; if (source_context) { @@ -933,11 +1060,11 @@ void Type::set_allocated_source_context(::google::protobuf::SourceContext* sourc void Type::clear_syntax() { syntax_ = 0; } - ::google::protobuf::Syntax Type::syntax() const { +::google::protobuf::Syntax Type::syntax() const { // @@protoc_insertion_point(field_get:google.protobuf.Type.syntax) return static_cast< ::google::protobuf::Syntax >(syntax_); } - void Type::set_syntax(::google::protobuf::Syntax value) { +void Type::set_syntax(::google::protobuf::Syntax value) { syntax_ = value; // @@protoc_insertion_point(field_set:google.protobuf.Type.syntax) @@ -952,7 +1079,7 @@ const ::google::protobuf::EnumDescriptor* Field_Kind_descriptor() { return Field_Kind_descriptor_; } bool Field_Kind_IsValid(int value) { - switch(value) { + switch (value) { case 0: case 1: case 2: @@ -1007,7 +1134,7 @@ const ::google::protobuf::EnumDescriptor* Field_Cardinality_descriptor() { return Field_Cardinality_descriptor_; } bool Field_Cardinality_IsValid(int value) { - switch(value) { + switch (value) { case 0: case 1: case 2: @@ -1042,35 +1169,41 @@ const int Field::kDefaultValueFieldNumber; Field::Field() : ::google::protobuf::Message(), _internal_metadata_(NULL) { + if (this != internal_default_instance()) protobuf_InitDefaults_google_2fprotobuf_2ftype_2eproto(); SharedCtor(); // @@protoc_insertion_point(constructor:google.protobuf.Field) } +Field::Field(::google::protobuf::Arena* arena) + : ::google::protobuf::Message(), + _internal_metadata_(arena), + options_(arena) { +#ifdef GOOGLE_PROTOBUF_NO_STATIC_INITIALIZER + protobuf_InitDefaults_google_2fprotobuf_2ftype_2eproto(); +#endif // GOOGLE_PROTOBUF_NO_STATIC_INITIALIZER + SharedCtor(); + RegisterArenaDtor(arena); + // @@protoc_insertion_point(arena_constructor:google.protobuf.Field) +} void Field::InitAsDefaultInstance() { - _is_default_instance_ = true; } Field::Field(const Field& from) : ::google::protobuf::Message(), _internal_metadata_(NULL) { SharedCtor(); - MergeFrom(from); + UnsafeMergeFrom(from); // @@protoc_insertion_point(copy_constructor:google.protobuf.Field) } void Field::SharedCtor() { - _is_default_instance_ = false; - ::google::protobuf::internal::GetEmptyString(); - _cached_size_ = 0; - kind_ = 0; - cardinality_ = 0; - number_ = 0; name_.UnsafeSetDefault(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); type_url_.UnsafeSetDefault(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); - oneof_index_ = 0; - packed_ = false; json_name_.UnsafeSetDefault(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); default_value_.UnsafeSetDefault(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); + ::memset(&kind_, 0, reinterpret_cast(&packed_) - + reinterpret_cast(&kind_) + sizeof(packed_)); + _cached_size_ = 0; } Field::~Field() { @@ -1079,14 +1212,23 @@ Field::~Field() { } void Field::SharedDtor() { - name_.DestroyNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); - type_url_.DestroyNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); - json_name_.DestroyNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); - default_value_.DestroyNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); - if (this != default_instance_) { + ::google::protobuf::Arena* arena = GetArenaNoVirtual(); + if (arena != NULL) { + return; } + + name_.Destroy(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), arena); + type_url_.Destroy(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), arena); + json_name_.Destroy(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), arena); + default_value_.Destroy(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), arena); } +void Field::ArenaDtor(void* object) { + Field* _this = reinterpret_cast< Field* >(object); + (void)_this; +} +void Field::RegisterArenaDtor(::google::protobuf::Arena* arena) { +} void Field::SetCachedSize(int size) const { GOOGLE_SAFE_CONCURRENT_WRITES_BEGIN(); _cached_size_ = size; @@ -1098,18 +1240,14 @@ const ::google::protobuf::Descriptor* Field::descriptor() { } const Field& Field::default_instance() { - if (default_instance_ == NULL) protobuf_AddDesc_google_2fprotobuf_2ftype_2eproto(); - return *default_instance_; + protobuf_InitDefaults_google_2fprotobuf_2ftype_2eproto(); + return *internal_default_instance(); } -Field* Field::default_instance_ = NULL; +::google::protobuf::internal::ExplicitlyConstructed Field::default_instance_; Field* Field::New(::google::protobuf::Arena* arena) const { - Field* n = new Field; - if (arena != NULL) { - arena->Own(n); - } - return n; + return ::google::protobuf::Arena::CreateMessage(arena); } void Field::Clear() { @@ -1130,13 +1268,11 @@ void Field::Clear() { ZR_HELPER_(last) - ZR_HELPER_(first) + sizeof(last));\ } while (0) - ZR_(kind_, cardinality_); - ZR_(number_, oneof_index_); - name_.ClearToEmptyNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); - type_url_.ClearToEmptyNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); - packed_ = false; - json_name_.ClearToEmptyNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); - default_value_.ClearToEmptyNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); + ZR_(kind_, packed_); + name_.ClearToEmpty(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), GetArenaNoVirtual()); + type_url_.ClearToEmpty(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), GetArenaNoVirtual()); + json_name_.ClearToEmpty(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), GetArenaNoVirtual()); + default_value_.ClearToEmpty(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), GetArenaNoVirtual()); #undef ZR_HELPER_ #undef ZR_ @@ -1189,10 +1325,10 @@ bool Field::MergePartialFromCodedStream( case 3: { if (tag == 24) { parse_number: + DO_((::google::protobuf::internal::WireFormatLite::ReadPrimitive< ::google::protobuf::int32, ::google::protobuf::internal::WireFormatLite::TYPE_INT32>( input, &number_))); - } else { goto handle_unusual; } @@ -1238,10 +1374,10 @@ bool Field::MergePartialFromCodedStream( case 7: { if (tag == 56) { parse_oneof_index: + DO_((::google::protobuf::internal::WireFormatLite::ReadPrimitive< ::google::protobuf::int32, ::google::protobuf::internal::WireFormatLite::TYPE_INT32>( input, &oneof_index_))); - } else { goto handle_unusual; } @@ -1253,10 +1389,10 @@ bool Field::MergePartialFromCodedStream( case 8: { if (tag == 64) { parse_packed: + DO_((::google::protobuf::internal::WireFormatLite::ReadPrimitive< bool, ::google::protobuf::internal::WireFormatLite::TYPE_BOOL>( input, &packed_))); - } else { goto handle_unusual; } @@ -1501,9 +1637,9 @@ void Field::SerializeWithCachedSizes( return target; } -int Field::ByteSize() const { +size_t Field::ByteSizeLong() const { // @@protoc_insertion_point(message_byte_size_start:google.protobuf.Field) - int total_size = 0; + size_t total_size = 0; // optional .google.protobuf.Field.Kind kind = 1; if (this->kind() != 0) { @@ -1565,25 +1701,27 @@ int Field::ByteSize() const { } // repeated .google.protobuf.Option options = 9; - total_size += 1 * this->options_size(); - for (int i = 0; i < this->options_size(); i++) { - total_size += - ::google::protobuf::internal::WireFormatLite::MessageSizeNoVirtual( - this->options(i)); + { + unsigned int count = this->options_size(); + total_size += 1UL * count; + for (unsigned int i = 0; i < count; i++) { + total_size += + ::google::protobuf::internal::WireFormatLite::MessageSizeNoVirtual( + this->options(i)); + } } + int cached_size = ::google::protobuf::internal::ToCachedSize(total_size); GOOGLE_SAFE_CONCURRENT_WRITES_BEGIN(); - _cached_size_ = total_size; + _cached_size_ = cached_size; GOOGLE_SAFE_CONCURRENT_WRITES_END(); return total_size; } void Field::MergeFrom(const ::google::protobuf::Message& from) { // @@protoc_insertion_point(generalized_merge_from_start:google.protobuf.Field) - if (GOOGLE_PREDICT_FALSE(&from == this)) { - ::google::protobuf::internal::MergeFromFail(__FILE__, __LINE__); - } - const Field* source = + if (GOOGLE_PREDICT_FALSE(&from == this)) MergeFromFail(__LINE__); + const Field* source = ::google::protobuf::internal::DynamicCastToGenerated( &from); if (source == NULL) { @@ -1591,15 +1729,21 @@ void Field::MergeFrom(const ::google::protobuf::Message& from) { ::google::protobuf::internal::ReflectionOps::Merge(from, this); } else { // @@protoc_insertion_point(generalized_merge_from_cast_success:google.protobuf.Field) - MergeFrom(*source); + UnsafeMergeFrom(*source); } } void Field::MergeFrom(const Field& from) { // @@protoc_insertion_point(class_specific_merge_from_start:google.protobuf.Field) - if (GOOGLE_PREDICT_FALSE(&from == this)) { - ::google::protobuf::internal::MergeFromFail(__FILE__, __LINE__); + if (GOOGLE_PREDICT_TRUE(&from != this)) { + UnsafeMergeFrom(from); + } else { + MergeFromFail(__LINE__); } +} + +void Field::UnsafeMergeFrom(const Field& from) { + GOOGLE_DCHECK(&from != this); options_.MergeFrom(from.options_); if (from.kind() != 0) { set_kind(from.kind()); @@ -1611,12 +1755,10 @@ void Field::MergeFrom(const Field& from) { set_number(from.number()); } if (from.name().size() > 0) { - - name_.AssignWithDefault(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), from.name_); + set_name(from.name()); } if (from.type_url().size() > 0) { - - type_url_.AssignWithDefault(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), from.type_url_); + set_type_url(from.type_url()); } if (from.oneof_index() != 0) { set_oneof_index(from.oneof_index()); @@ -1625,12 +1767,10 @@ void Field::MergeFrom(const Field& from) { set_packed(from.packed()); } if (from.json_name().size() > 0) { - - json_name_.AssignWithDefault(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), from.json_name_); + set_json_name(from.json_name()); } if (from.default_value().size() > 0) { - - default_value_.AssignWithDefault(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), from.default_value_); + set_default_value(from.default_value()); } } @@ -1645,7 +1785,7 @@ void Field::CopyFrom(const Field& from) { // @@protoc_insertion_point(class_specific_copy_from_start:google.protobuf.Field) if (&from == this) return; Clear(); - MergeFrom(from); + UnsafeMergeFrom(from); } bool Field::IsInitialized() const { @@ -1655,6 +1795,18 @@ bool Field::IsInitialized() const { void Field::Swap(Field* other) { if (other == this) return; + if (GetArenaNoVirtual() == other->GetArenaNoVirtual()) { + InternalSwap(other); + } else { + Field temp; + temp.UnsafeMergeFrom(*this); + CopyFrom(*other); + other->CopyFrom(temp); + } +} +void Field::UnsafeArenaSwap(Field* other) { + if (other == this) return; + GOOGLE_DCHECK(GetArenaNoVirtual() == other->GetArenaNoVirtual()); InternalSwap(other); } void Field::InternalSwap(Field* other) { @@ -1687,11 +1839,11 @@ void Field::InternalSwap(Field* other) { void Field::clear_kind() { kind_ = 0; } - ::google::protobuf::Field_Kind Field::kind() const { +::google::protobuf::Field_Kind Field::kind() const { // @@protoc_insertion_point(field_get:google.protobuf.Field.kind) return static_cast< ::google::protobuf::Field_Kind >(kind_); } - void Field::set_kind(::google::protobuf::Field_Kind value) { +void Field::set_kind(::google::protobuf::Field_Kind value) { kind_ = value; // @@protoc_insertion_point(field_set:google.protobuf.Field.kind) @@ -1701,11 +1853,11 @@ void Field::clear_kind() { void Field::clear_cardinality() { cardinality_ = 0; } - ::google::protobuf::Field_Cardinality Field::cardinality() const { +::google::protobuf::Field_Cardinality Field::cardinality() const { // @@protoc_insertion_point(field_get:google.protobuf.Field.cardinality) return static_cast< ::google::protobuf::Field_Cardinality >(cardinality_); } - void Field::set_cardinality(::google::protobuf::Field_Cardinality value) { +void Field::set_cardinality(::google::protobuf::Field_Cardinality value) { cardinality_ = value; // @@protoc_insertion_point(field_set:google.protobuf.Field.cardinality) @@ -1715,11 +1867,11 @@ void Field::clear_cardinality() { void Field::clear_number() { number_ = 0; } - ::google::protobuf::int32 Field::number() const { +::google::protobuf::int32 Field::number() const { // @@protoc_insertion_point(field_get:google.protobuf.Field.number) return number_; } - void Field::set_number(::google::protobuf::int32 value) { +void Field::set_number(::google::protobuf::int32 value) { number_ = value; // @@protoc_insertion_point(field_set:google.protobuf.Field.number) @@ -1727,101 +1879,145 @@ void Field::clear_number() { // optional string name = 4; void Field::clear_name() { - name_.ClearToEmptyNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); + name_.ClearToEmpty(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), GetArenaNoVirtual()); } - const ::std::string& Field::name() const { +const ::std::string& Field::name() const { // @@protoc_insertion_point(field_get:google.protobuf.Field.name) - return name_.GetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); + return name_.Get(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); } - void Field::set_name(const ::std::string& value) { +void Field::set_name(const ::std::string& value) { - name_.SetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), value); + name_.Set(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), value, GetArenaNoVirtual()); // @@protoc_insertion_point(field_set:google.protobuf.Field.name) } - void Field::set_name(const char* value) { +void Field::set_name(const char* value) { - name_.SetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), ::std::string(value)); + name_.Set(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), ::std::string(value), + GetArenaNoVirtual()); // @@protoc_insertion_point(field_set_char:google.protobuf.Field.name) } - void Field::set_name(const char* value, size_t size) { +void Field::set_name(const char* value, + size_t size) { - name_.SetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), - ::std::string(reinterpret_cast(value), size)); + name_.Set(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), ::std::string( + reinterpret_cast(value), size), GetArenaNoVirtual()); // @@protoc_insertion_point(field_set_pointer:google.protobuf.Field.name) } - ::std::string* Field::mutable_name() { +::std::string* Field::mutable_name() { // @@protoc_insertion_point(field_mutable:google.protobuf.Field.name) - return name_.MutableNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); + return name_.Mutable(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), GetArenaNoVirtual()); } - ::std::string* Field::release_name() { +::std::string* Field::release_name() { // @@protoc_insertion_point(field_release:google.protobuf.Field.name) - return name_.ReleaseNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); + return name_.Release(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), GetArenaNoVirtual()); } - void Field::set_allocated_name(::std::string* name) { +::std::string* Field::unsafe_arena_release_name() { + // @@protoc_insertion_point(field_unsafe_arena_release:google.protobuf.Field.name) + GOOGLE_DCHECK(GetArenaNoVirtual() != NULL); + + return name_.UnsafeArenaRelease(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), + GetArenaNoVirtual()); +} +void Field::set_allocated_name(::std::string* name) { if (name != NULL) { } else { } - name_.SetAllocatedNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), name); + name_.SetAllocated(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), name, + GetArenaNoVirtual()); // @@protoc_insertion_point(field_set_allocated:google.protobuf.Field.name) } +void Field::unsafe_arena_set_allocated_name( + ::std::string* name) { + GOOGLE_DCHECK(GetArenaNoVirtual() != NULL); + if (name != NULL) { + + } else { + + } + name_.UnsafeArenaSetAllocated(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), + name, GetArenaNoVirtual()); + // @@protoc_insertion_point(field_unsafe_arena_set_allocated:google.protobuf.Field.name) +} // optional string type_url = 6; void Field::clear_type_url() { - type_url_.ClearToEmptyNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); + type_url_.ClearToEmpty(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), GetArenaNoVirtual()); } - const ::std::string& Field::type_url() const { +const ::std::string& Field::type_url() const { // @@protoc_insertion_point(field_get:google.protobuf.Field.type_url) - return type_url_.GetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); + return type_url_.Get(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); } - void Field::set_type_url(const ::std::string& value) { +void Field::set_type_url(const ::std::string& value) { - type_url_.SetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), value); + type_url_.Set(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), value, GetArenaNoVirtual()); // @@protoc_insertion_point(field_set:google.protobuf.Field.type_url) } - void Field::set_type_url(const char* value) { +void Field::set_type_url(const char* value) { - type_url_.SetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), ::std::string(value)); + type_url_.Set(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), ::std::string(value), + GetArenaNoVirtual()); // @@protoc_insertion_point(field_set_char:google.protobuf.Field.type_url) } - void Field::set_type_url(const char* value, size_t size) { +void Field::set_type_url(const char* value, + size_t size) { - type_url_.SetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), - ::std::string(reinterpret_cast(value), size)); + type_url_.Set(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), ::std::string( + reinterpret_cast(value), size), GetArenaNoVirtual()); // @@protoc_insertion_point(field_set_pointer:google.protobuf.Field.type_url) } - ::std::string* Field::mutable_type_url() { +::std::string* Field::mutable_type_url() { // @@protoc_insertion_point(field_mutable:google.protobuf.Field.type_url) - return type_url_.MutableNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); + return type_url_.Mutable(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), GetArenaNoVirtual()); } - ::std::string* Field::release_type_url() { +::std::string* Field::release_type_url() { // @@protoc_insertion_point(field_release:google.protobuf.Field.type_url) - return type_url_.ReleaseNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); + return type_url_.Release(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), GetArenaNoVirtual()); } - void Field::set_allocated_type_url(::std::string* type_url) { +::std::string* Field::unsafe_arena_release_type_url() { + // @@protoc_insertion_point(field_unsafe_arena_release:google.protobuf.Field.type_url) + GOOGLE_DCHECK(GetArenaNoVirtual() != NULL); + + return type_url_.UnsafeArenaRelease(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), + GetArenaNoVirtual()); +} +void Field::set_allocated_type_url(::std::string* type_url) { if (type_url != NULL) { } else { } - type_url_.SetAllocatedNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), type_url); + type_url_.SetAllocated(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), type_url, + GetArenaNoVirtual()); // @@protoc_insertion_point(field_set_allocated:google.protobuf.Field.type_url) } +void Field::unsafe_arena_set_allocated_type_url( + ::std::string* type_url) { + GOOGLE_DCHECK(GetArenaNoVirtual() != NULL); + if (type_url != NULL) { + + } else { + + } + type_url_.UnsafeArenaSetAllocated(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), + type_url, GetArenaNoVirtual()); + // @@protoc_insertion_point(field_unsafe_arena_set_allocated:google.protobuf.Field.type_url) +} // optional int32 oneof_index = 7; void Field::clear_oneof_index() { oneof_index_ = 0; } - ::google::protobuf::int32 Field::oneof_index() const { +::google::protobuf::int32 Field::oneof_index() const { // @@protoc_insertion_point(field_get:google.protobuf.Field.oneof_index) return oneof_index_; } - void Field::set_oneof_index(::google::protobuf::int32 value) { +void Field::set_oneof_index(::google::protobuf::int32 value) { oneof_index_ = value; // @@protoc_insertion_point(field_set:google.protobuf.Field.oneof_index) @@ -1831,11 +2027,11 @@ void Field::clear_oneof_index() { void Field::clear_packed() { packed_ = false; } - bool Field::packed() const { +bool Field::packed() const { // @@protoc_insertion_point(field_get:google.protobuf.Field.packed) return packed_; } - void Field::set_packed(bool value) { +void Field::set_packed(bool value) { packed_ = value; // @@protoc_insertion_point(field_set:google.protobuf.Field.packed) @@ -1873,96 +2069,173 @@ Field::options() const { // optional string json_name = 10; void Field::clear_json_name() { - json_name_.ClearToEmptyNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); + json_name_.ClearToEmpty(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), GetArenaNoVirtual()); } - const ::std::string& Field::json_name() const { +const ::std::string& Field::json_name() const { // @@protoc_insertion_point(field_get:google.protobuf.Field.json_name) - return json_name_.GetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); + return json_name_.Get(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); } - void Field::set_json_name(const ::std::string& value) { +void Field::set_json_name(const ::std::string& value) { - json_name_.SetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), value); + json_name_.Set(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), value, GetArenaNoVirtual()); // @@protoc_insertion_point(field_set:google.protobuf.Field.json_name) } - void Field::set_json_name(const char* value) { +void Field::set_json_name(const char* value) { - json_name_.SetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), ::std::string(value)); + json_name_.Set(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), ::std::string(value), + GetArenaNoVirtual()); // @@protoc_insertion_point(field_set_char:google.protobuf.Field.json_name) } - void Field::set_json_name(const char* value, size_t size) { +void Field::set_json_name(const char* value, + size_t size) { - json_name_.SetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), - ::std::string(reinterpret_cast(value), size)); + json_name_.Set(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), ::std::string( + reinterpret_cast(value), size), GetArenaNoVirtual()); // @@protoc_insertion_point(field_set_pointer:google.protobuf.Field.json_name) } - ::std::string* Field::mutable_json_name() { +::std::string* Field::mutable_json_name() { // @@protoc_insertion_point(field_mutable:google.protobuf.Field.json_name) - return json_name_.MutableNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); + return json_name_.Mutable(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), GetArenaNoVirtual()); } - ::std::string* Field::release_json_name() { +::std::string* Field::release_json_name() { // @@protoc_insertion_point(field_release:google.protobuf.Field.json_name) - return json_name_.ReleaseNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); + return json_name_.Release(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), GetArenaNoVirtual()); +} +::std::string* Field::unsafe_arena_release_json_name() { + // @@protoc_insertion_point(field_unsafe_arena_release:google.protobuf.Field.json_name) + GOOGLE_DCHECK(GetArenaNoVirtual() != NULL); + + return json_name_.UnsafeArenaRelease(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), + GetArenaNoVirtual()); } - void Field::set_allocated_json_name(::std::string* json_name) { +void Field::set_allocated_json_name(::std::string* json_name) { if (json_name != NULL) { } else { } - json_name_.SetAllocatedNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), json_name); + json_name_.SetAllocated(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), json_name, + GetArenaNoVirtual()); // @@protoc_insertion_point(field_set_allocated:google.protobuf.Field.json_name) } +void Field::unsafe_arena_set_allocated_json_name( + ::std::string* json_name) { + GOOGLE_DCHECK(GetArenaNoVirtual() != NULL); + if (json_name != NULL) { + + } else { + + } + json_name_.UnsafeArenaSetAllocated(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), + json_name, GetArenaNoVirtual()); + // @@protoc_insertion_point(field_unsafe_arena_set_allocated:google.protobuf.Field.json_name) +} // optional string default_value = 11; void Field::clear_default_value() { - default_value_.ClearToEmptyNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); + default_value_.ClearToEmpty(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), GetArenaNoVirtual()); } - const ::std::string& Field::default_value() const { +const ::std::string& Field::default_value() const { // @@protoc_insertion_point(field_get:google.protobuf.Field.default_value) - return default_value_.GetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); + return default_value_.Get(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); } - void Field::set_default_value(const ::std::string& value) { +void Field::set_default_value(const ::std::string& value) { - default_value_.SetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), value); + default_value_.Set(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), value, GetArenaNoVirtual()); // @@protoc_insertion_point(field_set:google.protobuf.Field.default_value) } - void Field::set_default_value(const char* value) { +void Field::set_default_value(const char* value) { - default_value_.SetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), ::std::string(value)); + default_value_.Set(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), ::std::string(value), + GetArenaNoVirtual()); // @@protoc_insertion_point(field_set_char:google.protobuf.Field.default_value) } - void Field::set_default_value(const char* value, size_t size) { +void Field::set_default_value(const char* value, + size_t size) { - default_value_.SetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), - ::std::string(reinterpret_cast(value), size)); + default_value_.Set(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), ::std::string( + reinterpret_cast(value), size), GetArenaNoVirtual()); // @@protoc_insertion_point(field_set_pointer:google.protobuf.Field.default_value) } - ::std::string* Field::mutable_default_value() { +::std::string* Field::mutable_default_value() { // @@protoc_insertion_point(field_mutable:google.protobuf.Field.default_value) - return default_value_.MutableNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); + return default_value_.Mutable(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), GetArenaNoVirtual()); } - ::std::string* Field::release_default_value() { +::std::string* Field::release_default_value() { // @@protoc_insertion_point(field_release:google.protobuf.Field.default_value) - return default_value_.ReleaseNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); + return default_value_.Release(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), GetArenaNoVirtual()); +} +::std::string* Field::unsafe_arena_release_default_value() { + // @@protoc_insertion_point(field_unsafe_arena_release:google.protobuf.Field.default_value) + GOOGLE_DCHECK(GetArenaNoVirtual() != NULL); + + return default_value_.UnsafeArenaRelease(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), + GetArenaNoVirtual()); } - void Field::set_allocated_default_value(::std::string* default_value) { +void Field::set_allocated_default_value(::std::string* default_value) { if (default_value != NULL) { } else { } - default_value_.SetAllocatedNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), default_value); + default_value_.SetAllocated(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), default_value, + GetArenaNoVirtual()); // @@protoc_insertion_point(field_set_allocated:google.protobuf.Field.default_value) } +void Field::unsafe_arena_set_allocated_default_value( + ::std::string* default_value) { + GOOGLE_DCHECK(GetArenaNoVirtual() != NULL); + if (default_value != NULL) { + + } else { + + } + default_value_.UnsafeArenaSetAllocated(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), + default_value, GetArenaNoVirtual()); + // @@protoc_insertion_point(field_unsafe_arena_set_allocated:google.protobuf.Field.default_value) +} #endif // PROTOBUF_INLINE_NOT_IN_HEADERS // =================================================================== +void Enum::_slow_mutable_source_context() { + source_context_ = ::google::protobuf::Arena::Create< ::google::protobuf::SourceContext >( + GetArenaNoVirtual()); +} +::google::protobuf::SourceContext* Enum::_slow_release_source_context() { + if (source_context_ == NULL) { + return NULL; + } else { + ::google::protobuf::SourceContext* temp = new ::google::protobuf::SourceContext(*source_context_); + source_context_ = NULL; + return temp; + } +} +::google::protobuf::SourceContext* Enum::unsafe_arena_release_source_context() { + // @@protoc_insertion_point(field_unsafe_arena_release:google.protobuf.Enum.source_context) + + ::google::protobuf::SourceContext* temp = source_context_; + source_context_ = NULL; + return temp; +} +void Enum::unsafe_arena_set_allocated_source_context( + ::google::protobuf::SourceContext* source_context) { + if (GetArenaNoVirtual() == NULL) { + delete source_context_; + } + source_context_ = source_context; + if (source_context) { + + } else { + + } + // @@protoc_insertion_point(field_unsafe_arena_set_allocated:google.protobuf.Enum.source_context) +} #if !defined(_MSC_VER) || _MSC_VER >= 1900 const int Enum::kNameFieldNumber; const int Enum::kEnumvalueFieldNumber; @@ -1973,30 +2246,41 @@ const int Enum::kSyntaxFieldNumber; Enum::Enum() : ::google::protobuf::Message(), _internal_metadata_(NULL) { + if (this != internal_default_instance()) protobuf_InitDefaults_google_2fprotobuf_2ftype_2eproto(); SharedCtor(); // @@protoc_insertion_point(constructor:google.protobuf.Enum) } +Enum::Enum(::google::protobuf::Arena* arena) + : ::google::protobuf::Message(), + _internal_metadata_(arena), + enumvalue_(arena), + options_(arena) { +#ifdef GOOGLE_PROTOBUF_NO_STATIC_INITIALIZER + protobuf_InitDefaults_google_2fprotobuf_2ftype_2eproto(); +#endif // GOOGLE_PROTOBUF_NO_STATIC_INITIALIZER + SharedCtor(); + RegisterArenaDtor(arena); + // @@protoc_insertion_point(arena_constructor:google.protobuf.Enum) +} void Enum::InitAsDefaultInstance() { - _is_default_instance_ = true; - source_context_ = const_cast< ::google::protobuf::SourceContext*>(&::google::protobuf::SourceContext::default_instance()); + source_context_ = const_cast< ::google::protobuf::SourceContext*>( + ::google::protobuf::SourceContext::internal_default_instance()); } Enum::Enum(const Enum& from) : ::google::protobuf::Message(), _internal_metadata_(NULL) { SharedCtor(); - MergeFrom(from); + UnsafeMergeFrom(from); // @@protoc_insertion_point(copy_constructor:google.protobuf.Enum) } void Enum::SharedCtor() { - _is_default_instance_ = false; - ::google::protobuf::internal::GetEmptyString(); - _cached_size_ = 0; name_.UnsafeSetDefault(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); source_context_ = NULL; syntax_ = 0; + _cached_size_ = 0; } Enum::~Enum() { @@ -2005,12 +2289,21 @@ Enum::~Enum() { } void Enum::SharedDtor() { - name_.DestroyNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); - if (this != default_instance_) { - delete source_context_; + ::google::protobuf::Arena* arena = GetArenaNoVirtual(); + if (arena != NULL) { + return; } + + name_.Destroy(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), arena); + delete source_context_; } +void Enum::ArenaDtor(void* object) { + Enum* _this = reinterpret_cast< Enum* >(object); + (void)_this; +} +void Enum::RegisterArenaDtor(::google::protobuf::Arena* arena) { +} void Enum::SetCachedSize(int size) const { GOOGLE_SAFE_CONCURRENT_WRITES_BEGIN(); _cached_size_ = size; @@ -2022,23 +2315,19 @@ const ::google::protobuf::Descriptor* Enum::descriptor() { } const Enum& Enum::default_instance() { - if (default_instance_ == NULL) protobuf_AddDesc_google_2fprotobuf_2ftype_2eproto(); - return *default_instance_; + protobuf_InitDefaults_google_2fprotobuf_2ftype_2eproto(); + return *internal_default_instance(); } -Enum* Enum::default_instance_ = NULL; +::google::protobuf::internal::ExplicitlyConstructed Enum::default_instance_; Enum* Enum::New(::google::protobuf::Arena* arena) const { - Enum* n = new Enum; - if (arena != NULL) { - arena->Own(n); - } - return n; + return ::google::protobuf::Arena::CreateMessage(arena); } void Enum::Clear() { // @@protoc_insertion_point(message_clear_start:google.protobuf.Enum) - name_.ClearToEmptyNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); + name_.ClearToEmpty(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), GetArenaNoVirtual()); if (GetArenaNoVirtual() == NULL && source_context_ != NULL) delete source_context_; source_context_ = NULL; syntax_ = 0; @@ -2241,9 +2530,9 @@ void Enum::SerializeWithCachedSizes( return target; } -int Enum::ByteSize() const { +size_t Enum::ByteSizeLong() const { // @@protoc_insertion_point(message_byte_size_start:google.protobuf.Enum) - int total_size = 0; + size_t total_size = 0; // optional string name = 1; if (this->name().size() > 0) { @@ -2266,33 +2555,38 @@ int Enum::ByteSize() const { } // repeated .google.protobuf.EnumValue enumvalue = 2; - total_size += 1 * this->enumvalue_size(); - for (int i = 0; i < this->enumvalue_size(); i++) { - total_size += - ::google::protobuf::internal::WireFormatLite::MessageSizeNoVirtual( - this->enumvalue(i)); + { + unsigned int count = this->enumvalue_size(); + total_size += 1UL * count; + for (unsigned int i = 0; i < count; i++) { + total_size += + ::google::protobuf::internal::WireFormatLite::MessageSizeNoVirtual( + this->enumvalue(i)); + } } // repeated .google.protobuf.Option options = 3; - total_size += 1 * this->options_size(); - for (int i = 0; i < this->options_size(); i++) { - total_size += - ::google::protobuf::internal::WireFormatLite::MessageSizeNoVirtual( - this->options(i)); + { + unsigned int count = this->options_size(); + total_size += 1UL * count; + for (unsigned int i = 0; i < count; i++) { + total_size += + ::google::protobuf::internal::WireFormatLite::MessageSizeNoVirtual( + this->options(i)); + } } + int cached_size = ::google::protobuf::internal::ToCachedSize(total_size); GOOGLE_SAFE_CONCURRENT_WRITES_BEGIN(); - _cached_size_ = total_size; + _cached_size_ = cached_size; GOOGLE_SAFE_CONCURRENT_WRITES_END(); return total_size; } void Enum::MergeFrom(const ::google::protobuf::Message& from) { // @@protoc_insertion_point(generalized_merge_from_start:google.protobuf.Enum) - if (GOOGLE_PREDICT_FALSE(&from == this)) { - ::google::protobuf::internal::MergeFromFail(__FILE__, __LINE__); - } - const Enum* source = + if (GOOGLE_PREDICT_FALSE(&from == this)) MergeFromFail(__LINE__); + const Enum* source = ::google::protobuf::internal::DynamicCastToGenerated( &from); if (source == NULL) { @@ -2300,20 +2594,25 @@ void Enum::MergeFrom(const ::google::protobuf::Message& from) { ::google::protobuf::internal::ReflectionOps::Merge(from, this); } else { // @@protoc_insertion_point(generalized_merge_from_cast_success:google.protobuf.Enum) - MergeFrom(*source); + UnsafeMergeFrom(*source); } } void Enum::MergeFrom(const Enum& from) { // @@protoc_insertion_point(class_specific_merge_from_start:google.protobuf.Enum) - if (GOOGLE_PREDICT_FALSE(&from == this)) { - ::google::protobuf::internal::MergeFromFail(__FILE__, __LINE__); + if (GOOGLE_PREDICT_TRUE(&from != this)) { + UnsafeMergeFrom(from); + } else { + MergeFromFail(__LINE__); } +} + +void Enum::UnsafeMergeFrom(const Enum& from) { + GOOGLE_DCHECK(&from != this); enumvalue_.MergeFrom(from.enumvalue_); options_.MergeFrom(from.options_); if (from.name().size() > 0) { - - name_.AssignWithDefault(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), from.name_); + set_name(from.name()); } if (from.has_source_context()) { mutable_source_context()->::google::protobuf::SourceContext::MergeFrom(from.source_context()); @@ -2334,7 +2633,7 @@ void Enum::CopyFrom(const Enum& from) { // @@protoc_insertion_point(class_specific_copy_from_start:google.protobuf.Enum) if (&from == this) return; Clear(); - MergeFrom(from); + UnsafeMergeFrom(from); } bool Enum::IsInitialized() const { @@ -2344,6 +2643,18 @@ bool Enum::IsInitialized() const { void Enum::Swap(Enum* other) { if (other == this) return; + if (GetArenaNoVirtual() == other->GetArenaNoVirtual()) { + InternalSwap(other); + } else { + Enum temp; + temp.UnsafeMergeFrom(*this); + CopyFrom(*other); + other->CopyFrom(temp); + } +} +void Enum::UnsafeArenaSwap(Enum* other) { + if (other == this) return; + GOOGLE_DCHECK(GetArenaNoVirtual() == other->GetArenaNoVirtual()); InternalSwap(other); } void Enum::InternalSwap(Enum* other) { @@ -2369,47 +2680,69 @@ void Enum::InternalSwap(Enum* other) { // optional string name = 1; void Enum::clear_name() { - name_.ClearToEmptyNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); + name_.ClearToEmpty(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), GetArenaNoVirtual()); } - const ::std::string& Enum::name() const { +const ::std::string& Enum::name() const { // @@protoc_insertion_point(field_get:google.protobuf.Enum.name) - return name_.GetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); + return name_.Get(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); } - void Enum::set_name(const ::std::string& value) { +void Enum::set_name(const ::std::string& value) { - name_.SetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), value); + name_.Set(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), value, GetArenaNoVirtual()); // @@protoc_insertion_point(field_set:google.protobuf.Enum.name) } - void Enum::set_name(const char* value) { +void Enum::set_name(const char* value) { - name_.SetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), ::std::string(value)); + name_.Set(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), ::std::string(value), + GetArenaNoVirtual()); // @@protoc_insertion_point(field_set_char:google.protobuf.Enum.name) } - void Enum::set_name(const char* value, size_t size) { +void Enum::set_name(const char* value, + size_t size) { - name_.SetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), - ::std::string(reinterpret_cast(value), size)); + name_.Set(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), ::std::string( + reinterpret_cast(value), size), GetArenaNoVirtual()); // @@protoc_insertion_point(field_set_pointer:google.protobuf.Enum.name) } - ::std::string* Enum::mutable_name() { +::std::string* Enum::mutable_name() { // @@protoc_insertion_point(field_mutable:google.protobuf.Enum.name) - return name_.MutableNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); + return name_.Mutable(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), GetArenaNoVirtual()); } - ::std::string* Enum::release_name() { +::std::string* Enum::release_name() { // @@protoc_insertion_point(field_release:google.protobuf.Enum.name) - return name_.ReleaseNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); + return name_.Release(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), GetArenaNoVirtual()); +} +::std::string* Enum::unsafe_arena_release_name() { + // @@protoc_insertion_point(field_unsafe_arena_release:google.protobuf.Enum.name) + GOOGLE_DCHECK(GetArenaNoVirtual() != NULL); + + return name_.UnsafeArenaRelease(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), + GetArenaNoVirtual()); } - void Enum::set_allocated_name(::std::string* name) { +void Enum::set_allocated_name(::std::string* name) { if (name != NULL) { } else { } - name_.SetAllocatedNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), name); + name_.SetAllocated(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), name, + GetArenaNoVirtual()); // @@protoc_insertion_point(field_set_allocated:google.protobuf.Enum.name) } +void Enum::unsafe_arena_set_allocated_name( + ::std::string* name) { + GOOGLE_DCHECK(GetArenaNoVirtual() != NULL); + if (name != NULL) { + + } else { + + } + name_.UnsafeArenaSetAllocated(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), + name, GetArenaNoVirtual()); + // @@protoc_insertion_point(field_unsafe_arena_set_allocated:google.protobuf.Enum.name) +} // repeated .google.protobuf.EnumValue enumvalue = 2; int Enum::enumvalue_size() const { @@ -2473,7 +2806,7 @@ Enum::options() const { // optional .google.protobuf.SourceContext source_context = 4; bool Enum::has_source_context() const { - return !_is_default_instance_ && source_context_ != NULL; + return this != internal_default_instance() && source_context_ != NULL; } void Enum::clear_source_context() { if (GetArenaNoVirtual() == NULL && source_context_ != NULL) delete source_context_; @@ -2481,12 +2814,13 @@ void Enum::clear_source_context() { } const ::google::protobuf::SourceContext& Enum::source_context() const { // @@protoc_insertion_point(field_get:google.protobuf.Enum.source_context) - return source_context_ != NULL ? *source_context_ : *default_instance_->source_context_; + return source_context_ != NULL ? *source_context_ + : *::google::protobuf::SourceContext::internal_default_instance(); } ::google::protobuf::SourceContext* Enum::mutable_source_context() { if (source_context_ == NULL) { - source_context_ = new ::google::protobuf::SourceContext; + _slow_mutable_source_context(); } // @@protoc_insertion_point(field_mutable:google.protobuf.Enum.source_context) return source_context_; @@ -2494,12 +2828,24 @@ const ::google::protobuf::SourceContext& Enum::source_context() const { ::google::protobuf::SourceContext* Enum::release_source_context() { // @@protoc_insertion_point(field_release:google.protobuf.Enum.source_context) - ::google::protobuf::SourceContext* temp = source_context_; - source_context_ = NULL; - return temp; + if (GetArenaNoVirtual() != NULL) { + return _slow_release_source_context(); + } else { + ::google::protobuf::SourceContext* temp = source_context_; + source_context_ = NULL; + return temp; + } } -void Enum::set_allocated_source_context(::google::protobuf::SourceContext* source_context) { - delete source_context_; + void Enum::set_allocated_source_context(::google::protobuf::SourceContext* source_context) { + ::google::protobuf::Arena* message_arena = GetArenaNoVirtual(); + if (message_arena == NULL) { + delete source_context_; + } + if (source_context != NULL) { + if (message_arena != NULL) { + message_arena->Own(source_context); + } + } source_context_ = source_context; if (source_context) { @@ -2513,11 +2859,11 @@ void Enum::set_allocated_source_context(::google::protobuf::SourceContext* sourc void Enum::clear_syntax() { syntax_ = 0; } - ::google::protobuf::Syntax Enum::syntax() const { +::google::protobuf::Syntax Enum::syntax() const { // @@protoc_insertion_point(field_get:google.protobuf.Enum.syntax) return static_cast< ::google::protobuf::Syntax >(syntax_); } - void Enum::set_syntax(::google::protobuf::Syntax value) { +void Enum::set_syntax(::google::protobuf::Syntax value) { syntax_ = value; // @@protoc_insertion_point(field_set:google.protobuf.Enum.syntax) @@ -2535,28 +2881,37 @@ const int EnumValue::kOptionsFieldNumber; EnumValue::EnumValue() : ::google::protobuf::Message(), _internal_metadata_(NULL) { + if (this != internal_default_instance()) protobuf_InitDefaults_google_2fprotobuf_2ftype_2eproto(); SharedCtor(); // @@protoc_insertion_point(constructor:google.protobuf.EnumValue) } +EnumValue::EnumValue(::google::protobuf::Arena* arena) + : ::google::protobuf::Message(), + _internal_metadata_(arena), + options_(arena) { +#ifdef GOOGLE_PROTOBUF_NO_STATIC_INITIALIZER + protobuf_InitDefaults_google_2fprotobuf_2ftype_2eproto(); +#endif // GOOGLE_PROTOBUF_NO_STATIC_INITIALIZER + SharedCtor(); + RegisterArenaDtor(arena); + // @@protoc_insertion_point(arena_constructor:google.protobuf.EnumValue) +} void EnumValue::InitAsDefaultInstance() { - _is_default_instance_ = true; } EnumValue::EnumValue(const EnumValue& from) : ::google::protobuf::Message(), _internal_metadata_(NULL) { SharedCtor(); - MergeFrom(from); + UnsafeMergeFrom(from); // @@protoc_insertion_point(copy_constructor:google.protobuf.EnumValue) } void EnumValue::SharedCtor() { - _is_default_instance_ = false; - ::google::protobuf::internal::GetEmptyString(); - _cached_size_ = 0; name_.UnsafeSetDefault(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); number_ = 0; + _cached_size_ = 0; } EnumValue::~EnumValue() { @@ -2565,11 +2920,20 @@ EnumValue::~EnumValue() { } void EnumValue::SharedDtor() { - name_.DestroyNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); - if (this != default_instance_) { + ::google::protobuf::Arena* arena = GetArenaNoVirtual(); + if (arena != NULL) { + return; } + + name_.Destroy(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), arena); } +void EnumValue::ArenaDtor(void* object) { + EnumValue* _this = reinterpret_cast< EnumValue* >(object); + (void)_this; +} +void EnumValue::RegisterArenaDtor(::google::protobuf::Arena* arena) { +} void EnumValue::SetCachedSize(int size) const { GOOGLE_SAFE_CONCURRENT_WRITES_BEGIN(); _cached_size_ = size; @@ -2581,23 +2945,19 @@ const ::google::protobuf::Descriptor* EnumValue::descriptor() { } const EnumValue& EnumValue::default_instance() { - if (default_instance_ == NULL) protobuf_AddDesc_google_2fprotobuf_2ftype_2eproto(); - return *default_instance_; + protobuf_InitDefaults_google_2fprotobuf_2ftype_2eproto(); + return *internal_default_instance(); } -EnumValue* EnumValue::default_instance_ = NULL; +::google::protobuf::internal::ExplicitlyConstructed EnumValue::default_instance_; EnumValue* EnumValue::New(::google::protobuf::Arena* arena) const { - EnumValue* n = new EnumValue; - if (arena != NULL) { - arena->Own(n); - } - return n; + return ::google::protobuf::Arena::CreateMessage(arena); } void EnumValue::Clear() { // @@protoc_insertion_point(message_clear_start:google.protobuf.EnumValue) - name_.ClearToEmptyNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); + name_.ClearToEmpty(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), GetArenaNoVirtual()); number_ = 0; options_.Clear(); } @@ -2632,10 +2992,10 @@ bool EnumValue::MergePartialFromCodedStream( case 2: { if (tag == 16) { parse_number: + DO_((::google::protobuf::internal::WireFormatLite::ReadPrimitive< ::google::protobuf::int32, ::google::protobuf::internal::WireFormatLite::TYPE_INT32>( input, &number_))); - } else { goto handle_unusual; } @@ -2739,9 +3099,9 @@ void EnumValue::SerializeWithCachedSizes( return target; } -int EnumValue::ByteSize() const { +size_t EnumValue::ByteSizeLong() const { // @@protoc_insertion_point(message_byte_size_start:google.protobuf.EnumValue) - int total_size = 0; + size_t total_size = 0; // optional string name = 1; if (this->name().size() > 0) { @@ -2758,25 +3118,27 @@ int EnumValue::ByteSize() const { } // repeated .google.protobuf.Option options = 3; - total_size += 1 * this->options_size(); - for (int i = 0; i < this->options_size(); i++) { - total_size += - ::google::protobuf::internal::WireFormatLite::MessageSizeNoVirtual( - this->options(i)); + { + unsigned int count = this->options_size(); + total_size += 1UL * count; + for (unsigned int i = 0; i < count; i++) { + total_size += + ::google::protobuf::internal::WireFormatLite::MessageSizeNoVirtual( + this->options(i)); + } } + int cached_size = ::google::protobuf::internal::ToCachedSize(total_size); GOOGLE_SAFE_CONCURRENT_WRITES_BEGIN(); - _cached_size_ = total_size; + _cached_size_ = cached_size; GOOGLE_SAFE_CONCURRENT_WRITES_END(); return total_size; } void EnumValue::MergeFrom(const ::google::protobuf::Message& from) { // @@protoc_insertion_point(generalized_merge_from_start:google.protobuf.EnumValue) - if (GOOGLE_PREDICT_FALSE(&from == this)) { - ::google::protobuf::internal::MergeFromFail(__FILE__, __LINE__); - } - const EnumValue* source = + if (GOOGLE_PREDICT_FALSE(&from == this)) MergeFromFail(__LINE__); + const EnumValue* source = ::google::protobuf::internal::DynamicCastToGenerated( &from); if (source == NULL) { @@ -2784,19 +3146,24 @@ void EnumValue::MergeFrom(const ::google::protobuf::Message& from) { ::google::protobuf::internal::ReflectionOps::Merge(from, this); } else { // @@protoc_insertion_point(generalized_merge_from_cast_success:google.protobuf.EnumValue) - MergeFrom(*source); + UnsafeMergeFrom(*source); } } void EnumValue::MergeFrom(const EnumValue& from) { // @@protoc_insertion_point(class_specific_merge_from_start:google.protobuf.EnumValue) - if (GOOGLE_PREDICT_FALSE(&from == this)) { - ::google::protobuf::internal::MergeFromFail(__FILE__, __LINE__); + if (GOOGLE_PREDICT_TRUE(&from != this)) { + UnsafeMergeFrom(from); + } else { + MergeFromFail(__LINE__); } +} + +void EnumValue::UnsafeMergeFrom(const EnumValue& from) { + GOOGLE_DCHECK(&from != this); options_.MergeFrom(from.options_); if (from.name().size() > 0) { - - name_.AssignWithDefault(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), from.name_); + set_name(from.name()); } if (from.number() != 0) { set_number(from.number()); @@ -2814,7 +3181,7 @@ void EnumValue::CopyFrom(const EnumValue& from) { // @@protoc_insertion_point(class_specific_copy_from_start:google.protobuf.EnumValue) if (&from == this) return; Clear(); - MergeFrom(from); + UnsafeMergeFrom(from); } bool EnumValue::IsInitialized() const { @@ -2824,6 +3191,18 @@ bool EnumValue::IsInitialized() const { void EnumValue::Swap(EnumValue* other) { if (other == this) return; + if (GetArenaNoVirtual() == other->GetArenaNoVirtual()) { + InternalSwap(other); + } else { + EnumValue temp; + temp.UnsafeMergeFrom(*this); + CopyFrom(*other); + other->CopyFrom(temp); + } +} +void EnumValue::UnsafeArenaSwap(EnumValue* other) { + if (other == this) return; + GOOGLE_DCHECK(GetArenaNoVirtual() == other->GetArenaNoVirtual()); InternalSwap(other); } void EnumValue::InternalSwap(EnumValue* other) { @@ -2847,57 +3226,79 @@ void EnumValue::InternalSwap(EnumValue* other) { // optional string name = 1; void EnumValue::clear_name() { - name_.ClearToEmptyNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); + name_.ClearToEmpty(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), GetArenaNoVirtual()); } - const ::std::string& EnumValue::name() const { +const ::std::string& EnumValue::name() const { // @@protoc_insertion_point(field_get:google.protobuf.EnumValue.name) - return name_.GetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); + return name_.Get(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); } - void EnumValue::set_name(const ::std::string& value) { +void EnumValue::set_name(const ::std::string& value) { - name_.SetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), value); + name_.Set(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), value, GetArenaNoVirtual()); // @@protoc_insertion_point(field_set:google.protobuf.EnumValue.name) } - void EnumValue::set_name(const char* value) { +void EnumValue::set_name(const char* value) { - name_.SetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), ::std::string(value)); + name_.Set(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), ::std::string(value), + GetArenaNoVirtual()); // @@protoc_insertion_point(field_set_char:google.protobuf.EnumValue.name) } - void EnumValue::set_name(const char* value, size_t size) { +void EnumValue::set_name(const char* value, + size_t size) { - name_.SetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), - ::std::string(reinterpret_cast(value), size)); + name_.Set(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), ::std::string( + reinterpret_cast(value), size), GetArenaNoVirtual()); // @@protoc_insertion_point(field_set_pointer:google.protobuf.EnumValue.name) } - ::std::string* EnumValue::mutable_name() { +::std::string* EnumValue::mutable_name() { // @@protoc_insertion_point(field_mutable:google.protobuf.EnumValue.name) - return name_.MutableNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); + return name_.Mutable(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), GetArenaNoVirtual()); } - ::std::string* EnumValue::release_name() { +::std::string* EnumValue::release_name() { // @@protoc_insertion_point(field_release:google.protobuf.EnumValue.name) - return name_.ReleaseNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); + return name_.Release(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), GetArenaNoVirtual()); } - void EnumValue::set_allocated_name(::std::string* name) { +::std::string* EnumValue::unsafe_arena_release_name() { + // @@protoc_insertion_point(field_unsafe_arena_release:google.protobuf.EnumValue.name) + GOOGLE_DCHECK(GetArenaNoVirtual() != NULL); + + return name_.UnsafeArenaRelease(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), + GetArenaNoVirtual()); +} +void EnumValue::set_allocated_name(::std::string* name) { if (name != NULL) { } else { } - name_.SetAllocatedNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), name); + name_.SetAllocated(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), name, + GetArenaNoVirtual()); // @@protoc_insertion_point(field_set_allocated:google.protobuf.EnumValue.name) } +void EnumValue::unsafe_arena_set_allocated_name( + ::std::string* name) { + GOOGLE_DCHECK(GetArenaNoVirtual() != NULL); + if (name != NULL) { + + } else { + + } + name_.UnsafeArenaSetAllocated(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), + name, GetArenaNoVirtual()); + // @@protoc_insertion_point(field_unsafe_arena_set_allocated:google.protobuf.EnumValue.name) +} // optional int32 number = 2; void EnumValue::clear_number() { number_ = 0; } - ::google::protobuf::int32 EnumValue::number() const { +::google::protobuf::int32 EnumValue::number() const { // @@protoc_insertion_point(field_get:google.protobuf.EnumValue.number) return number_; } - void EnumValue::set_number(::google::protobuf::int32 value) { +void EnumValue::set_number(::google::protobuf::int32 value) { number_ = value; // @@protoc_insertion_point(field_set:google.protobuf.EnumValue.number) @@ -2937,6 +3338,39 @@ EnumValue::options() const { // =================================================================== +void Option::_slow_mutable_value() { + value_ = ::google::protobuf::Arena::Create< ::google::protobuf::Any >( + GetArenaNoVirtual()); +} +::google::protobuf::Any* Option::_slow_release_value() { + if (value_ == NULL) { + return NULL; + } else { + ::google::protobuf::Any* temp = new ::google::protobuf::Any(*value_); + value_ = NULL; + return temp; + } +} +::google::protobuf::Any* Option::unsafe_arena_release_value() { + // @@protoc_insertion_point(field_unsafe_arena_release:google.protobuf.Option.value) + + ::google::protobuf::Any* temp = value_; + value_ = NULL; + return temp; +} +void Option::unsafe_arena_set_allocated_value( + ::google::protobuf::Any* value) { + if (GetArenaNoVirtual() == NULL) { + delete value_; + } + value_ = value; + if (value) { + + } else { + + } + // @@protoc_insertion_point(field_unsafe_arena_set_allocated:google.protobuf.Option.value) +} #if !defined(_MSC_VER) || _MSC_VER >= 1900 const int Option::kNameFieldNumber; const int Option::kValueFieldNumber; @@ -2944,29 +3378,38 @@ const int Option::kValueFieldNumber; Option::Option() : ::google::protobuf::Message(), _internal_metadata_(NULL) { + if (this != internal_default_instance()) protobuf_InitDefaults_google_2fprotobuf_2ftype_2eproto(); SharedCtor(); // @@protoc_insertion_point(constructor:google.protobuf.Option) } +Option::Option(::google::protobuf::Arena* arena) + : ::google::protobuf::Message(), + _internal_metadata_(arena) { +#ifdef GOOGLE_PROTOBUF_NO_STATIC_INITIALIZER + protobuf_InitDefaults_google_2fprotobuf_2ftype_2eproto(); +#endif // GOOGLE_PROTOBUF_NO_STATIC_INITIALIZER + SharedCtor(); + RegisterArenaDtor(arena); + // @@protoc_insertion_point(arena_constructor:google.protobuf.Option) +} void Option::InitAsDefaultInstance() { - _is_default_instance_ = true; - value_ = const_cast< ::google::protobuf::Any*>(&::google::protobuf::Any::default_instance()); + value_ = const_cast< ::google::protobuf::Any*>( + ::google::protobuf::Any::internal_default_instance()); } Option::Option(const Option& from) : ::google::protobuf::Message(), _internal_metadata_(NULL) { SharedCtor(); - MergeFrom(from); + UnsafeMergeFrom(from); // @@protoc_insertion_point(copy_constructor:google.protobuf.Option) } void Option::SharedCtor() { - _is_default_instance_ = false; - ::google::protobuf::internal::GetEmptyString(); - _cached_size_ = 0; name_.UnsafeSetDefault(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); value_ = NULL; + _cached_size_ = 0; } Option::~Option() { @@ -2975,12 +3418,21 @@ Option::~Option() { } void Option::SharedDtor() { - name_.DestroyNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); - if (this != default_instance_) { - delete value_; + ::google::protobuf::Arena* arena = GetArenaNoVirtual(); + if (arena != NULL) { + return; } + + name_.Destroy(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), arena); + delete value_; } +void Option::ArenaDtor(void* object) { + Option* _this = reinterpret_cast< Option* >(object); + (void)_this; +} +void Option::RegisterArenaDtor(::google::protobuf::Arena* arena) { +} void Option::SetCachedSize(int size) const { GOOGLE_SAFE_CONCURRENT_WRITES_BEGIN(); _cached_size_ = size; @@ -2992,23 +3444,19 @@ const ::google::protobuf::Descriptor* Option::descriptor() { } const Option& Option::default_instance() { - if (default_instance_ == NULL) protobuf_AddDesc_google_2fprotobuf_2ftype_2eproto(); - return *default_instance_; + protobuf_InitDefaults_google_2fprotobuf_2ftype_2eproto(); + return *internal_default_instance(); } -Option* Option::default_instance_ = NULL; +::google::protobuf::internal::ExplicitlyConstructed